altangent / ccxws

WebSocket client for 38 cryptocurrency exchanges
MIT License
617 stars 186 forks source link

Liquid Trades do not preserve price and amount precision #177

Closed Shutch closed 4 years ago

Shutch commented 4 years ago

Exchange Liquid

Subscription type Trades

Describe the bug When creating the trade object from the Liquid trade websocket response the price and amount are truncated to the default 2 decimal places using toFixed() because a precision is not specified

https://github.com/altangent/ccxws/blob/master/src/exchanges/liquid-client.js#L284

To Reproduce Steps to reproduce the behavior:

  1. Start a trade subscription for any product on liquid
const ccxws = require("ccxws");
const binance = new ccxws.liquid();

const market = {
  id: "celbtc", // liquid IDs from ccxt do not work, websocket stream uses [base][quote] format
  base: "CEL", // standardized base symbol for Bitcoin
  quote: "BTC", // standardized quote symbol for Tether
};

// handle trade events
binance.on("trade", trade => console.log(trade));

// subscribe to trades
binance.subscribeTrades(market);
  1. Compare the websocket response with the ccxws Trade object

Example output: ccxws:

Trade {
  exchange: 'Liquid',
  quote: 'BTC',
  base: 'CEL',
  tradeId: '333106471',
  unix: 1593603406000,
  side: 'buy',
  price: '0',
  amount: '482',
  buyOrderId: undefined,
  sellOrderId: undefined
}

JSON response from liquid:

{
    "channel": "executions_cash_celbtc",
    "data": "{\"created_at\":1593603406,\"id\":333106471,\"price\":0.00005167,\"quantity\":482,\"taker_side\":\"buy\"}",
    "event": "created"
}

Expected behavior Precision for price and amount is preserved from the exchange, which is 8 digits of precision for both.

bmancini55 commented 4 years ago

Thanks for the issue and PR! Will release shortly.

bmancini55 commented 4 years ago

Released in https://github.com/altangent/ccxws/releases/tag/v0.35.2. Thanks!