applyLine() refactor/fix
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user