diff --git a/src/components/DiagonalOrder.vue b/src/components/DiagonalOrder.vue index aeed518..ec94301 100644 --- a/src/components/DiagonalOrder.vue +++ b/src/components/DiagonalOrder.vue @@ -1,23 +1,15 @@ - + - Coming soon! - + Line Point A + + + + Line Point B + + + + Backend support for diagonal lines is coming soon... @@ -26,65 +18,22 @@ 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 {applyLimit, applyLinePoints} from "@/orderbuild.js"; import {validateRequired, validateTranches} from "@/validate.js"; import {MAX_FRACTION, newTranche} from "@/blockchain/orderlib.js"; +import TimeEntry from "@/components/TimeEntry.vue"; const os = useOrderStore() -const skew = ref(0) -const rungs = computed(()=>{ - if( !os.limitPrice || !os.limitPrice2 ) - return [] - const n = os.tranches; - const a = parseFloat(os.limitPrice); - const b = parseFloat(os.limitPrice2); - if( n < 1 || !a || !b ) return [] - if( n === 1 ) return [(a+b)/2] - // num >= 2 - const result = [] - const delta = (b-a)/(n-1) - for( let i=0; i{ - return rungs.value.map((r)=>r.toPrecision(5)) // todo precisions -}) -const fractions = computed(()=>{ - const n = os.tranches - const s = skew.value / 100 - const result = [] - if( s === 1 ) { - result.push(1) - for( let i=1; ifractions.value.map((f)=>f*os.totalAmount) ) +const time1 = ref(new Date()) +const price1 = ref(null) +const time2 = ref(new Date()) +const price2 = ref(null) function buildTranches() { - const ts = [] - const n = os.tranches - for( let i=0; i - - + + tranches diff --git a/src/components/LimitPrice.vue b/src/components/LimitPrice.vue index 3d8b0bc..7d6ede2 100644 --- a/src/components/LimitPrice.vue +++ b/src/components/LimitPrice.vue @@ -1,7 +1,7 @@ - + :clearable="!required && clearable" :rules="rules" v-auto-select> {{ os.pairSymbol }} @@ -26,10 +26,17 @@ import {vAutoSelect} from "@/misc.js"; const os = useOrderStore() const props = defineProps({ + modelValue: {required: true}, required: {default: false}, label: {default: null}, - storeVar: {default: 'limitPrice'}, showPrice: {default: true}, + clearable: {default: true}, +}) +const emit = defineEmits(['update:modelValue']) + +const mv = computed({ + get() {return props.modelValue}, + set(v) {emit('update:modelValue', v)} }) const rules = computed(()=>props.required ? [validateAmount, validateRequired] : [validateAmount]) diff --git a/src/components/NavDrawer.vue b/src/components/NavDrawer.vue index 6e107be..35f3102 100644 --- a/src/components/NavDrawer.vue +++ b/src/components/NavDrawer.vue @@ -7,7 +7,7 @@ - + diff --git a/src/components/Order.vue b/src/components/Order.vue index e7a02eb..24b2c62 100644 --- a/src/components/Order.vue +++ b/src/components/Order.vue @@ -11,7 +11,7 @@ - Cancel + Cancel Place Dexorder diff --git a/src/components/TimeEntry.vue b/src/components/TimeEntry.vue new file mode 100644 index 0000000..14ace6e --- /dev/null +++ b/src/components/TimeEntry.vue @@ -0,0 +1,65 @@ + + + + + + + + + + + + diff --git a/src/components/TimedOrder.vue b/src/components/TimedOrder.vue index 79594bc..919d9a5 100644 --- a/src/components/TimedOrder.vue +++ b/src/components/TimedOrder.vue @@ -1,7 +1,7 @@ - + diff --git a/src/misc.js b/src/misc.js index bd470a1..25c2769 100644 --- a/src/misc.js +++ b/src/misc.js @@ -77,3 +77,8 @@ export function dateString(seconds) { const date = new Date(seconds*1000) return _dateFormat.format(date) } + + +export function timestamp(date) { + return Math.round(date.getTime() / 1000) +} diff --git a/src/orderbuild.js b/src/orderbuild.js index 8ae2291..8978da7 100644 --- a/src/orderbuild.js +++ b/src/orderbuild.js @@ -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() { diff --git a/src/store/store.js b/src/store/store.js index 2cfe4fb..a2dc2e8 100644 --- a/src/store/store.js +++ b/src/store/store.js @@ -29,7 +29,7 @@ import {computed, ref} from "vue"; export const useStore = defineStore('app', ()=> { - const nav = ref(false) + const nav = ref(false) // controls opening navigation drawer const _chainId = ref(null) const _chainInfo = ref({}) @@ -136,6 +136,7 @@ export const useOrderStore = defineStore('order', ()=> { const timeUnitIndex = ref(0) const routes = ref([]) const routesPending = ref(false) + const utc = ref(false) const validOrder = computed(() => amount.value > 0 && routes.value.length > 0) const route = computed(() => routes.value.length === 0 ? null : routes.value[0]) @@ -164,6 +165,6 @@ export const useOrderStore = defineStore('order', ()=> { return { tokenA, tokenB, buy, inverted, amount, amountIsTokenA, amountIsTotal, limitPrice, limitPrice2, tranches, interval, intervalIsTotal, timeUnitIndex, routes, routesPending, validOrder, route, base, quote, pairSymbol, - limitIsMinimum, amountToken, amountIsInput, setDefaultTokens, totalAmount, trancheAmount, + limitIsMinimum, amountToken, amountIsInput, setDefaultTokens, totalAmount, trancheAmount, utc, } }) diff --git a/src/views/OrdersView.vue b/src/views/OrdersView.vue index 9fb0cb7..b40967a 100644 --- a/src/views/OrdersView.vue +++ b/src/views/OrdersView.vue @@ -1,7 +1,8 @@ - + + Vault Orders