diagonal order form
This commit is contained in:
@@ -1,31 +1,53 @@
|
||||
import {routeInverted} from "@/misc.js";
|
||||
import {routeInverted, timestamp} from "@/misc.js";
|
||||
import {MAX_FRACTION, newTranche} from "@/blockchain/orderlib.js";
|
||||
import {useOrderStore} from "@/store/store.js";
|
||||
import {encodeIEE754} from "@/blockchain/common.js";
|
||||
|
||||
|
||||
export function applyLimit(tranche, price=null) {
|
||||
const os = useOrderStore()
|
||||
export function applyLimit(tranche, price=null, isAbove=null) {
|
||||
if( price === null ) {
|
||||
const os = useOrderStore()
|
||||
price = os.limitPrice
|
||||
if (!price)
|
||||
return
|
||||
}
|
||||
|
||||
applyLine(tranche, price, 0, isAbove)
|
||||
}
|
||||
|
||||
|
||||
export function applyLinePoints(tranche, date0, price0, date1, price1, isAbove=null) {
|
||||
const os = useOrderStore()
|
||||
if( !date0 || !price0 && price0!==0 || !date1 || !price1 && price1!==0 )
|
||||
return
|
||||
|
||||
const t0 = timestamp(date0);
|
||||
const t1 = timestamp(date1);
|
||||
const slope = (price1-price0)/(t1-t0)
|
||||
const intercept = price1 - slope * t1
|
||||
applyLine(tranche, intercept, slope, isAbove)
|
||||
}
|
||||
|
||||
|
||||
export function applyLine(tranche, intercept, slope, isAbove=null) {
|
||||
// intercept and slope are still in "human" units of decimal-adjusted prices
|
||||
const os = useOrderStore()
|
||||
const route = os.route
|
||||
const inverted = routeInverted(route)
|
||||
const isAbove = os.limitIsMinimum ^ inverted
|
||||
const isRatio = false // todo ratios
|
||||
const decimals = 10 ** (os.tokenA.decimals - os.tokenB.decimals)
|
||||
const limit = encodeIEE754(inverted ? decimals / price : price / decimals)
|
||||
tranche.marketOrder = false;
|
||||
const scale = 10 ** (os.tokenA.decimals - os.tokenB.decimals)
|
||||
const m = encodeIEE754(inverted ? scale / slope : slope / scale)
|
||||
const b = encodeIEE754(inverted ? scale / intercept : intercept / scale)
|
||||
if( isAbove === null )
|
||||
isAbove = os.limitIsMinimum ^ inverted
|
||||
if( isAbove ) {
|
||||
tranche.minIntercept = limit;
|
||||
tranche.minSlope = 0;
|
||||
tranche.minIntercept = b;
|
||||
tranche.minSlope = m;
|
||||
}
|
||||
else {
|
||||
tranche.maxIntercept = limit;
|
||||
tranche.maxSlope = 0;
|
||||
tranche.maxIntercept = b;
|
||||
tranche.maxSlope = m;
|
||||
}
|
||||
tranche.marketOrder = false;
|
||||
}
|
||||
|
||||
export function timesliceTranches() {
|
||||
|
||||
Reference in New Issue
Block a user