interactive horizontal limit lines
This commit is contained in:
@@ -2,10 +2,53 @@ 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";
|
||||
import {defineStore} from "pinia";
|
||||
import {computed, ref} from "vue";
|
||||
|
||||
|
||||
export function applyLimit(tranche, price=null, isMinimum=null) {
|
||||
if( price === null ) {
|
||||
function unimplemented() { throw Error('Unimplemented') }
|
||||
|
||||
// Builders are data objects which store a configuration state
|
||||
function TrancheBuilder( component, options = {}) {
|
||||
const id = 'builder-'+Date.now();
|
||||
return {id, component, options, points: {}, shapes: {}, props: {}, build: unimplemented}
|
||||
}
|
||||
|
||||
|
||||
export const useChartOrderStore = defineStore('chart_orders', () => {
|
||||
const builderIdList = ref([]) // this is where we keep the UI ordering
|
||||
const builderList = computed(()=>{
|
||||
console.log('builder list', builderIdList.value.map((id)=>builderDict.value[id]))
|
||||
return builderIdList.value.map((id)=>builderDict.value[id])
|
||||
}) // convenience
|
||||
const builderDict = ref({}) // builders stored by id
|
||||
|
||||
const drawing = ref(false)
|
||||
const drawingCallbacks = ref(null) // only during draw mode
|
||||
|
||||
function addBuilder(component, options={}) {
|
||||
const b = TrancheBuilder(component,options)
|
||||
builderIdList.value.push(b.id)
|
||||
builderDict.value[b.id] = b
|
||||
}
|
||||
|
||||
function touchBuilder(builder) {
|
||||
// noinspection SillyAssignmentJS
|
||||
builderIdList.value = builderIdList.value
|
||||
builderDict.value[builder.id] = builder
|
||||
}
|
||||
|
||||
function removeBuilder(builder) {
|
||||
builderIdList.value = builderIdList.value.filter((v)=>v!==builder.id)
|
||||
delete builderDict.value[builder.id]
|
||||
}
|
||||
|
||||
return { builderList, builderDict, drawing, drawingCallbacks, addBuilder, removeBuilder, touchBuilder }
|
||||
})
|
||||
|
||||
|
||||
export function applyLimit(tranche, price = null, isMinimum = null) {
|
||||
if (price === null) {
|
||||
const os = useOrderStore()
|
||||
price = os.limitPrice
|
||||
if (!price)
|
||||
@@ -29,27 +72,26 @@ function computeInterceptSlope(time0, price0, time1, price1) {
|
||||
}
|
||||
|
||||
|
||||
export function linePointsValue(time0, price0, time1, price1, unixTime=null) {
|
||||
if(unixTime===null)
|
||||
export function linePointsValue(time0, price0, time1, price1, unixTime = null) {
|
||||
if (unixTime === null)
|
||||
unixTime = timestamp()
|
||||
try {
|
||||
const [intercept, slope] = computeInterceptSlope(time0, price0, time1, price1)
|
||||
return intercept + unixTime * slope
|
||||
}
|
||||
catch (e) {
|
||||
console.log('error computing line',e)
|
||||
} catch (e) {
|
||||
console.log('error computing line', e)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export function applyLinePoints(tranche, time0, price0, time1, price1, isMinimum=null) {
|
||||
export function applyLinePoints(tranche, time0, price0, time1, price1, isMinimum = null) {
|
||||
const [intercept, slope] = computeInterceptSlope(time0, price0, time1, price1);
|
||||
applyLine(tranche, intercept, slope, isMinimum)
|
||||
}
|
||||
|
||||
|
||||
export function applyLine(tranche, intercept, slope, isMinimum=null) {
|
||||
export function applyLine(tranche, intercept, slope, isMinimum = null) {
|
||||
console.log('intercept, slope', intercept, slope)
|
||||
// intercept and slope are still in "human" units of decimal-adjusted prices
|
||||
const os = useOrderStore()
|
||||
@@ -62,7 +104,7 @@ export function applyLine(tranche, intercept, slope, isMinimum=null) {
|
||||
console.log('inverted b, m, cur', inverted, b, m, cur)
|
||||
m = encodeIEE754(m)
|
||||
b = encodeIEE754(b)
|
||||
if( isMinimum === null )
|
||||
if (isMinimum === null)
|
||||
isMinimum = os.limitIsMinimum
|
||||
console.log('limit is minimum', isMinimum)
|
||||
if (isMinimum) {
|
||||
@@ -83,8 +125,8 @@ export function timesliceTranches() {
|
||||
const timeUnitIndex = os.timeUnitIndex;
|
||||
let duration =
|
||||
timeUnitIndex === 0 ? interval * 60 : // minutes
|
||||
timeUnitIndex === 1 ? interval * 60 * 60 : // hours
|
||||
interval * 24 * 60 * 60; // days
|
||||
timeUnitIndex === 1 ? interval * 60 * 60 : // hours
|
||||
interval * 24 * 60 * 60; // days
|
||||
let window
|
||||
if (!os.intervalIsTotal) {
|
||||
window = duration
|
||||
@@ -92,7 +134,7 @@ export function timesliceTranches() {
|
||||
} else {
|
||||
window = Math.round(duration / n)
|
||||
}
|
||||
if( window < 60 )
|
||||
if (window < 60)
|
||||
window = 60 // always allow at least one minute for execution
|
||||
const amtPerTranche = Math.ceil(MAX_FRACTION / n)
|
||||
duration -= 15 // subtract 15 seconds so the last tranche completes before the deadline
|
||||
@@ -109,3 +151,4 @@ export function timesliceTranches() {
|
||||
}
|
||||
return ts
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user