bugfix for limit/diagonal tranche building

This commit is contained in:
tim
2025-04-01 13:48:59 -04:00
parent 0442b08623
commit 715a43c097
5 changed files with 10 additions and 13 deletions

View File

@@ -1,6 +1,6 @@
import {uint32max, uint64max} from "@/misc.js";
import {encodeIEE754} from "@/common.js";
import {DEFAULT_SLIPPAGE} from "@/orderbuild.js";
import {DEFAULT_SLIPPAGE, MIN_SLIPPAGE} from "@/orderbuild.js";
export const MAX_FRACTION = 65535;
export const NO_CONDITIONAL_ORDER = uint64max;
@@ -82,15 +82,13 @@ export function newTranche({
rateLimitFraction = 0,
rateLimitPeriod = 0,
} = {}) {
if( minIntercept === 0 && minSlope === 0 && maxIntercept === 0 && maxSlope === 0 )
marketOrder = true
if( marketOrder ) {
if (minIntercept !== 0 || minSlope !== 0 || maxIntercept !== 0 || maxSlope !== 0)
console.warn('Ignoring line information in a market order')
if (slippage === 0) {
console.warn(`setting market order slippage to ${DEFAULT_SLIPPAGE}`)
throw Error('Cannot set line information on a market order')
if (slippage === 0)
slippage = DEFAULT_SLIPPAGE
}
else if (slippage < MIN_SLIPPAGE)
slippage = MIN_SLIPPAGE
minIntercept = encodeIEE754(slippage) // this is the slippage field for market orders
minSlope = 0
maxIntercept = 0

View File

@@ -206,10 +206,11 @@ function buildTranches() {
if (endTime <= s.clock)
warnings.push(`Tranche already expired at ${new Date(endTime*1000)}`)
const t = newTranche({
marketOrder: true,
slippage: builder.slippage,
fraction: ws[i] * MAX_FRACTION,
startTime: ts[i],
endTime, // always give at least 60 seconds of window to execute
slippage: builder.slippage,
})
tranches.push(t)
}

View File

@@ -90,10 +90,6 @@ function buildTranches() {
let p = ps[i]
const w = ws[i]
const t = newTranche({
// todo start/end
// todo check expired
// if (endTime <= s.clock)
// warnings.push(`Tranche already expired at ${new Date(endTime*1000)}`)
fraction: w * MAX_FRACTION,
})
const symbol = co.selectedSymbol

View File

@@ -44,7 +44,7 @@ function buildTranches() {
warnings.push('Slippage will be set to the minimum of 0.01%')
const slip = Math.max(slippage.value, MIN_SLIPPAGE)
return {
tranches: [newTranche({slippage: slip / 100})],
tranches: [newTranche({marketOrder: true, slippage: slip / 100})],
warnings,
}
}

View File

@@ -9,6 +9,7 @@ import Color from "color";
export const MIN_EXECUTION_TIME = 60 // give at least one full minute for each tranche to trigger
export const DEFAULT_SLIPPAGE = 0.0030;
export const MIN_SLIPPAGE = 0.0001;
// Builders are data objects which store a configuration state
@@ -184,6 +185,7 @@ export function timesliceTranches() {
const start = Math.floor(i * (duration / Math.max((n - 1), 1)))
const end = start + window
ts.push(newTranche({
marketOrder: true,
fraction: amtPerTranche,
startTimeIsRelative: true,
startTime: start,