initial chart checkin
This commit is contained in:
@@ -16,11 +16,11 @@ export function applyLimit(tranche, price=null, isMinimum=null) {
|
||||
}
|
||||
|
||||
|
||||
function computeInterceptSlope(date0, price0, date1, price1) {
|
||||
if (!date0 || !price0 && price0 !== 0 || !date1 || !price1 && price1 !== 0)
|
||||
throw Error(`invalid line points data ${date0} ${price0} ${date1} ${price1}`)
|
||||
const t0 = timestamp(date0);
|
||||
const t1 = timestamp(date1);
|
||||
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)
|
||||
@@ -29,21 +29,22 @@ function computeInterceptSlope(date0, price0, date1, price1) {
|
||||
}
|
||||
|
||||
|
||||
export function linePointsValue(date0, price0, date1, price1, unixTime=null) {
|
||||
export function linePointsValue(time0, price0, time1, price1, unixTime=null) {
|
||||
if(unixTime===null)
|
||||
unixTime = timestamp()
|
||||
try {
|
||||
const [intercept, slope] = computeInterceptSlope(date0, price0, date1, price1)
|
||||
const [intercept, slope] = computeInterceptSlope(time0, price0, time1, price1)
|
||||
return intercept + unixTime * slope
|
||||
}
|
||||
catch (e) {
|
||||
console.log('error computing line',e)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export function applyLinePoints(tranche, date0, price0, date1, price1, isMinimum=null) {
|
||||
const [intercept, slope] = computeInterceptSlope(date0, price0, date1, price1);
|
||||
export function applyLinePoints(tranche, time0, price0, time1, price1, isMinimum=null) {
|
||||
const [intercept, slope] = computeInterceptSlope(time0, price0, time1, price1);
|
||||
applyLine(tranche, intercept, slope, isMinimum)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user