ramda#uniqBy JavaScript Examples

The following examples show how to use ramda#uniqBy. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: processOrderBookSnapshot.js    From binance-websocket-examples with MIT License 6 votes vote down vote up
processOrderBookSnapshot = (orderBookData, snapshotOrderbook) => {
  const { lastUpdateId, bids, asks } = snapshotOrderbook;

  // clean the order that is out of date
  const cleanOutOfDateOrder = (order) => order[2] > lastUpdateId;
  orderBookData.bid = filter(cleanOutOfDateOrder, orderBookData.bid);
  orderBookData.ask = filter(cleanOutOfDateOrder, orderBookData.ask);

  // append the updateId into snapshotOrderbook
  const snapshotOrders = appendUpdatedId(lastUpdateId, asks, bids);
  const compareValueFn = cond([
    [equals('ask'), () => (a, b) => (new Big(a[0])).minus(b[0])],
    [equals('bid'), () => (a, b) => (new Big(b[0])).minus(a[0])],
  ]);

  const validateValue = (v) => Big(v[0]);
  orderBookData.bid = uniqBy(validateValue, [...snapshotOrders[1], ...orderBookData.bid])
    .sort(compareValueFn('bid'), orderBookData.bid);

  orderBookData.ask = uniqBy(validateValue, [...snapshotOrders[0], ...orderBookData.ask])
    .sort(compareValueFn('ask'), orderBookData.ask);


  return orderBookData;
}
Example #2
Source File: processOrderBookUpdate.js    From binance-websocket-examples with MIT License 6 votes vote down vote up
processOrderBookUpdate = (data, bid, ask) => {
  const validateValue = (v) => Big(v[0]);
  const compareValueFn = cond([
    [equals('ask'), () => (a, b) => (new Big(a[0])).minus(b[0])],
    [equals('bid'), () => (a, b) => (new Big(b[0])).minus(a[0])],
  ]);
  const purgeEmptyVolume = (v) => Big(v[1]).gt(0);

  data.bid = uniqBy(validateValue, [...bid, ...data.bid])
    .sort(compareValueFn('bid'), data.bid)
    .filter(purgeEmptyVolume, data.bid);

  data.ask = uniqBy(validateValue, [...ask, ...data.ask])
    .sort(compareValueFn('ask'), data.ask)
    .filter(purgeEmptyVolume, data.ask);
  return data;
}