diff --git a/src/blockchain/orderlib.js b/src/blockchain/orderlib.js index 3aabe65..c8a72ac 100644 --- a/src/blockchain/orderlib.js +++ b/src/blockchain/orderlib.js @@ -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 diff --git a/src/components/chart/DateBuilder.vue b/src/components/chart/DateBuilder.vue index b78a681..2b925ee 100644 --- a/src/components/chart/DateBuilder.vue +++ b/src/components/chart/DateBuilder.vue @@ -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) } diff --git a/src/components/chart/LimitBuilder.vue b/src/components/chart/LimitBuilder.vue index f5ba4a5..e2e813b 100644 --- a/src/components/chart/LimitBuilder.vue +++ b/src/components/chart/LimitBuilder.vue @@ -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 diff --git a/src/components/chart/MarketBuilder.vue b/src/components/chart/MarketBuilder.vue index f1e6a11..d47d7a7 100644 --- a/src/components/chart/MarketBuilder.vue +++ b/src/components/chart/MarketBuilder.vue @@ -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, } } diff --git a/src/orderbuild.js b/src/orderbuild.js index c891d86..7b060de 100644 --- a/src/orderbuild.js +++ b/src/orderbuild.js @@ -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,