Skip to content

Commit

Permalink
[BOT] sandeep/refactor: 🔥 remove binary-utils package (#17169)
Browse files Browse the repository at this point in the history
* refactor: 🔥 remove binary-utils package

* refactor: 🔥 moved common function into binary-utils.js
  • Loading branch information
sandeep-deriv authored Oct 15, 2024
1 parent ba2717f commit 62af2cf
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 163 deletions.
124 changes: 0 additions & 124 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions packages/bot-skeleton/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,12 @@
"typescript": "^4.6.3"
},
"dependencies": {
"blockly": "^10.4.3",
"@deriv/deriv-api": "^1.0.15",
"@deriv/indicators": "^1.0.0",
"@deriv/js-interpreter": "^3.0.0",
"@deriv/shared": "^1.0.0",
"@deriv/translations": "^1.0.0",
"binary-utils": "^4.23.0",
"blockly": "^10.4.3",
"file-saver": "^2.0.2",
"immutable": "^3.8.2",
"localforage": "^1.9.0",
Expand Down
43 changes: 43 additions & 0 deletions packages/bot-skeleton/src/services/api/binary-utils.js
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');
45 changes: 9 additions & 36 deletions packages/bot-skeleton/src/services/api/ticks_service.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,16 @@
import { Map } from 'immutable';
import { historyToTicks, getLast } from 'binary-utils';
import { doUntilDone, getUUID } from '../tradeEngine/utils/helpers';
import { observer as globalObserver } from '../../utils/observer';
import { api_base } from './api-base';

const parseTick = tick => ({
epoch: +tick.epoch,
quote: +tick.quote,
});

const parseOhlc = ohlc => ({
open: +ohlc.open,
high: +ohlc.high,
low: +ohlc.low,
close: +ohlc.close,
epoch: +(ohlc.open_time || ohlc.epoch),
});

const parseCandles = candles => candles.map(t => parseOhlc(t));

const updateTicks = (ticks, newTick) => (getLast(ticks).epoch >= newTick.epoch ? ticks : [...ticks.slice(1), newTick]);

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];
};

const getType = isCandle => (isCandle ? 'candles' : 'ticks');
import {
historyToTicks,
parseTick,
parseOhlc,
parseCandles,
updateTicks,
updateCandles,
getType,
} from './binary-utils';

export default class TicksService {
constructor() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { getLast } from 'binary-utils';
import { localize } from '@deriv/translations';
import * as constants from './state/constants';
import { getDirection, getLastDigit } from '../utils/helpers';
import { expectPositiveInteger } from '../utils/sanitize';
import { observer as globalObserver } from '../../../utils/observer';
import { api_base } from '../../api/api-base';
import debounce from 'lodash.debounce';
import { getLast } from '../../api/binary-utils';

let tickListenerKey;

Expand Down

0 comments on commit 62af2cf

Please sign in to comment.