line inversion fixes
This commit is contained in:
@@ -26,7 +26,7 @@ import {useOrderStore} from "@/store/store";
|
||||
import LimitPrice from "@/components/LimitPrice.vue";
|
||||
import Order from "@/components/Order.vue";
|
||||
import {computed, ref} from "vue";
|
||||
import {applyLimit} from "@/orderbuild.js";
|
||||
import {applyLimitOld} from "@/orderbuild.js";
|
||||
import {validateRequired, validateTranches} from "@/validate.js";
|
||||
import {MAX_FRACTION, newTranche} from "@/blockchain/orderlib.js";
|
||||
|
||||
@@ -81,7 +81,7 @@ function buildTranches() {
|
||||
// todo optional deadline
|
||||
const fraction = Math.min(MAX_FRACTION, Math.ceil(MAX_FRACTION * fractions.value[i]) )
|
||||
const tranche = newTranche({fraction})
|
||||
applyLimit(tranche, rungs.value[i])
|
||||
applyLimitOld(tranche, rungs.value[i])
|
||||
ts.push(tranche)
|
||||
}
|
||||
return ts
|
||||
|
||||
@@ -29,7 +29,7 @@ import {useOrderStore} from "@/store/store";
|
||||
import LimitPrice from "@/components/LimitPrice.vue";
|
||||
import Order from "@/components/Order.vue";
|
||||
import {computed, ref} from "vue";
|
||||
import {applyLimit} from "@/orderbuild.js";
|
||||
import {applyLimitOld} from "@/orderbuild.js";
|
||||
import {validateRequired, validateTranches} from "@/validate.js";
|
||||
import {MAX_FRACTION, newTranche} from "@/blockchain/orderlib.js";
|
||||
|
||||
@@ -84,7 +84,7 @@ function buildTranches() {
|
||||
// todo optional deadline
|
||||
const fraction = Math.min(MAX_FRACTION, Math.ceil(MAX_FRACTION * fractions.value[i]) )
|
||||
const tranche = newTranche({fraction})
|
||||
applyLimit(tranche, rungs.value[i])
|
||||
applyLimitOld(tranche, rungs.value[i])
|
||||
ts.push(tranche)
|
||||
}
|
||||
return ts
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
import {routeInverted, SingletonCoroutine, vAutoSelect} from "@/misc.js";
|
||||
import Order from "@/components/Order.vue";
|
||||
import LimitPrice from "@/components/LimitPrice.vue";
|
||||
import {timesliceTranches, applyLimit} from "@/orderbuild.js";
|
||||
import {timesliceTranches, applyLimitOld} from "@/orderbuild.js";
|
||||
import Tranches from "@/components/Tranches.vue";
|
||||
import {useOrderStore} from "@/store/store.js";
|
||||
|
||||
@@ -22,7 +22,7 @@ function buildTranches() {
|
||||
const price = os.limitPrice
|
||||
if( price )
|
||||
for( let i=0; i<ts.length; i++)
|
||||
applyLimit(ts[i], price)
|
||||
applyLimitOld(ts[i], price)
|
||||
return ts
|
||||
}
|
||||
|
||||
|
||||
@@ -117,13 +117,23 @@ function buildTranches() {
|
||||
const la = _endpoints.value[0] // use the flatline format which is a vector of length 4, useful for vectorInterpolate()
|
||||
const lb = _endpoints.value[1]
|
||||
const ws = weights.value
|
||||
const symbol = co.selectedSymbol
|
||||
const inverted = symbol.inverted
|
||||
const scale = 10 ** -symbol.decimals
|
||||
const isMinimum = inverted === order.buy
|
||||
for (let i = 0; i < ws.length; i++) {
|
||||
const w = ws[i]
|
||||
const line = ws.length === 1 ? la : vectorInterpolate(la, lb, i/(ws.length-1))
|
||||
if (inverted) {
|
||||
// invert prices
|
||||
line[1] = 1/line[1]
|
||||
line[3] = 1/line[3]
|
||||
}
|
||||
// scale to pool decimals
|
||||
line[1] *= scale
|
||||
line[3] *= scale
|
||||
const t = newTranche({fraction: w * MAX_FRACTION})
|
||||
const symbol = co.selectedSymbol
|
||||
console.log('symbol', symbol)
|
||||
applyLinePoints(t, order.buy, ...line, symbol.decimals, symbol.inverted)
|
||||
applyLinePoints(t, isMinimum, ...line)
|
||||
tranches.push(t)
|
||||
}
|
||||
return tranches
|
||||
|
||||
@@ -81,16 +81,23 @@ function buildTranches() {
|
||||
console.log('buildTranches', builder, order, tranches)
|
||||
const ps = prices.value
|
||||
const ws = weights.value
|
||||
const symbol = co.selectedSymbol
|
||||
const scale = 10 ** -symbol.decimals
|
||||
const inverted = symbol.inverted
|
||||
const isMinimum = inverted === order.buy
|
||||
for(let i=0; i<ps.length; i++) {
|
||||
const p = ps[i]
|
||||
let p = ps[i]
|
||||
if (inverted)
|
||||
p = 1/p
|
||||
p *= scale
|
||||
const w = ws[i]
|
||||
const t = newTranche({
|
||||
// todo start/end
|
||||
fraction: w * MAX_FRACTION,
|
||||
})
|
||||
const symbol = co.selectedSymbol
|
||||
console.log('symbol', symbol)
|
||||
applyLine(t, order.buy, p, 0, symbol.decimals, symbol.inverted)
|
||||
console.log('symbol', symbol, isMinimum, p)
|
||||
applyLine(t, isMinimum, p, 0)
|
||||
tranches.push(t)
|
||||
}
|
||||
return tranches
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {timestamp, uuid} from "@/misc.js";
|
||||
import {routeInverted, timestamp, uuid} from "@/misc.js";
|
||||
import {MAX_FRACTION, newTranche} from "@/blockchain/orderlib.js";
|
||||
import {useOrderStore, useStore} from "@/store/store.js";
|
||||
import {encodeIEE754} from "@/common.js";
|
||||
@@ -10,8 +10,6 @@ import Color from "color";
|
||||
export const MIN_EXECUTION_TIME = 60 // give at least one full minute for each tranche to trigger
|
||||
|
||||
|
||||
function unimplemented() { throw Error('Unimplemented') }
|
||||
|
||||
// Builders are data objects which store a configuration state
|
||||
// the component name must match a corresponding Vue component in the BuilderFactory.vue component, which is responsible
|
||||
// for instantiating the UI component for a given builder dictionary, based on its builder.component field.
|
||||
@@ -101,7 +99,8 @@ export const useChartOrderStore = defineStore('chart_orders', () => {
|
||||
})
|
||||
|
||||
|
||||
export function applyLimit(tranche, price = null, isMinimum = null) {
|
||||
export function applyLimitOld(tranche, price = null, isMinimum = null) {
|
||||
// todo deprecate. used by old forms-based components.
|
||||
if (price === null) {
|
||||
const os = useOrderStore()
|
||||
price = os.limitPrice
|
||||
@@ -109,7 +108,7 @@ export function applyLimit(tranche, price = null, isMinimum = null) {
|
||||
return
|
||||
}
|
||||
|
||||
applyLine(tranche, price, 0, isMinimum)
|
||||
applyLineOld(tranche, price, 0, isMinimum)
|
||||
}
|
||||
|
||||
|
||||
@@ -139,23 +138,45 @@ export function linePointsValue(time0, price0, time1, price1, unixTime = null) {
|
||||
}
|
||||
|
||||
|
||||
export function applyLinePoints(tranche, buy, time0, price0, time1, price1, poolDecimals, inverted) {
|
||||
export function applyLinePoints(tranche, isMinimum, time0, price0, time1, price1) {
|
||||
const [intercept, slope] = computeInterceptSlope(time0, price0, time1, price1);
|
||||
applyLine(tranche, buy, intercept, slope, poolDecimals, inverted)
|
||||
applyLine(tranche, isMinimum, intercept, slope)
|
||||
}
|
||||
|
||||
|
||||
export function applyLine(tranche, buy, intercept, slope, poolDecimals, inverted) {
|
||||
export function applyLineOld(tranche, intercept, slope, isMinimum = null) {
|
||||
console.log('intercept, slope', intercept, slope)
|
||||
// intercept and slope are still in "human" units of decimal-adjusted prices
|
||||
const scale = 10 ** -poolDecimals
|
||||
let m = slope === 0 ? 0 : inverted ? -scale / slope : scale * slope
|
||||
let b = inverted ? scale / intercept : scale * intercept
|
||||
// const cur = b + timestamp() * m
|
||||
// console.log('inverted b, m, cur', inverted, b, m, cur)
|
||||
const os = useOrderStore()
|
||||
const route = os.route
|
||||
const inverted = routeInverted(route)
|
||||
const scale = 10 ** (os.tokenA.d - os.tokenB.d)
|
||||
let m = inverted ? -scale / slope : slope / scale
|
||||
let b = inverted ? scale / intercept : intercept / scale
|
||||
const cur = b + timestamp() * m
|
||||
console.log('inverted b, m, cur', inverted, b, m, cur)
|
||||
m = encodeIEE754(m)
|
||||
b = encodeIEE754(b)
|
||||
if (isMinimum === null)
|
||||
isMinimum = os.limitIsMinimum
|
||||
console.log('limit is minimum', isMinimum)
|
||||
if (isMinimum) {
|
||||
tranche.minIntercept = b;
|
||||
tranche.minSlope = m;
|
||||
} else {
|
||||
tranche.maxIntercept = b;
|
||||
tranche.maxSlope = m;
|
||||
}
|
||||
tranche.marketOrder = false;
|
||||
}
|
||||
|
||||
|
||||
export function applyLine(tranche, isMinimum, intercept, slope) {
|
||||
// intercept and slope must be already adjusted to be in correct pool units
|
||||
let m = slope
|
||||
let b = intercept
|
||||
m = encodeIEE754(m)
|
||||
b = encodeIEE754(b)
|
||||
const isMinimum = !(buy ^ inverted)
|
||||
console.log('applyLine', buy, intercept, slope, poolDecimals, inverted, isMinimum)
|
||||
if (isMinimum) {
|
||||
tranche.minIntercept = b;
|
||||
tranche.minSlope = m;
|
||||
|
||||
Reference in New Issue
Block a user