public async Task RetrieveKline2(Action <string> handler, List <string> lst) //string symbol, KlineInterval interval) { var payloadlst = lst.Select((code) => "{\"event\": \"subscribe\",\"channel\": \"candles\",\"key\": \"trade:" + ConvertHelper.ObtainEnumValue(KlineInterval.OneMinute) + ":t" + code.Split('.')[0] + "\"}"); int _klineSocketId = await AccessWebSocket.Subscribe2(payloadlst, handler); }
public void CloseAllSocketConnet() { foreach (int socketID in socketIdList) { AccessWebSocket.Unsubscribe(socketID); } socketIdList.Clear(); }
public async Task RetrieveKline(Action <string> handler, string symbol, KlineInterval interval) { //if (_klineSocketId.HasValue) // AbortKline(); string payload = "{\"event\": \"subscribe\",\"channel\": \"candles\",\"key\": \"trade:" + ConvertHelper.ObtainEnumValue(interval) + ":t" + symbol + "\"}"; //Payload payload = new Payload() //{ // Channel = "candles", // Key = $"trade:{ConvertHelper.ObtainEnumValue(interval)}:t{symbol}" //}; int _klineSocketId = await AccessWebSocket.Subscribe(payload, handler); }
public void RetrieveOrderBooks(Action <PairInfo> handler, string symbol, string precision) { var args = GeneratePayload("book"); args.Add("pair", symbol.ToUpper()); args.Add("prec", precision); AccessWebSocket.Subscribe(args, o => { if (o.Count == 4) { handler(new PairInfo() { amount = (decimal)o[o.Count - 1], price = (decimal)o[o.Count - 3], timestamp = DateTime.UtcNow, }); } }); }
T GetSnapShot <T> (string args, string chanId) { string id = AccessWebSocket.Subscribe <T>(args, chanId); int messageNum = 0; Queue <string> buffer = AccessWebSocket._bufferPool[id]; while (messageNum < 2) { while (buffer.Count == 0) { ; } buffer.Dequeue(); messageNum++; } while (buffer.Count == 0) { ; } return(JsonConvert.DeserializeObject <T>(buffer.Dequeue())); }
public void RetrieveTrades(Action <PairInfo> handler, string symbol) { var args = GeneratePayload("trades"); args.Add("pair", symbol.ToUpper()); int socketID = AccessWebSocket.Subscribe(args, o => { if ((o.Count == 6)) { handler(new PairInfo() { amount = (decimal)o[o.Count - 1], price = (decimal)o[o.Count - 2], timestamp = DateTimeOffset.FromUnixTimeSeconds((long)o[o.Count - 3]).DateTime, }); } }); socketIdList.Add(socketID); }