ladder orders!
This commit is contained in:
@@ -1,22 +1,96 @@
|
||||
<template>
|
||||
<order :tranches="buildTranches">
|
||||
<limit-price :required="true" label=""/>
|
||||
<limit-price :show-price="false" store-var="limitPrice2" :required="true" label=""/>
|
||||
<order title="Ladder" subtitle="Multiple price levels" :tranches="buildTranches" :valid="validOrder">
|
||||
<limit-price :required="true" label="start price" :show-price="false"/>
|
||||
<limit-price store-var="limitPrice2" :required="true" label="end price"/>
|
||||
<v-text-field label='Parts' type="number" step="1" aria-valuemin="0" min="1" variant="outlined"
|
||||
v-model="num" />
|
||||
<v-text-field label='Skew' type="number" step="10" aria-valuemin="0" min="-100" max="100" variant="outlined"
|
||||
v-model="skew" clearable @click:clear="skew=0" suffix="%"/>
|
||||
<!-- todo deadline -->
|
||||
<v-table>
|
||||
<thead>
|
||||
<tr><td>Fraction</td><td>Amount</td><td>Price</td></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="(r,i) in rungsFmt">
|
||||
<td>{{(100*fractions[i]).toFixed(1)}}%</td>
|
||||
<td>{{(amounts[i]).toPrecision(5)}} {{os.amountToken.symbol}}</td>
|
||||
<td>{{r}}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</v-table>
|
||||
</order>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import {useStore} from "@/store/store";
|
||||
import {useOrderStore} from "@/store/store";
|
||||
import LimitPrice from "@/components/LimitPrice.vue";
|
||||
import Order from "@/components/Order.vue";
|
||||
import {computed, ref} from "vue";
|
||||
import {newTimeConstraint, TimeMode} from "@/blockchain/orderlib.js";
|
||||
import {limitConstraint, maxFraction} from "@/orderbuild.js";
|
||||
import {validateMax} from "@/validate.js";
|
||||
|
||||
const s = useStore()
|
||||
const os = useOrderStore()
|
||||
|
||||
const num = ref(3)
|
||||
const skew = ref(0)
|
||||
const rungs = computed(()=>{
|
||||
const n = num.value;
|
||||
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<n; i++ )
|
||||
result.push(a+i*delta)
|
||||
return result
|
||||
})
|
||||
const rungsFmt = computed(()=>{
|
||||
return rungs.value.map((r)=>r.toPrecision(5)) // todo precisions
|
||||
})
|
||||
const fractions = computed(()=>{
|
||||
const n = num.value
|
||||
const s = skew.value / 100
|
||||
const result = []
|
||||
if( s === 1 ) {
|
||||
result.push(1)
|
||||
for( let i=1; i<n; i++ )
|
||||
result.push(0)
|
||||
}
|
||||
else if( s === -1 ) {
|
||||
for( let i=1; i<n; i++ )
|
||||
result.push(0)
|
||||
result.push(1)
|
||||
}
|
||||
else {
|
||||
const mean = 1/n
|
||||
for( let i=0; i<n; i++ )
|
||||
result.push( mean * ( 1 - s * (2*i/(n-1)-1) ) )
|
||||
}
|
||||
return result
|
||||
})
|
||||
const amounts = computed( ()=>fractions.value.map((f)=>f*os.amount) )
|
||||
|
||||
function buildTranches() {
|
||||
const ts = []
|
||||
const n = num.value
|
||||
const mf = Number(maxFraction)
|
||||
for( let i=0; i<n; i++ ) {
|
||||
// todo optional deadline
|
||||
const cs = [limitConstraint(rungs.value[i])]
|
||||
const fraction = Math.min(mf, Math.ceil(mf * fractions.value[i]) )
|
||||
ts.push([fraction, cs])
|
||||
}
|
||||
return ts
|
||||
}
|
||||
|
||||
function validOrder() {
|
||||
return os.validOrder
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
|
||||
Reference in New Issue
Block a user