applyLine() refactor/fix
This commit is contained in:
@@ -27,7 +27,6 @@ function changeSymbol(symbol) {
|
|||||||
lastSymbolChangedArgs = info
|
lastSymbolChangedArgs = info
|
||||||
symbolChangedCbs.forEach((cb)=>cb(info))
|
symbolChangedCbs.forEach((cb)=>cb(info))
|
||||||
co.selectedSymbol = 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
|
/* TradingView event keystrings
|
||||||
const subscribeEvents = [
|
const subscribeEvents = [
|
||||||
'toggle_sidebar', 'indicators_dialog', 'toggle_header', 'edit_object_dialog', 'chart_load_requested',
|
'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.crossHairMoved().subscribe(null, (point)=>setTimeout(()=>handleCrosshairMovement(point),0) )
|
||||||
chart.onSymbolChanged().subscribe(null, changeSymbol)
|
chart.onSymbolChanged().subscribe(null, changeSymbol)
|
||||||
chart.onIntervalChanged().subscribe(null, changeInterval)
|
chart.onIntervalChanged().subscribe(null, changeInterval)
|
||||||
|
chart.onDataLoaded().subscribe(null, dataLoaded)
|
||||||
const tzapi = chart.getTimezoneApi();
|
const tzapi = chart.getTimezoneApi();
|
||||||
tzapi.onTimezoneChanged().subscribe(null, (tz)=>{if (tz==='exchange') tz='Etc/UTC'; s.timeZone=tz})
|
tzapi.onTimezoneChanged().subscribe(null, (tz)=>{if (tz==='exchange') tz='Etc/UTC'; s.timeZone=tz})
|
||||||
s.timeZone = tzapi.getTimezone().id
|
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 {MAX_FRACTION, newTranche} from "@/blockchain/orderlib.js";
|
||||||
import RungBuilder from "@/components/chart/RungBuilder.vue";
|
import RungBuilder from "@/components/chart/RungBuilder.vue";
|
||||||
import {computed, ref} from "vue";
|
import {computed, ref} from "vue";
|
||||||
import {chartMeanRange} from "@/charts/chart.js";
|
|
||||||
import {HLine} from "@/charts/shape.js";
|
import {HLine} from "@/charts/shape.js";
|
||||||
|
|
||||||
const s = useStore()
|
const s = useStore()
|
||||||
@@ -92,7 +91,7 @@ function buildTranches() {
|
|||||||
})
|
})
|
||||||
const symbol = co.selectedSymbol
|
const symbol = co.selectedSymbol
|
||||||
console.log('symbol', symbol)
|
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)
|
tranches.push(t)
|
||||||
}
|
}
|
||||||
return tranches
|
return tranches
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import {encodeIEE754} from "@/common.js";
|
|||||||
import {defineStore} from "pinia";
|
import {defineStore} from "pinia";
|
||||||
import {computed, ref} from "vue";
|
import {computed, ref} from "vue";
|
||||||
import Color from "color";
|
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
|
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) {
|
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
|
// intercept and slope are still in "human" units of decimal-adjusted prices
|
||||||
const scale = 10 ** -poolDecimals
|
const scale = 10 ** -poolDecimals
|
||||||
let m = slope === 0 ? 0 : inverted ? -scale / slope : scale * slope
|
let m = slope === 0 ? 0 : inverted ? -scale / slope : scale * slope
|
||||||
let b = inverted ? scale / intercept : scale * intercept
|
let b = inverted ? scale / intercept : scale * intercept
|
||||||
const cur = b + timestamp() * m
|
// const cur = b + timestamp() * m
|
||||||
console.log('inverted b, m, cur', inverted, b, m, cur)
|
// console.log('inverted b, m, cur', inverted, b, m, cur)
|
||||||
m = encodeIEE754(m)
|
m = encodeIEE754(m)
|
||||||
b = encodeIEE754(b)
|
b = encodeIEE754(b)
|
||||||
let isMinimum = !(buy ^ inverted)
|
const isMinimum = !(buy ^ inverted)
|
||||||
|
console.log('applyLine', buy, intercept, slope, poolDecimals, inverted, isMinimum)
|
||||||
if (isMinimum) {
|
if (isMinimum) {
|
||||||
tranche.minIntercept = b;
|
tranche.minIntercept = b;
|
||||||
tranche.minSlope = m;
|
tranche.minSlope = m;
|
||||||
|
|||||||
Reference in New Issue
Block a user