custom order placeholder
This commit is contained in:
99
src/components/CustomOrder.vue
Normal file
99
src/components/CustomOrder.vue
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
<template>
|
||||||
|
<order title="Custom" subtitle="Create your own dexorder" :tranches="buildTranches" :valid="validOrder">
|
||||||
|
<!-- todo times -->
|
||||||
|
<span><i>Coming soon!</i></span>
|
||||||
|
<!--
|
||||||
|
<limit-price :required="true" label="start price" :show-price="false"/>
|
||||||
|
<limit-price store-var="limitPrice2" :required="true" label="end price"/>
|
||||||
|
<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 {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 {validateRequired, validateTranches} from "@/validate.js";
|
||||||
|
import {MAX_FRACTION, newTranche} from "@/blockchain/orderlib.js";
|
||||||
|
|
||||||
|
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<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 = os.tranches
|
||||||
|
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.totalAmount) )
|
||||||
|
|
||||||
|
function buildTranches() {
|
||||||
|
const ts = []
|
||||||
|
const n = os.tranches
|
||||||
|
for( let i=0; i<n; i++ ) {
|
||||||
|
// todo optional deadline
|
||||||
|
const fraction = Math.min(MAX_FRACTION, Math.ceil(MAX_FRACTION * fractions.value[i]) )
|
||||||
|
const tranche = newTranche({fraction})
|
||||||
|
applyLimit(tranche, rungs.value[i])
|
||||||
|
ts.push(tranche)
|
||||||
|
}
|
||||||
|
return ts
|
||||||
|
}
|
||||||
|
|
||||||
|
function validOrder() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped lang="scss">
|
||||||
|
@use "src/styles/vars" as *;
|
||||||
|
|
||||||
|
</style>
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<order title="Diagonal" subtitle="Trade trends and channels" :tranches="buildTranches" :valid="validOrder">
|
<order title="Diagonal" subtitle="Trade trends and channels" :tranches="buildTranches" :valid="validOrder">
|
||||||
<!-- todo times -->
|
<!-- todo times -->
|
||||||
<span><i>Coming soon after Tim's wrist heals!</i></span>
|
<span><i>Coming soon!</i></span>
|
||||||
<!--
|
<!--
|
||||||
<limit-price :required="true" label="start price" :show-price="false"/>
|
<limit-price :required="true" label="start price" :show-price="false"/>
|
||||||
<limit-price store-var="limitPrice2" :required="true" label="end price"/>
|
<limit-price store-var="limitPrice2" :required="true" label="end price"/>
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
<v-list-item prepend-icon="mdi-clock-outline" title="DCA" subtitle="Spread order across time" @click="nav('twap')"></v-list-item>
|
<v-list-item prepend-icon="mdi-clock-outline" title="DCA" subtitle="Spread order across time" @click="nav('twap')"></v-list-item>
|
||||||
<v-list-item prepend-icon="mdi-menu" title="Ladder" subtitle="Multiple price levels" @click="nav('ladder')"></v-list-item>
|
<v-list-item prepend-icon="mdi-menu" title="Ladder" subtitle="Multiple price levels" @click="nav('ladder')"></v-list-item>
|
||||||
<v-list-item prepend-icon="mdi-vector-line" title="Diagonal" subtitle="Trade trends and channels" @click="nav('diagonal')"></v-list-item>
|
<v-list-item prepend-icon="mdi-vector-line" title="Diagonal" subtitle="Trade trends and channels" @click="nav('diagonal')"></v-list-item>
|
||||||
|
<v-list-item prepend-icon="mdi-hammer-wrench" title="Custom" subtitle="Create your own" @click="nav('custom')"></v-list-item>
|
||||||
</v-list>
|
</v-list>
|
||||||
</v-navigation-drawer>
|
</v-navigation-drawer>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -48,6 +48,11 @@ const routes = [
|
|||||||
name: 'Diagonal',
|
name: 'Diagonal',
|
||||||
component: () => import(/* webpackChunkName: "diagonal" */ '@/components/DiagonalOrder.vue'),
|
component: () => import(/* webpackChunkName: "diagonal" */ '@/components/DiagonalOrder.vue'),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: '/custom',
|
||||||
|
name: 'Custom',
|
||||||
|
component: () => import(/* webpackChunkName: "custom" */ '@/components/CustomOrder.vue'),
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user