arb1 redeploy
This commit is contained in:
@@ -18,12 +18,6 @@ export function nearestOhlcStart(timestamp, periodSeconds=null) {
|
||||
return Math.round((timestamp-OHLC_START) / periodSeconds) * periodSeconds + OHLC_START
|
||||
}
|
||||
|
||||
export function pointsToTvOhlcStart(points, periodSeconds=null) {
|
||||
return points === null ? null : points.map((p) => {
|
||||
return {time: nearestOhlcStart(p.time, periodSeconds), price: p.price}
|
||||
})
|
||||
}
|
||||
|
||||
export function dirtyPoints(pointsA, pointsB) {
|
||||
if (pointsA === undefined)
|
||||
return true
|
||||
|
||||
@@ -3,7 +3,9 @@
|
||||
import {invokeCallback, mixin} from "@/common.js";
|
||||
import {chart, createShape, deleteShapeId, dragging, draggingShapeIds, drawShape, widget} from "@/charts/chart.js";
|
||||
import Color from "color";
|
||||
import {dirtyItems, dirtyPoints, pointsToTvOhlcStart} from "@/charts/chart-misc.js";
|
||||
import {dirtyItems, dirtyPoints, nearestOhlcStart, pointsToTvOhlcStart} from "@/charts/chart-misc.js";
|
||||
import {readonly} from "vue";
|
||||
import {computeInterceptSlope} from "@/misc.js";
|
||||
|
||||
|
||||
//
|
||||
@@ -222,7 +224,7 @@ export class Shape {
|
||||
// createShape(this.type, this.points, {overrides:this.props}, new ShapeTVCallbacks(this))
|
||||
options = mixin(options, this.drawingOverrides())
|
||||
options['overrides'] = props
|
||||
this.tvPoints = pointsToTvOhlcStart(points)
|
||||
this.tvPoints = this.pointsToTvOhlcStart(points)
|
||||
this.tvCallbacks = new ShapeTVCallbacks(this);
|
||||
const id = createShape(this.type, this.tvPoints, options, this.tvCallbacks)
|
||||
// todo set id?
|
||||
@@ -267,7 +269,7 @@ export class Shape {
|
||||
if (this.id === null)
|
||||
this.create()
|
||||
else {
|
||||
points = pointsToTvOhlcStart(points)
|
||||
points = this.pointsToTvOhlcStart(points)
|
||||
if (dirtyPoints(this.tvPoints, points)) {
|
||||
/*
|
||||
setPoints(e) {
|
||||
@@ -298,6 +300,13 @@ export class Shape {
|
||||
}
|
||||
}
|
||||
|
||||
// diagonals need to override this to adjust their price as well.
|
||||
pointsToTvOhlcStart(points, periodSeconds=null) {
|
||||
return points === null ? null : points.map((p) => {
|
||||
return {time: nearestOhlcStart(p.time, periodSeconds), price: p.price}
|
||||
})
|
||||
}
|
||||
|
||||
onPoints(points) {} // the control points of an existing shape were changed
|
||||
|
||||
setProps(props) {
|
||||
@@ -602,4 +611,20 @@ export class DLine extends Line {
|
||||
super.onProps(props);
|
||||
this.updateModel({extendLeft: props.extendLeft, extendRight: props.extendRight})
|
||||
}
|
||||
|
||||
|
||||
pointsToTvOhlcStart(points, periodSeconds = null) {
|
||||
if (points === null) return null
|
||||
const [v,w] = points
|
||||
const [b,m] = computeInterceptSlope(v.time, v.price, w.time, w.price)
|
||||
points.map((p) => {
|
||||
let {time, price} = p
|
||||
const aligned = nearestOhlcStart(time, periodSeconds);
|
||||
if (time !== aligned) {
|
||||
time = aligned
|
||||
price = b + m * aligned
|
||||
}
|
||||
return {time, price}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,8 @@ const props = defineProps(['modelValue', 'vault', 'token'])
|
||||
const emit = defineEmits(['update:modelValue'])
|
||||
const balance = computed(() => {
|
||||
console.log('balance', props.vault, props.token, s.vaultBalances)
|
||||
return BigInt(s.vaultBalances[props.vault][props.token.address]) || 0n
|
||||
const b = s.vaultBalances[props.vault][props.token.address];
|
||||
return b === undefined ? 0n : BigInt(b)
|
||||
})
|
||||
const balanceFloat = computed(() => tokenFloat(props.token, balance.value))
|
||||
const floatAmount = ref(0)
|
||||
|
||||
13
src/misc.js
13
src/misc.js
@@ -1,4 +1,4 @@
|
||||
import {ethers, FixedNumber} from "ethers";
|
||||
import {FixedNumber} from "ethers";
|
||||
import {usePrefStore, useStore} from "@/store/store.js";
|
||||
import {token} from "@/blockchain/token.js";
|
||||
import Color from "color";
|
||||
@@ -242,3 +242,14 @@ export function interpolate(a, b, zeroToOne) {
|
||||
return a + d * zeroToOne
|
||||
}
|
||||
|
||||
export function computeInterceptSlope(time0, price0, time1, price1) {
|
||||
if (!time0 || !price0 && price0 !== 0 || !time1 || !price1 && price1 !== 0)
|
||||
throw Error(`invalid line points data ${time0} ${price0} ${time1} ${price1}`)
|
||||
const t0 = time0
|
||||
const t1 = time1
|
||||
if (t0 === t1)
|
||||
throw Error("line points' times must be different")
|
||||
const slope = (price1 - price0) / (t1 - t0)
|
||||
const intercept = price1 - slope * t1
|
||||
return [intercept, slope]
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import {timestamp, uuid} from "@/misc.js";
|
||||
import {computeInterceptSlope, timestamp, uuid} from "@/misc.js";
|
||||
import {MAX_FRACTION, newTranche} from "@/blockchain/orderlib.js";
|
||||
import {useOrderStore, useStore} from "@/store/store.js";
|
||||
import {encodeIEE754} from "@/common.js";
|
||||
@@ -112,19 +112,6 @@ export function applyLimitOld(tranche, price = null, isMinimum = null) {
|
||||
}
|
||||
|
||||
|
||||
function computeInterceptSlope(time0, price0, time1, price1) {
|
||||
if (!time0 || !price0 && price0 !== 0 || !time1 || !price1 && price1 !== 0)
|
||||
throw Error(`invalid line points data ${time0} ${price0} ${time1} ${price1}`)
|
||||
const t0 = time0
|
||||
const t1 = time1
|
||||
if (t0 === t1)
|
||||
throw Error("line points' times must be different")
|
||||
const slope = (price1 - price0) / (t1 - t0)
|
||||
const intercept = price1 - slope * t1
|
||||
return [intercept, slope]
|
||||
}
|
||||
|
||||
|
||||
export function linePointsValue(time0, price0, time1, price1, unixTime = null) {
|
||||
if (unixTime === null)
|
||||
unixTime = timestamp()
|
||||
|
||||
Reference in New Issue
Block a user