rate limit DCA

This commit is contained in:
tim
2025-03-19 20:27:10 -04:00
parent cd84e7c3c9
commit 8750951de5
14 changed files with 651 additions and 325 deletions

View File

@@ -1,6 +1,6 @@
import {useChartOrderStore} from "@/orderbuild.js";
import {invokeCallbacks, prototype} from "@/common.js";
import {DataFeed, feelessTickerKey, getAllSymbols, lookupSymbol} from "@/charts/datafeed.js";
import {DataFeed, defaultSymbol, feelessTickerKey, getAllSymbols, lookupSymbol} from "@/charts/datafeed.js";
import {intervalToSeconds, SingletonCoroutine} from "@/misc.js";
import {usePrefStore, useStore} from "@/store/store.js";
import {tvCustomThemes} from "../../theme.js";
@@ -24,9 +24,10 @@ export function removeSymbolChangedCallback(cb) {
}
function symbolChanged(symbol) {
const info = symbol===null ? null : lookupSymbol(symbol.ticker)
const info = symbol===null ? (defaultSymbol===null?'default':defaultSymbol) : lookupSymbol(symbol.ticker)
co.selectedSymbol = info
prefs.selectedTicker = info?.ticker
console.log('setting prefs ticker', info.ticker)
prefs.selectedTicker = info.ticker
symbolChangedCbs.forEach((cb) => cb(info))
updateFeeDropdown()
console.log('symbol changed', info)
@@ -149,6 +150,7 @@ export function initWidget(el) {
drawings_access: {type: 'white', tools: [],}, // show no tools
custom_themes: tvCustomThemes,
theme: useStore().theme,
timezone: prefs.timezone,
// Chart Overrides
// https://www.tradingview.com/charting-library-docs/latest/customization/overrides/chart-overrides
@@ -182,8 +184,7 @@ function initChart() {
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
tzapi.onTimezoneChanged().subscribe(null, (tz)=>{if (tz==='exchange') tz='Etc/UTC'; prefs.timezone=tz;})
// chart.onHoveredSourceChanged().subscribe(null, ()=>console.log('hovered source changed', arguments))
// chart.selection().onChanged().subscribe(null, s => console.log('selection', chart.selection().allSources()));
const symbolExt = chart.symbolExt();
@@ -358,7 +359,7 @@ function doHandleCrosshairMovement(point) {
const lpbe = shape._model._linePointBeingEdited
points[lpbe] = point
// console.log('drag calling onPoints', points, shape, lpbe)
invokeCallbacks(shapeCallbacks[shapeId], 'onPoints', shapeId, shape, points)
invokeCallbacks(shapeCallbacks[shapeId], 'onDrag', shapeId, shape, points)
}
}
else if (draggingShapeIds.length > 0) {

View File

@@ -131,8 +131,13 @@ function addSymbol(chainId, p, base, quote, inverted) {
else
feeGroups[feelessKey] = [[symbolInfo.address, symbolInfo.fee]]
symbolInfo.feeGroup = feeGroups[feelessKey]
if (defaultSymbol===null && !invertedDefault(symbolInfo.base.a, symbolInfo.quote.a))
if (defaultSymbol===null) {
console.log(`invertedDefault(${symbolInfo.base.s}, ${symbolInfo.quote.s})`,invertedDefault(symbolInfo.base.a, symbolInfo.quote.a))
}
if (defaultSymbol===null && !invertedDefault(symbolInfo.base.a, symbolInfo.quote.a)) {
console.log('setting default symbol', symbolInfo.base.s, symbolInfo.quote.s, symbolInfo.base.a, symbolInfo.quote.a)
defaultSymbol = _symbols[ticker]
}
log('new symbol', ticker, _symbols[ticker])
}
@@ -684,4 +689,4 @@ export const DataFeed = {
let _rolloverBumper = null
let defaultSymbol = null
export let defaultSymbol = null

View File

@@ -36,6 +36,7 @@ export const ShapeType = {
HLine: {name: 'Horizontal Line', code: 'horizontal_line', drawingProp: 'linetoolhorzline'},
VLine: {name: 'Vertical Line', code: 'vertical_line', drawingProp: 'linetoolvertline'},
PriceRange: {name: 'Price Range', code: 'price_range'},
DateRange: {name: 'Date Range', code: 'date_range', drawingProp: 'linetooldaterange'},
}
@@ -335,6 +336,8 @@ export class Shape {
onPoints(points) {} // the control points of an existing shape were changed
onDrag(points) { console.log('shape ondrag'); this.onPoints(points) }
setProps(props) {
if (!props || Object.keys(props).length===0) return
if (this.debug) console.log('setProps', this.id, props)
@@ -384,7 +387,6 @@ export class Shape {
onUndraw() {} // drawing was canceled by clicking on a different tool
onAddPoint() {} // the user clicked a point while drawing (that point is added to the points list)
onMove(points) {} // the shape was moved by dragging a drawing element not the control point
onDrag(points) {}
onHide(props) {}
onShow(props) {}
onClick() {} // the shape was selected
@@ -479,16 +481,6 @@ class ShapeTVCallbacks {
export class Line extends Shape {
onDrag(points) {
const s = this.tvShape();
if (this.debug) {
console.log('shape', s.id, s)
console.log('currentMovingPoint', s._source.currentMovingPoint())
console.log('startMovingPoint', s._source.startMovingPoint())
console.log('isBeingEdited', s._source.isBeingEdited())
console.log('state', s._source.state())
}
}
}
@@ -656,3 +648,17 @@ export class DLine extends Line {
}
*/
}
export class DateRange extends Shape {
constructor(model, onModel=null, onDelete=null, props=null) {
super(ShapeType.DateRange, onModel, onDelete, props)
}
setModel(model) {
super.setModel(model);
if (model.startTime !== this.model.startTime || model.endTime !== this.model.endTime)
this.setPoints([{time: model.startTime}, {time: model.endTime}])
}
}