protected override async Task <ExchangeOrderBook> OnGetOrderBookAsync(string marketSymbol, int maxCount = 100) { JToken token = await MakeJsonRequestAsync <JToken>("public/getorderbook?market=" + marketSymbol + "&type=both&limit_bids=" + maxCount + "&limit_asks=" + maxCount); return(ExchangeAPIExtensions.ParseOrderBookFromJTokenDictionaries(token, "sell", "buy", "Rate", "Quantity", maxCount: maxCount)); }
protected override async Task <ExchangeOrderBook> OnGetOrderBookAsync(string symbol, int maxCount = 100) { JToken obj = await MakeJsonRequestAsync <JToken>("/depth?symbol=" + symbol + "&limit=" + maxCount); return(ExchangeAPIExtensions.ParseOrderBookFromJTokenArrays(obj, sequence: "lastUpdateId", maxCount: maxCount)); }
protected override async Task <ExchangeOrderBook> OnGetOrderBookAsync(string marketSymbol, int maxCount = 100) { JToken token = await MakeBitstampRequestAsync("/order_book/" + marketSymbol); return(ExchangeAPIExtensions.ParseOrderBookFromJTokenArrays(token, maxCount: maxCount)); }
protected internal override async Task <ExchangeOrderBook> OnGetOrderBookAsync(string symbol, int maxCount = 100) { JToken token = await MakeJsonRequestAsync <JToken>("/public/orderbook/" + symbol + "?limit=" + maxCount.ToStringInvariant()); return(ExchangeAPIExtensions.ParseOrderBookFromJTokenDictionaries(token, asks: "ask", bids: "bid", amount: "size", maxCount: maxCount)); }
protected override async Task <IWebSocket> OnGetDeltaOrderBookWebSocketAsync(Action <ExchangeOrderBook> callback, int maxCount = 20, params string[] marketSymbols) { return(await ConnectPublicWebSocketAsync(string.Empty, async (_socket, msg) => { /* * {{ * "id": "id1", * "status": "ok", * "subbed": "market.btcusdt.depth.step0", * "ts": 1526749164133 * }} * * * {{ * "ch": "market.btcusdt.depth.step0", * "ts": 1526749254037, * "tick": { * "bids": [ * [ * 8268.3, * 0.101 * ], * [ * 8268.29, * 0.8248 * ], * * ], * "asks": [ * [ * 8275.07, * 0.1961 * ], * * [ * 8337.1, * 0.5803 * ] * ], * "ts": 1526749254016, * "version": 7664175145 * } * }} */ var str = msg.ToStringFromUTF8Gzip(); JToken token = JToken.Parse(str); if (token["status"] != null) { return; } else if (token["ping"] != null) { await _socket.SendMessageAsync(str.Replace("ping", "pong")); return; } var ch = token["ch"].ToStringInvariant(); var sArray = ch.Split('.'); var marketSymbol = sArray[1].ToStringInvariant(); ExchangeOrderBook book = ExchangeAPIExtensions.ParseOrderBookFromJTokenArrays(token["tick"], maxCount: maxCount); book.MarketSymbol = marketSymbol; callback(book); }, async (_socket) => { if (marketSymbols == null || marketSymbols.Length == 0) { marketSymbols = (await GetMarketSymbolsAsync()).ToArray(); } foreach (string symbol in marketSymbols) { long id = System.Threading.Interlocked.Increment(ref webSocketId); var normalizedSymbol = NormalizeMarketSymbol(symbol); string channel = $"market.{normalizedSymbol}.depth.step0"; await _socket.SendMessageAsync(new { sub = channel, id = "id" + id.ToStringInvariant() }); } })); }
protected override IDisposable OnGetOrderBookDeltasWebSocket(Action <ExchangeOrderBook> callback, int maxCount = 20, params string[] symbols) { if (callback == null || symbols == null || symbols.Length == 0) { return(null); } return(ConnectWebSocket(string.Empty, (msg, _socket) => { /* * {{ * "id": "id1", * "status": "ok", * "subbed": "market.btcusdt.depth.step0", * "ts": 1526749164133 * }} * * * {{ * "ch": "market.btcusdt.depth.step0", * "ts": 1526749254037, * "tick": { * "bids": [ * [ * 8268.3, * 0.101 * ], * [ * 8268.29, * 0.8248 * ], * * ], * "asks": [ * [ * 8275.07, * 0.1961 * ], * * [ * 8337.1, * 0.5803 * ] * ], * "ts": 1526749254016, * "version": 7664175145 * } * }} */ try { var str = msg.UTF8StringFromGzip(); JToken token = JToken.Parse(str); if (token["status"] != null) { return; } else if (token["ping"] != null) { _socket.SendMessage(str.Replace("ping", "pong")); return; } var ch = token["ch"].ToStringInvariant(); var sArray = ch.Split('.'); var symbol = sArray[1].ToStringInvariant(); ExchangeOrderBook book = ExchangeAPIExtensions.ParseOrderBookFromJTokenArrays(token["tick"], maxCount: maxCount); book.Symbol = symbol; callback(book); } catch { // TODO: Handle exception } }, (_socket) => { if (symbols.Length == 0) { symbols = GetSymbols().ToArray(); } // request all symbols, this does not work sadly, only the first is pulled foreach (string symbol in symbols) { long id = System.Threading.Interlocked.Increment(ref webSocketId); var normalizedSymbol = NormalizeSymbol(symbols[0]); // subscribe to order book and trades channel for given symbol string channel = $"market.{normalizedSymbol}.depth.step0"; string msg = $"{{\"sub\":\"{channel}\",\"id\":\"id{id}\"}}"; _socket.SendMessage(msg); } })); }
protected override async Task <ExchangeOrderBook> OnGetOrderBookAsync(string marketSymbol, int maxCount = 100) { var data = await MakeRequestBithumbAsync(marketSymbol, "/public/orderbook/$SYMBOL$"); return(ExchangeAPIExtensions.ParseOrderBookFromJTokenDictionaries(data.Item1, amount: "quantity", sequence: "timestamp", maxCount: maxCount)); }
protected override async Task<ExchangeOrderBook> OnGetOrderBookAsync(string marketSymbol, int maxCount = 100) { JToken obj = await MakeJsonRequestAsync<JToken>("/0/public/Depth?pair=" + marketSymbol + "&count=" + maxCount); return ExchangeAPIExtensions.ParseOrderBookFromJTokenArrays(obj[marketSymbol], maxCount: maxCount); }
protected override async Task <ExchangeOrderBook> OnGetOrderBookAsync(string marketSymbol, int maxCount = 100) { var token = await MakeRequestOkexAsync(marketSymbol, $"/spot/v3/instruments/{marketSymbol}/book", BaseUrlV3); return(ExchangeAPIExtensions.ParseOrderBookFromJTokenArrays(token.Item1, maxCount: maxCount)); }
protected override async Task <ExchangeOrderBook> OnGetOrderBookAsync(string symbol, int maxCount = 100) { JToken token = await MakeJsonRequestAsync <JToken>("/open/orders?symbol=" + symbol + "&limit=" + maxCount); return(ExchangeAPIExtensions.ParseOrderBookFromJTokenArrays(token, asks: "SELL", bids: "BUY", maxCount: maxCount)); }
protected override async Task <ExchangeOrderBook> OnGetOrderBookAsync(string marketSymbol, int maxCount = 100) { JToken obj = await MakeJsonRequestAsync <JToken>("/book/" + marketSymbol + "?limit_bids=" + maxCount + "&limit_asks=" + maxCount); return(ExchangeAPIExtensions.ParseOrderBookFromJTokenDictionaries(obj, maxCount: maxCount)); }
protected override async Task <ExchangeOrderBook> OnGetOrderBookAsync(string symbol, int maxCount = 100) { var token = await MakeRequestOkexAsync(symbol, "/depth.do?symbol=$SYMBOL$"); return(ExchangeAPIExtensions.ParseOrderBookFromJTokenArrays(token.Item1, maxCount: maxCount)); }
protected override IDisposable OnGetOrderBookDeltasWebSocket(Action <ExchangeOrderBook> callback, int maxCount = 20, params string[] symbols) { if (callback == null || symbols == null || symbols.Length == 0) { return(null); } return(ConnectWebSocket(string.Empty, (msg, _socket) => { /* * {[ * { * "binary": 0, * "channel": "addChannel", * "data": { * "result": true, * "channel": "ok_sub_spot_bch_btc_depth_5" * } * } * ]} * * * * {[ * { * "data": { * "asks": [ * [ * "8364.1163", * "0.005" * ], * * ], * "bids": [ * [ * "8335.99", * "0.01837999" * ], * [ * "8335.9899", * "0.06" * ], * ], * "timestamp": 1526734386064 * }, * "binary": 0, * "channel": "ok_sub_spot_btc_usdt_depth_20" * } * ]} * */ try { JToken token = JToken.Parse(msg.UTF8String()); token = token[0]; var channel = token["channel"].ToStringInvariant(); if (channel.EqualsWithOption("addChannel")) { return; } var sArray = channel.Split('_'); var symbol = sArray[3] + "_" + sArray[4]; var data = token["data"]; ExchangeOrderBook book = ExchangeAPIExtensions.ParseOrderBookFromJTokenArrays(data, sequence: "timestamp", maxCount: maxCount); book.Symbol = symbol; callback(book); } catch { // TODO: Handle exception } }, (_socket) => { if (symbols.Length == 0) { symbols = GetSymbols().ToArray(); } foreach (string symbol in symbols) { // subscribe to order book and trades channel for given symbol string normalizedSymbol = NormalizeSymbol(symbol); string channel = $"ok_sub_spot_{normalizedSymbol}_depth_{maxCount}"; string msg = $"{{\'event\':\'addChannel\',\'channel\':\'{channel}\'}}"; _socket.SendMessage(msg); } })); }
protected override async Task <ExchangeOrderBook> OnGetOrderBookAsync(string marketSymbol, int maxCount = 100) { JToken token = await MakeJsonRequestAsync <JToken>("/depth/" + marketSymbol + "?limit=" + maxCount, BaseUrl, null); return(ExchangeAPIExtensions.ParseOrderBookFromJTokenArrays(token[marketSymbol])); }
protected override async Task <ExchangeOrderBook> OnGetOrderBookAsync(string marketSymbol, int maxCount = 100) { JToken token = await MakeJsonRequestAsync <JToken>("/market/orderbook/level2_" + maxCount + "?symbol=" + marketSymbol); return(ExchangeAPIExtensions.ParseOrderBookFromJTokenArrays(token, asks: "asks", bids: "bids", maxCount: maxCount)); }
protected override async Task <ExchangeOrderBook> OnGetOrderBookAsync(string symbol, int maxCount = 100) { JToken token = await MakeJsonRequestAsync <JToken>("/products/" + symbol + "/book?level=" + (maxCount > 50 ? "0" : "2")); return(ExchangeAPIExtensions.ParseOrderBookFromJTokenArrays(token, maxCount: maxCount)); }
protected override async Task <ExchangeOrderBook> OnGetOrderBookAsync(string marketSymbol, int maxCount = 100) { JToken token = await MakeJsonRequestAsync <JToken>("/exchange/order_book?currencyPair=" + marketSymbol.UrlEncode() + "&depth=" + maxCount.ToStringInvariant()); return(ExchangeAPIExtensions.ParseOrderBookFromJTokenArrays(token)); }
/// <inheritdoc /> protected async override Task <ExchangeOrderBook> OnGetOrderBookAsync(string marketSymbol, int maxCount = 100) { JToken response = await MakeJsonRequestAsync <JToken>($"/markets/{marketSymbol}/orderbook?depth={maxCount}"); return(ExchangeAPIExtensions.ParseOrderBookFromJTokenArrays(response, maxCount: maxCount)); }