Created
August 22, 2025 14:06
-
-
Save gallegogt/2287c66dc2540b2ff50a7920cdec5bee to your computer and use it in GitHub Desktop.
describe the missing payload on orderbook
This file contains hidden or 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
| { | |
| "name": "notbank-test", | |
| "version": "1.0.0", | |
| "description": "", | |
| "type": "module", | |
| "main": "index.js", | |
| "scripts": { | |
| "test": "echo \"Error: no test specified\" && exit 1" | |
| }, | |
| "keywords": [], | |
| "author": "", | |
| "license": "ISC", | |
| "packageManager": "pnpm@10.15.0", | |
| "dependencies": { | |
| "@types/node": "^24.3.0", | |
| "@types/ws": "^8.18.1", | |
| "bufferutil": "^4.0.9", | |
| "dotenv": "^17.2.1", | |
| "notbank": "1.1.0-alpha", | |
| "utf-8-validate": "^6.0.5", | |
| "ws": "^8.18.3" | |
| } | |
| } |
This file contains hidden or 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
| // dependencies: | |
| // npm install ws bufferutil @types/ws @types/node | |
| import WebSocket from "ws"; | |
| const ws_client = new WebSocket("wss://api.notbank.exchange/wsgateway"); | |
| ws_client.on("error", console.error); | |
| ws_client.on("open", function open() { | |
| const payload = JSON.stringify({ | |
| m: 0, | |
| i: 1000, | |
| n: "SubscribeLevel2", | |
| o: JSON.stringify({ | |
| OMSId: 1, | |
| InstrumentId: 27, // "BTCUSDT" | |
| Depth: 10, | |
| }), | |
| }); | |
| console.log(payload); | |
| ws_client.send(payload); | |
| }); | |
| const market = { | |
| seq: 0, | |
| bids: {}, | |
| asks: {}, | |
| }; | |
| ws_client.on("message", function message(data) { | |
| const message_frame = JSON.parse(data.toString()); | |
| if (message_frame.n === "SubscribeLevel2") { | |
| return; | |
| } | |
| const payload = JSON.parse(message_frame.o); | |
| let instrument_id = payload[0][7]; | |
| console.log(instrument_id); | |
| for (let data of payload as any[]) { | |
| let seq = data[0]; | |
| // let ts = data[2]; | |
| // 0 new | 1 update | 2 deletion | |
| let action = data[3]; | |
| let price_level = data[6]; | |
| let qty_updated = data[8]; | |
| // 0 Buy | 1 Sell | 2 Short (reserved for future use) | 3 Unknown (error condition) | |
| let side = data[9]; | |
| // BIDS == BUY | |
| if (side === 0) { | |
| if (market.bids[price_level] !== undefined) { | |
| if (action === 2) { | |
| delete market.bids[price_level]; | |
| } else { | |
| market.bids[price_level] += qty_updated; | |
| } | |
| } else if (qty_updated > 0.0 && action != 2) { | |
| market.bids[price_level] = qty_updated; | |
| } | |
| continue; | |
| } | |
| // ASK == SELL | |
| if (side == 1) { | |
| if (market.asks[price_level] !== undefined) { | |
| if (action == 2) { | |
| delete market.asks[price_level]; | |
| } else { | |
| market.asks[price_level] += qty_updated; | |
| } | |
| } else if (qty_updated > 0.0 && action != 2) { | |
| market.asks[price_level] = qty_updated; | |
| } | |
| } | |
| } | |
| console.log( | |
| "received: asks-len=%s bids-len=%s", | |
| Object.keys(market.asks).length, | |
| Object.keys(market.bids).length, | |
| ); | |
| }); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
run: