chart-based route finding

This commit is contained in:
Tim
2024-02-27 22:20:23 -04:00
parent fc126955b6
commit 9a5d7a1ce5
12 changed files with 126 additions and 46 deletions

View File

@@ -1,10 +1,28 @@
import {useChartOrderStore} from "@/orderbuild.js";
import {invokeCallbacks, prototype} from "@/common.js";
import datafeed from "@/charts/datafeed.js";
import datafeed, {lookupSymbol} from "@/charts/datafeed.js";
export let widget = null
export let chart = null
export let crosshairPoint = null
let symbolChangedCbs = [] // callbacks for TV's chart.onSymbolChanged()
let lastSymbolChangedArgs = null
export function addSymbolChangedCallback(cb) {
symbolChangedCbs.push(cb)
}
export function removeSymbolChangedCallback(cb) {
symbolChangedCbs = symbolChangedCbs.filter((i)=>i!==cb)
}
function changeSymbol(symbol) {
console.log('tv changeSymbol', symbol)
const info = lookupSymbol(symbol.full_name)
lastSymbolChangedArgs = info
symbolChangedCbs.forEach((cb)=>cb(info))
}
const subscribeEvents = [
'toggle_sidebar', 'indicators_dialog', 'toggle_header', 'edit_object_dialog', 'chart_load_requested',
@@ -51,7 +69,10 @@ function initChart() {
console.log('init chart')
chart = widget.activeChart()
chart.crossHairMoved().subscribe(null, (point)=>setTimeout(()=>handleCrosshairMovement(point),0) )
chart.onSymbolChanged().subscribe(null, changeSymbol);
changeSymbol(chart.symbolExt())
useChartOrderStore().chartReady = true
console.log('chart ready')
}

View File

@@ -57,7 +57,7 @@ function addSymbol(p, base, quote, inverted) {
const longExchange = ['Uniswap v2', 'Uniswap v3',][p.e]
const description = `${base.n} / ${quote.n}`
const type = 'swap'
_symbols[full_name] = {symbol, full_name, description, exchange, type, inverted,}
_symbols[full_name] = {symbol, full_name, description, exchange, type, inverted, base, quote}
indexes[full_name] = {
// key
id: full_name,
@@ -84,7 +84,6 @@ function addSymbol(p, base, quote, inverted) {
// }
async function getAllSymbols() {
if (_symbols===null) {
_symbols = {}
for (const t of metadata.t)
@@ -112,6 +111,10 @@ async function getAllSymbols() {
return _symbols
}
export function lookupSymbol(fullName) {
return _symbols[fullName]
}
export default {
onReady: (callback) => {
console.log('[onReady]: Method call');