LimitBuilder as RungBuilder; HLine fixes; cant place orders yet

This commit is contained in:
Tim
2024-04-16 18:50:14 -04:00
parent 65be28fb0a
commit 1a752d3080
4 changed files with 117 additions and 372 deletions

View File

@@ -150,7 +150,7 @@ export class Shape {
doCreate() {
// createShape(this.type, this.points, {overrides:this.props}, new ShapeTVCallbacks(this))
this.tvPoints = [...this.ourPoints]
this.id = createShape(this.type, this.ourPoints, {overrides:this.ourProps}, new ShapeTVCallbacks(this))
createShape(this.type, this.ourPoints, {overrides:this.ourProps}, new ShapeTVCallbacks(this))
if (this.debug) console.log('created', this.type.name, this.ourPoints, this.id)
}
@@ -171,7 +171,7 @@ export class Shape {
setPoints(points) {
// setting points to null will delete the shape from the chart. setting points to a valid value will cause the
// shape to be drawn.
if (this.debug) console.log('setPoints', points)
if (this.debug) console.log('setPoints', points, this.id)
this.ourPoints = points
if (points === null || !points.length)
this.delete()
@@ -185,15 +185,6 @@ export class Shape {
if (this.debug) console.log('not dragging. use setPoints.')
s.setPoints(points)
}
else {
if (this.debug) console.log('dragging. use QUIET setPoints.')
// quiet setPoints doesn't disturb tool editing mode
const i = s._pointsConverter.apiPointsToDataSource(points)
// s._model.startChangingLinetool(this._source)
s._model.changeLinePoints(s._source, i)
// s._model.endChangingLinetool(!0)
s._source.createServerPoints()
}
}
}
}
@@ -292,6 +283,7 @@ class ShapeTVCallbacks {
onCreate(shapeId, _tvShape, points, props) {
this.creating = true
this.shape.id = shapeId
invokeCallback(this.shape, 'onCreate', points, props)
}
@@ -371,10 +363,23 @@ export class Line extends Shape {
export class HLine extends Line {
constructor(model, onModel=null, onDelete=null, props=null) {
super(ShapeType.HLine, model, onModel, onDelete, props)
super(ShapeType.HLine, onModel, onDelete, props)
// Model
this.model.price = null
this.setModel(model) // call setModel at the end
}
delete() {
this.model.price = null
super.delete()
}
setModel(model) {
console.log('hline setModel', model)
super.setModel(model)
if (model.price !== undefined && model.price !== this.model.price) {
this.model.price = model.price
this.setPoints([{time:0,price:this.model.price}])
@@ -383,19 +388,8 @@ export class HLine extends Line {
onPoints(points) {
super.onPoints(points);
}
pointsFromModel(model) {
if (model.price === null || model.price===undefined) return null
// take any time available, or 0
const time =
this.ourPoints !== null && this.ourPoints.length > 0 ? this.ourPoints[0].time :
this.tvPoints !== null && this.tvPoints.length > 0 ? this.tvPoints[0].time : 0
return [{time:time, price:model.price}]
}
pointsToModel(points) {
return {price: this.ourPoints[0].price}
const price = points[0].price;
this.updateModel({price})
}
}
@@ -410,9 +404,9 @@ function timeAdjustmentTooSmall(orig, newValue) {
}
function ohlcStart(time) {
function nearestOhlcStart(time) {
const period = useChartOrderStore().intervalSecs
return Math.floor(time/period) * period
return Math.round(time/period) * period
}
@@ -426,38 +420,33 @@ export class VLine extends Line {
this.setModel(model) // call setModel at the end
}
onPoints(points) {
if (this.debug) console.log('vline onPoints', this.ourPoints, points)
super.onPoints(points);
const orig = this.ourPoints && this.ourPoints.length ? this.ourPoints[0].time : null
if (!timeAdjustmentTooSmall(orig, points[0].time)) {
if (this.debug) console.log('updateModel', points[0].time)
this.updateModel({time: points[0].time})
}
delete() {
this.model.time = null
super.delete()
}
setModel(model) {
if (this.debug) console.log('vline setModel', this.model.time, model )
super.setModel(model)
if (model.time !== undefined && model.time !== this.model.time) {
this.model.time = model.time
const time = ohlcStart(model.time);
const time = nearestOhlcStart(model.time);
if (this.debug) console.log('vline setPoints', this.id, time)
this.setPoints([{time, price:1}])
this.setPoints([{time, price:0}])
}
}
delete() {
this.model.time = null
super.delete()
onPoints(points) {
if (this.debug) console.log('vline onPoints', this.ourPoints, points)
super.onPoints(points);
const orig = this.ourPoints && this.ourPoints.length ? this.ourPoints[0].time : null
const time = points[0].time;
if (!timeAdjustmentTooSmall(orig, time)) {
if (this.debug) console.log('updateModel', time)
this.updateModel({time: time})
}
}
dirtyPoints(pointsA, pointsB) {
const a = pointsA ? pointsA[0].time : null
const b = pointsB ? pointsB[0].time : null
const result = !timeAdjustmentTooSmall(a, b)
if (this.debug) console.log('vline dirty points?', a, b, result)
return result
}
}