massive Shape rework: keep both tvPoints/Props and ourPoints/Props; delegate model updates to subclasses; DCA/VLine working but Ladder/HLine not done.
This commit is contained in:
35
src/misc.js
35
src/misc.js
@@ -172,18 +172,8 @@ export function pairPrice(chainId, baseToken, quoteToken, price) {
|
||||
|
||||
export const sleep = ms => new Promise(r => setTimeout(r, ms))
|
||||
|
||||
export function builderDefaults(props, emit, defaults) {
|
||||
let changed = false
|
||||
for (const k in defaults)
|
||||
if (props.builder[k] === undefined) {
|
||||
props.builder[k] = defaults[k] instanceof Function ? defaults[k]() : defaults[k]
|
||||
changed = true
|
||||
}
|
||||
if (changed)
|
||||
emit('update:builder', props.builder)
|
||||
}
|
||||
|
||||
export function uuid() {
|
||||
// noinspection JSUnresolvedReference
|
||||
return crypto.randomUUID();
|
||||
}
|
||||
|
||||
@@ -204,7 +194,7 @@ const colorRanges = {
|
||||
sell: ['#CC0033', '#CCCC33'],
|
||||
}
|
||||
|
||||
export function lineColor(buy, index) {
|
||||
export function sideColor(buy, index) {
|
||||
const range = buy ? colorRanges.buy : colorRanges.sell
|
||||
const a = new Color(range[0]).rgb()
|
||||
const b = new Color(range[1]).rgb()
|
||||
@@ -229,3 +219,24 @@ export function unique(arr) {
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
export function linspace(a, b, n) {
|
||||
if (n===1) return [(a+b)/2] // single line
|
||||
const spacing = (b - a) / (n - 1)
|
||||
// console.log('spacing', a, b)
|
||||
const result = []
|
||||
for (let i = 0; i < n; i++)
|
||||
result.push(a + i * spacing)
|
||||
return result;
|
||||
}
|
||||
|
||||
export function intervalToSeconds(interval) {
|
||||
if (interval.endsWith('T'))
|
||||
throw Error('Tick intervals not supported')
|
||||
return interval.endsWith('M') ? 30 * 24 * 60 * 60
|
||||
: interval.endsWith('W') ? 7 * 24 * 60 * 60
|
||||
: interval.endsWith('D') ? 24 * 60 * 60
|
||||
: interval.endsWith('S') ? 1
|
||||
: 60 // if no unit char, then it's minutes
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user