DCA builder looking good but can't place orders yet
This commit is contained in:
@@ -2,6 +2,8 @@ import {useChartOrderStore} from "@/orderbuild.js";
|
||||
import {invokeCallbacks, prototype} from "@/common.js";
|
||||
import {DataFeed, initFeeDropdown, lookupSymbol} from "@/charts/datafeed.js";
|
||||
import {intervalToSeconds, SingletonCoroutine} from "@/misc.js";
|
||||
import {store} from "core-js/internals/reflect-metadata.js";
|
||||
import {useStore} from "@/store/store.js";
|
||||
|
||||
export let widget = null
|
||||
export let chart = null
|
||||
@@ -9,6 +11,10 @@ export let crosshairPoint = null
|
||||
let symbolChangedCbs = [] // callbacks for TV's chart.onSymbolChanged()
|
||||
let lastSymbolChangedArgs = null
|
||||
|
||||
|
||||
const s = useStore()
|
||||
const co = useChartOrderStore()
|
||||
|
||||
export function addSymbolChangedCallback(cb) {
|
||||
symbolChangedCbs.push(cb)
|
||||
}
|
||||
@@ -21,12 +27,12 @@ function changeSymbol(symbol) {
|
||||
const info = lookupSymbol(symbol.full_name)
|
||||
lastSymbolChangedArgs = info
|
||||
symbolChangedCbs.forEach((cb)=>cb(info))
|
||||
useChartOrderStore().selectedSymbol = info
|
||||
co.selectedSymbol = info
|
||||
}
|
||||
|
||||
|
||||
function changeInterval(interval, _timeframe) {
|
||||
useChartOrderStore().intervalSecs = intervalToSeconds(interval)
|
||||
co.intervalSecs = intervalToSeconds(interval)
|
||||
}
|
||||
|
||||
|
||||
@@ -77,11 +83,14 @@ function initChart() {
|
||||
chart.crossHairMoved().subscribe(null, (point)=>setTimeout(()=>handleCrosshairMovement(point),0) )
|
||||
chart.onSymbolChanged().subscribe(null, changeSymbol)
|
||||
chart.onIntervalChanged().subscribe(null, changeInterval)
|
||||
const tzapi = chart.getTimezoneApi();
|
||||
tzapi.onTimezoneChanged().subscribe(null, (tz)=>s.timeZone=tz )
|
||||
s.timeZone = tzapi.getTimezone().id
|
||||
// chart.onHoveredSourceChanged().subscribe(null, ()=>console.log('hovered source changed', arguments))
|
||||
// chart.selection().onChanged().subscribe(null, s => console.log('selection', chart.selection().allSources()));
|
||||
changeSymbol(chart.symbolExt())
|
||||
changeInterval(widget.symbolInterval().interval)
|
||||
useChartOrderStore().chartReady = true
|
||||
co.chartReady = true
|
||||
console.log('chart ready')
|
||||
}
|
||||
|
||||
@@ -128,7 +137,6 @@ let drawingCallbacks = null
|
||||
export function drawShape(shapeType, ...callbacks) {
|
||||
// puts the chart into a line-drawing mode for a new shape
|
||||
console.log('drawShape', callbacks, shapeType.name, shapeType.code)
|
||||
const co = useChartOrderStore()
|
||||
if( drawingCallbacks )
|
||||
invokeCallbacks(drawingCallbacks, 'onUndraw')
|
||||
drawingCallbacks = callbacks
|
||||
@@ -141,7 +149,6 @@ export function drawShape(shapeType, ...callbacks) {
|
||||
|
||||
|
||||
export function createShape(shapeType, points, options={}, ...callbacks) {
|
||||
const co = useChartOrderStore()
|
||||
drawingCallbacks = null
|
||||
co.drawing = false
|
||||
options.shape = shapeType.code
|
||||
@@ -163,7 +170,7 @@ export function createShape(shapeType, points, options={}, ...callbacks) {
|
||||
if( callbacks.length )
|
||||
shapeCallbacks[shapeId] = callbacks
|
||||
const shape = chart.getShapeById(shapeId)
|
||||
console.log('tvShape created', shapeId)
|
||||
// console.log('tvShape created', shapeId)
|
||||
shape.bringToFront()
|
||||
const props = shape.getProperties()
|
||||
invokeCallbacks(callbacks, 'onCreate', shapeId, shape, points, props)
|
||||
@@ -174,7 +181,6 @@ export function createShape(shapeType, points, options={}, ...callbacks) {
|
||||
export let allShapeIds = []
|
||||
|
||||
export function cancelDrawing() {
|
||||
const co = useChartOrderStore()
|
||||
if (co.drawing) {
|
||||
co.drawing = false
|
||||
widget.selectLineTool(previousDrawingTool)
|
||||
@@ -190,7 +196,7 @@ function onSelectedLineToolChanged() {
|
||||
console.log('line tool changed', tool)
|
||||
if (drawingTool===null)
|
||||
drawingTool = tool
|
||||
else if (tool!==drawingTool && useChartOrderStore().drawing)
|
||||
else if (tool!==drawingTool && co.drawing)
|
||||
cancelDrawing();
|
||||
}
|
||||
|
||||
@@ -221,7 +227,6 @@ const crosshairHandler = new SingletonCoroutine(doHandleCrosshairMovement, 0)
|
||||
function doHandleCrosshairMovement(point) {
|
||||
// console.log('crosshair moved')
|
||||
crosshairPoint = point
|
||||
const co = useChartOrderStore()
|
||||
if (co.drawing)
|
||||
invokeCallbacks(drawingCallbacks, 'onRedraw')
|
||||
else if (dragging) {
|
||||
@@ -304,8 +309,6 @@ function doHandleDrawingEvent(id, event) {
|
||||
}
|
||||
if (event === 'create') {
|
||||
allShapeIds.push(id)
|
||||
|
||||
const co = useChartOrderStore();
|
||||
const callbacks = drawingCallbacks
|
||||
// console.log('drawing callbacks', callbacks)
|
||||
if (callbacks !== null) {
|
||||
|
||||
Reference in New Issue
Block a user