Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Orderbook checksum is incorrect with prices smaller than 0.000001 #70

Open
1 of 4 tasks
ighunter opened this issue Jul 6, 2021 · 0 comments
Open
1 of 4 tasks

Comments

@ighunter
Copy link

ighunter commented Jul 6, 2021

Issue type

  • bug
  • missing functionality
  • performance
  • feature request

Brief description

When an orderbook containing prices smaller than 0.000001, i.e. those which are stringified in e-notation, is passed to Orderbook.checksumArr(), it takes pains to ensure that those are stringified without e-notation. The resulting checksum value doesn't match the checksum from the Bitfinex websocket 'book' stream. In my own rather naive implementation I just let Node.js stringify those numbers in e-notation and the checksum does match.

I only tested Orderbook.checksumArr(), not Orderbook.checksum(), but the latter looks it probably behaves in the same way.

Steps to reproduce

const rawArr = [
    [5.6e-7, 1, 60712.4250231],
    [5.5e-7, 8, 1047414.30449527],
    [5.4e-7, 3, 26992.30308495],
    [5.3e-7, 1, 1597.7],
    [5.1e-7, 1, 300],
    [5e-7, 1, 4000],
    [4.9e-7, 1, 1000],
    [4.3e-7, 1, 2000],
    [4.2e-7, 1, 2000],
    [4.1e-7, 1, 2000],
    [4e-7, 3, 4452.125],
    [3.9e-7, 1, 2000],
    [3.8e-7, 1, 2000],
    [3.4e-7, 32, 10290.67],
    [3.3e-7, 2, 734.82],
    [3e-7, 1, 800],
    [2.9e-7, 1, 867],
    [2.8e-7, 1, 300],
    [2.7e-7, 1, 400.6],
    [2.6e-7, 1, 257],
    [2.5e-7, 2, 3600],
    [2.4e-7, 1, 108.5],
    [2.3e-7, 1, 8050],
    [2.1e-7, 1, 308],
    [2e-7, 1, 100],
    [5.7e-7, 6, -1106130.75562937],
    [5.8e-7, 1, -383.98454496],
    [5.9e-7, 1, -2501.6405316],
    [6.1e-7, 2, -416.6],
    [8.2e-7, 1, -2000],
    [8.9e-7, 1, -100],
    [9.2e-7, 1, -22222],
    [9.3e-7, 1, -500],
    [9.9e-7, 1, -500],
    [0.000001, 1, -250.37],
    [0.00000108, 1, -500],
    [0.0000011, 1, -129.576636],
    [0.00000111, 1, -29412.414691],
    [0.00000118, 1, -500],
    [0.00000119, 1, -100],
    [0.0000012, 1, -4000],
    [0.00000141, 1, -332.93],
    [0.00000165, 1, -152.76229702],
    [0.00000171, 1, -265.88],
    [0.00000175, 1, -653],
    [0.00000176, 1, -2.19],
    [0.0000018, 1, -4000],
    [0.000002, 1, -2722.65],
    [0.0000022, 1, -500],
    [0.0000024, 1, -4000]
];

console.log(bfx.OrderBook.checksumArr(rawArr));

Expected: -776929505
Result: 758960098

Subscribing to a market such as tVSYBTC where the prices are very small should give you your own real-world examples if you doubt.

Additional Notes:
  • Node v14.16.0
  • wss://api-pub.bitfinex.com/ws/2
  • Checksums enabled with ws.send(JSON.stringify({event: 'conf', flags: 131072}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant