ordershape fixes
This commit is contained in:
@@ -51,7 +51,7 @@ function changeInterval(interval, _timeframe) {
|
||||
|
||||
function dataLoaded() {
|
||||
const range = chartMeanRange()
|
||||
console.log('new mean range', range)
|
||||
console.log('new mean range', range,)
|
||||
co.meanRange = range
|
||||
}
|
||||
|
||||
@@ -400,6 +400,8 @@ export function deleteShapeId(id) {
|
||||
chart.removeEntity(id)
|
||||
}
|
||||
|
||||
const MEAN_RANGE_MULTIPLIER = 10
|
||||
|
||||
function chartMeanRange() {
|
||||
let range = 0
|
||||
const series = chart.getSeries()
|
||||
@@ -415,5 +417,5 @@ function chartMeanRange() {
|
||||
range /= count
|
||||
else
|
||||
range = 1
|
||||
return range
|
||||
return range * MEAN_RANGE_MULTIPLIER
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import {DISTANT_FUTURE, DISTANT_PAST} from "@/blockchain/orderlib.js";
|
||||
import {DLine, HLine} from "@/charts/shape.js";
|
||||
import {allocationText, DLine, HLine} from "@/charts/shape.js";
|
||||
import {createShape, deleteShapeId} from "@/charts/chart.js";
|
||||
import {allocationText} from "@/orderbuild.js";
|
||||
import {timestamp} from "@/misc.js";
|
||||
|
||||
export class OrderShapes {
|
||||
@@ -63,28 +62,37 @@ class TrancheShapes {
|
||||
const symbol = this.symbol
|
||||
const scale = 10**symbol.decimals;
|
||||
const buy = order.tokenIn === this.symbol.quote.a
|
||||
const inverted = buy === symbol.inverted
|
||||
const amountIsBase = buy !== this.status.order.amountIsInput
|
||||
const filledAmount = this.status.order.amountIsInput ? f.filledIn : f.filledOut;
|
||||
const amount = Number(filledAmount)
|
||||
* 10 ** -(amountIsBase ? this.symbol.base.d : this.symbol.quote.d)
|
||||
const weight = Number(filledAmount) / Number(this.status.order.amount)
|
||||
const amountSymbol = amountIsBase ? this.symbol.base.s : this.symbol.quote.s
|
||||
console.log('fillpoint', buy, filledAmount, this.status.order, this.symbol)
|
||||
const time = f.time
|
||||
const out = Number(f.filledOut) / (1-this.status.order.route.fee/1000000)
|
||||
let price = out / Number(f.filledIn)
|
||||
if (inverted)
|
||||
if (buy)
|
||||
price = 1/price
|
||||
price *= scale
|
||||
// console.log('price', price)
|
||||
const channel = buy?'low':'high';
|
||||
const text = (buy ? 'Buy ' : 'Sell ') + allocationText(null, f.filled, '')
|
||||
const text = (buy ? 'Buy ' : 'Sell ') + allocationText(weight, amount, amountSymbol, '\n')
|
||||
const s = createShape(buy?'arrow_up':'arrow_down', {time, price}, {channel,text,lock:true})
|
||||
// console.log('created fill shape at', time, price)
|
||||
this.fills.push(s)
|
||||
}
|
||||
|
||||
createLine(slope, intercept) {
|
||||
createLine(slope, intercept, amount) {
|
||||
const t = this.tranche
|
||||
const status = this.status
|
||||
const symbol = this.symbol
|
||||
const scale = 10**symbol.decimals;
|
||||
const buy = status.order.tokenIn === this.symbol.quote.a
|
||||
const inverted = buy === symbol.inverted
|
||||
amount = Number(amount)
|
||||
* 10 ** -(buy ? this.symbol.base.d : this.symbol.quote.d)
|
||||
const amountSymbol = buy ? this.symbol.base.s : this.symbol.quote.s
|
||||
const color = buy ? 'green' : 'red'
|
||||
if (intercept !== 0 || slope !== 0) {
|
||||
// console.log('tranche line', intercept, slope)
|
||||
@@ -96,19 +104,16 @@ class TrancheShapes {
|
||||
price *= scale
|
||||
// horizontal line
|
||||
// console.log('hline', price, inverted)
|
||||
const s = new HLine({price, color,
|
||||
// todo allocation maxAllocation amount amountSymbol
|
||||
}, null, null, null, true)
|
||||
const model = {price, color, maxAllocation: status.order.amount, amount, amountSymbol};
|
||||
const s = new HLine(model, null, null, null, true)
|
||||
this.shapes.push(s)
|
||||
} else {
|
||||
// diagonal line
|
||||
let startTime = t.startTime
|
||||
// noinspection EqualityComparisonWithCoercionJS
|
||||
if (startTime == DISTANT_PAST)
|
||||
if (startTime === DISTANT_PAST)
|
||||
startTime = 1231006505 // use Bitcoin genesis as the drawing point's start time. unnecessary.
|
||||
let endTime = t.endTime
|
||||
// noinspection EqualityComparisonWithCoercionJS
|
||||
if (endTime == DISTANT_FUTURE)
|
||||
if (endTime === DISTANT_FUTURE)
|
||||
endTime = timestamp() // use "now" as the drawing point's time
|
||||
let startPrice = (intercept + slope * startTime);
|
||||
let endPrice = (intercept + slope * endTime);
|
||||
@@ -118,15 +123,17 @@ class TrancheShapes {
|
||||
}
|
||||
startPrice *= scale
|
||||
endPrice *= scale
|
||||
// console.log('dline', startTime, endTime, DISTANT_FUTURE, startPrice, endPrice)
|
||||
const s = new DLine({
|
||||
pointA: {time: t.startTime, price: startPrice},
|
||||
pointB: {time: t.endTime, price: endPrice},
|
||||
console.log('dline', startTime, endTime, DISTANT_FUTURE, startPrice, endPrice)
|
||||
// noinspection EqualityComparisonWithCoercionJS
|
||||
const model = {
|
||||
pointA: {time: startTime, price: startPrice},
|
||||
pointB: {time: endTime, price: endPrice},
|
||||
extendLeft: t.startTime === DISTANT_PAST,
|
||||
extendRight: t.endTime === DISTANT_FUTURE,
|
||||
color,
|
||||
// todo allocation maxAllocation amount amountSymbol
|
||||
}, null, null, null, true)
|
||||
maxAllocation: status.order.amount, amount, amountSymbol,
|
||||
};
|
||||
const s = new DLine(model, null, null, null, true)
|
||||
this.shapes.push(s)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
import {invokeCallback, mixin} from "@/common.js";
|
||||
import {chart, createShape, deleteShapeId, dragging, draggingShapeIds, drawShape, widget} from "@/charts/chart.js";
|
||||
import {allocationText} from "@/orderbuild.js";
|
||||
import Color from "color";
|
||||
import {dirtyItems, dirtyPoints, pointsToTvOhlcStart} from "@/charts/chart-misc.js";
|
||||
|
||||
@@ -39,6 +38,25 @@ export const ShapeType = {
|
||||
}
|
||||
|
||||
|
||||
export function allocationText(weight, amount, symbol, separator = ' ') {
|
||||
const hasAmount = amount !== null && amount !== undefined && amount > 0
|
||||
if (hasAmount)
|
||||
amount = Number(amount)
|
||||
const hasWeight = weight !== null && weight !== undefined
|
||||
if (hasWeight)
|
||||
weight = Number(weight)
|
||||
let text = ''
|
||||
if (hasWeight)
|
||||
text += `${(weight * 100).toFixed(1)}%`
|
||||
const hasSymbol = symbol !== null && symbol !== undefined
|
||||
if (hasAmount && hasSymbol) {
|
||||
if (hasWeight)
|
||||
text += separator
|
||||
text += `${amount.toPrecision(3).toLocaleString('fullwide')} ${symbol}`
|
||||
}
|
||||
return text
|
||||
}
|
||||
|
||||
export class Shape {
|
||||
|
||||
constructor(type, onModel=null, onDelete=null, props=null, readonly=false, overrides={}) {
|
||||
@@ -555,6 +573,7 @@ export class DLine extends Line {
|
||||
if (model.pointA === null && model.pointB === null)
|
||||
this.delete()
|
||||
else {
|
||||
this.setProps({extendLeft:model.extendLeft, extendRight: model.extendRight})
|
||||
if ('pointA' in model && 'pointB' in model) {
|
||||
const newPoints = [model.pointA, model.pointB];
|
||||
const oldPoints = [this.model.pointA, this.model.pointB];
|
||||
@@ -564,7 +583,6 @@ export class DLine extends Line {
|
||||
this.setPoints(newPoints)
|
||||
}
|
||||
}
|
||||
this.setProps({extendLeft:model.extendLeft, extendRight: model.extendRight})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user