Ejemplo n.º 1
0
        private void Stream_OnMessageReceived(MessageReceivedEventArgs message)
        {
            StreamPayload payload = JsonConvert.DeserializeObject <StreamPayload>(message.Data);

            if (payload != null &&
                payload.Data != null &&
                payload.Stream == streamName)
            {
                MarketDepthData data = JsonConvert.DeserializeObject <MarketDepthData>(payload.Data.ToString());

                OnDataReceived?.Invoke(data);
            }
        }
 public override void UpdateMarketData(MarketData marketData)
 {
     if (marketData.Symbol != null && marketData.Symbol != "")
     {
         string symbol      = ConvertFromDEXSymbol(marketData.Symbol);
         string okexHttpUrl = string.Format("https://www.okex.com/api/spot/v3/instruments/{0}/book?size=5", symbol);
         string okexJson    = HttpGet(okexHttpUrl);
         if (okexJson != null && okexJson != "")
         {
             //parse okex market data
             var             obj       = JsonHelper.DeserializeAnonymousType(okexJson, new { asks = new List <double[]>(), bids = new List <double[]>() });
             MarketDepthData depthData = marketData.DepthData;
             depthData.Ask[0] = obj.asks[0][0];
             depthData.Bid[0] = obj.bids[0][0];
             if (depthData.Ask[0] > 0 && depthData.Bid[0] > 0)
             {
                 depthData.Mid = (depthData.Ask[0] + depthData.Bid[0]) / 2;
             }
             depthData.UpdateTime = DateTime.Now;
         }
     }
 }
 public override void UpdateMarketData(MarketData marketData)
 {
     if (marketData.Symbol != null && marketData.Symbol != "")
     {
         string symbol         = ConvertFromDEXSymbol(marketData.Symbol).Replace("_", "").ToUpper();
         string binanceHttpUrl = String.Format("https://api.binance.com/api/v3/depth?symbol={0}&limit=5", symbol);
         string binanceJson    = HttpGet(binanceHttpUrl);
         if (binanceJson != null && binanceJson != "")
         {
             //parse binance market data
             var             obj       = JsonHelper.DeserializeAnonymousType(binanceJson, new { asks = new List <double[]>(), bids = new List <double[]>() });
             MarketDepthData depthData = marketData.DepthData;
             depthData.Ask[0] = obj.asks[0][0];
             depthData.Bid[0] = obj.bids[0][0];
             if (depthData.Ask[0] > 0 && depthData.Bid[0] > 0)
             {
                 depthData.Mid = (depthData.Ask[0] + depthData.Bid[0]) / 2;
             }
             depthData.UpdateTime = DateTime.Now;
         }
     }
 }