bugfix for limit/diagonal tranche building
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import {uint32max, uint64max} from "@/misc.js";
|
import {uint32max, uint64max} from "@/misc.js";
|
||||||
import {encodeIEE754} from "@/common.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 MAX_FRACTION = 65535;
|
||||||
export const NO_CONDITIONAL_ORDER = uint64max;
|
export const NO_CONDITIONAL_ORDER = uint64max;
|
||||||
@@ -82,15 +82,13 @@ export function newTranche({
|
|||||||
rateLimitFraction = 0,
|
rateLimitFraction = 0,
|
||||||
rateLimitPeriod = 0,
|
rateLimitPeriod = 0,
|
||||||
} = {}) {
|
} = {}) {
|
||||||
if( minIntercept === 0 && minSlope === 0 && maxIntercept === 0 && maxSlope === 0 )
|
|
||||||
marketOrder = true
|
|
||||||
if( marketOrder ) {
|
if( marketOrder ) {
|
||||||
if (minIntercept !== 0 || minSlope !== 0 || maxIntercept !== 0 || maxSlope !== 0)
|
if (minIntercept !== 0 || minSlope !== 0 || maxIntercept !== 0 || maxSlope !== 0)
|
||||||
console.warn('Ignoring line information in a market order')
|
throw Error('Cannot set line information on a market order')
|
||||||
if (slippage === 0) {
|
if (slippage === 0)
|
||||||
console.warn(`setting market order slippage to ${DEFAULT_SLIPPAGE}`)
|
|
||||||
slippage = DEFAULT_SLIPPAGE
|
slippage = DEFAULT_SLIPPAGE
|
||||||
}
|
else if (slippage < MIN_SLIPPAGE)
|
||||||
|
slippage = MIN_SLIPPAGE
|
||||||
minIntercept = encodeIEE754(slippage) // this is the slippage field for market orders
|
minIntercept = encodeIEE754(slippage) // this is the slippage field for market orders
|
||||||
minSlope = 0
|
minSlope = 0
|
||||||
maxIntercept = 0
|
maxIntercept = 0
|
||||||
|
|||||||
@@ -206,10 +206,11 @@ function buildTranches() {
|
|||||||
if (endTime <= s.clock)
|
if (endTime <= s.clock)
|
||||||
warnings.push(`Tranche already expired at ${new Date(endTime*1000)}`)
|
warnings.push(`Tranche already expired at ${new Date(endTime*1000)}`)
|
||||||
const t = newTranche({
|
const t = newTranche({
|
||||||
|
marketOrder: true,
|
||||||
|
slippage: builder.slippage,
|
||||||
fraction: ws[i] * MAX_FRACTION,
|
fraction: ws[i] * MAX_FRACTION,
|
||||||
startTime: ts[i],
|
startTime: ts[i],
|
||||||
endTime, // always give at least 60 seconds of window to execute
|
endTime, // always give at least 60 seconds of window to execute
|
||||||
slippage: builder.slippage,
|
|
||||||
})
|
})
|
||||||
tranches.push(t)
|
tranches.push(t)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -90,10 +90,6 @@ function buildTranches() {
|
|||||||
let p = ps[i]
|
let p = ps[i]
|
||||||
const w = ws[i]
|
const w = ws[i]
|
||||||
const t = newTranche({
|
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,
|
fraction: w * MAX_FRACTION,
|
||||||
})
|
})
|
||||||
const symbol = co.selectedSymbol
|
const symbol = co.selectedSymbol
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ function buildTranches() {
|
|||||||
warnings.push('Slippage will be set to the minimum of 0.01%')
|
warnings.push('Slippage will be set to the minimum of 0.01%')
|
||||||
const slip = Math.max(slippage.value, MIN_SLIPPAGE)
|
const slip = Math.max(slippage.value, MIN_SLIPPAGE)
|
||||||
return {
|
return {
|
||||||
tranches: [newTranche({slippage: slip / 100})],
|
tranches: [newTranche({marketOrder: true, slippage: slip / 100})],
|
||||||
warnings,
|
warnings,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 MIN_EXECUTION_TIME = 60 // give at least one full minute for each tranche to trigger
|
||||||
export const DEFAULT_SLIPPAGE = 0.0030;
|
export const DEFAULT_SLIPPAGE = 0.0030;
|
||||||
|
export const MIN_SLIPPAGE = 0.0001;
|
||||||
|
|
||||||
|
|
||||||
// Builders are data objects which store a configuration state
|
// 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 start = Math.floor(i * (duration / Math.max((n - 1), 1)))
|
||||||
const end = start + window
|
const end = start + window
|
||||||
ts.push(newTranche({
|
ts.push(newTranche({
|
||||||
|
marketOrder: true,
|
||||||
fraction: amtPerTranche,
|
fraction: amtPerTranche,
|
||||||
startTimeIsRelative: true,
|
startTimeIsRelative: true,
|
||||||
startTime: start,
|
startTime: start,
|
||||||
|
|||||||
Reference in New Issue
Block a user