-
Notifications
You must be signed in to change notification settings - Fork 316
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BOT] sandeep/refactor: 🔥 remove binary-utils package (#17169)
* refactor: 🔥 remove binary-utils package * refactor: 🔥 moved common function into binary-utils.js
- Loading branch information
1 parent
ba2717f
commit 62af2cf
Showing
5 changed files
with
54 additions
and
163 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
export const historyToTicks = history => | ||
history.times.map((t, idx) => ({ | ||
epoch: +t, | ||
quote: +history.prices[idx], | ||
})); | ||
|
||
export const getLast = arr => arr && (arr.length === 0 ? undefined : arr[arr.length - 1]); | ||
|
||
export const parseTick = tick => ({ | ||
epoch: +tick.epoch, | ||
quote: +tick.quote, | ||
}); | ||
|
||
export const parseOhlc = ohlc => ({ | ||
open: +ohlc.open, | ||
high: +ohlc.high, | ||
low: +ohlc.low, | ||
close: +ohlc.close, | ||
epoch: +(ohlc.open_time || ohlc.epoch), | ||
}); | ||
|
||
export const parseCandles = candles => candles.map(t => parseOhlc(t)); | ||
|
||
export const updateTicks = (ticks, newTick) => | ||
getLast(ticks).epoch >= newTick.epoch ? ticks : [...ticks.slice(1), newTick]; | ||
|
||
export const updateCandles = (candles, ohlc) => { | ||
const lastCandle = getLast(candles); | ||
if ( | ||
(lastCandle.open === ohlc.open && | ||
lastCandle.high === ohlc.high && | ||
lastCandle.low === ohlc.low && | ||
lastCandle.close === ohlc.close && | ||
lastCandle.epoch === ohlc.epoch) || | ||
lastCandle.epoch > ohlc.epoch | ||
) { | ||
return candles; | ||
} | ||
const prevCandles = lastCandle.epoch === ohlc.epoch ? candles.slice(0, -1) : candles.slice(1); | ||
return [...prevCandles, ohlc]; | ||
}; | ||
|
||
export const getType = isCandle => (isCandle ? 'candles' : 'ticks'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters