From 2083ce1cc96990f3fc5cdf71c0572b6f15200499 Mon Sep 17 00:00:00 2001 From: Tim Date: Fri, 3 May 2024 13:42:37 -0400 Subject: [PATCH] applyLine() refactor/fix --- src/charts/chart.js | 9 ++++++++- src/components/chart/LimitBuilder.vue | 3 +-- src/orderbuild.js | 9 ++++----- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/charts/chart.js b/src/charts/chart.js index 713441c..2808ce4 100644 --- a/src/charts/chart.js +++ b/src/charts/chart.js @@ -27,7 +27,6 @@ function changeSymbol(symbol) { lastSymbolChangedArgs = info symbolChangedCbs.forEach((cb)=>cb(info)) co.selectedSymbol = info - co.meanRange = chartMeanRange() } @@ -36,6 +35,13 @@ function changeInterval(interval, _timeframe) { } +function dataLoaded() { + const range = chartMeanRange() + console.log('new mean range', range) + co.meanRange = range +} + + /* TradingView event keystrings const subscribeEvents = [ 'toggle_sidebar', 'indicators_dialog', 'toggle_header', 'edit_object_dialog', 'chart_load_requested', @@ -83,6 +89,7 @@ function initChart() { chart.crossHairMoved().subscribe(null, (point)=>setTimeout(()=>handleCrosshairMovement(point),0) ) chart.onSymbolChanged().subscribe(null, changeSymbol) chart.onIntervalChanged().subscribe(null, changeInterval) + chart.onDataLoaded().subscribe(null, dataLoaded) const tzapi = chart.getTimezoneApi(); tzapi.onTimezoneChanged().subscribe(null, (tz)=>{if (tz==='exchange') tz='Etc/UTC'; s.timeZone=tz}) s.timeZone = tzapi.getTimezone().id diff --git a/src/components/chart/LimitBuilder.vue b/src/components/chart/LimitBuilder.vue index cb5029f..d4c05d0 100644 --- a/src/components/chart/LimitBuilder.vue +++ b/src/components/chart/LimitBuilder.vue @@ -48,7 +48,6 @@ import {useOrderStore, useStore} from "@/store/store.js"; import {MAX_FRACTION, newTranche} from "@/blockchain/orderlib.js"; import RungBuilder from "@/components/chart/RungBuilder.vue"; import {computed, ref} from "vue"; -import {chartMeanRange} from "@/charts/chart.js"; import {HLine} from "@/charts/shape.js"; const s = useStore() @@ -92,7 +91,7 @@ function buildTranches() { }) const symbol = co.selectedSymbol console.log('symbol', symbol) - applyLine(t, , p, 0, symbol.decimals, symbol.inverted) + applyLine(t, order.buy, p, 0, symbol.decimals, symbol.inverted) tranches.push(t) } return tranches diff --git a/src/orderbuild.js b/src/orderbuild.js index d80c666..79fb74b 100644 --- a/src/orderbuild.js +++ b/src/orderbuild.js @@ -5,7 +5,6 @@ import {encodeIEE754} from "@/common.js"; import {defineStore} from "pinia"; import {computed, ref} from "vue"; import Color from "color"; -import {chartMeanRange} from "@/charts/chart.js"; export const MIN_EXECUTION_TIME = 60 // give at least one full minute for each tranche to trigger @@ -147,16 +146,16 @@ export function applyLinePoints(tranche, buy, time0, price0, time1, price1, pool export function applyLine(tranche, buy, intercept, slope, poolDecimals, inverted) { - console.log('intercept, slope', intercept, slope) // intercept and slope are still in "human" units of decimal-adjusted prices const scale = 10 ** -poolDecimals let m = slope === 0 ? 0 : inverted ? -scale / slope : scale * slope let b = inverted ? scale / intercept : scale * intercept - const cur = b + timestamp() * m - console.log('inverted b, m, cur', inverted, b, m, cur) + // const cur = b + timestamp() * m + // console.log('inverted b, m, cur', inverted, b, m, cur) m = encodeIEE754(m) b = encodeIEE754(b) - let isMinimum = !(buy ^ inverted) + const isMinimum = !(buy ^ inverted) + console.log('applyLine', buy, intercept, slope, poolDecimals, inverted, isMinimum) if (isMinimum) { tranche.minIntercept = b; tranche.minSlope = m;