public CandleStream(CurrencyPair pair, EMarketPeriod period, CandleDataCache owner) { try { Cache = owner; Pair = pair; Period = period; CandleData = new List <MarketChartData>(); // Create the stream connection and start buffering events m_pending = new List <CandleUpdate>(); Socket = new WebSocket(Api.Shutdown); // Request a snapshot to initialise the candle data // We can only buffer a limited range of candles. Outside that range forward to the rest api lock (CandleData) { // Get the most recent candle data CandleData = Api.GetChartData(Pair, period).Result; CandleData.Sort(x => x.Time); } } catch { Dispose(); throw; } }
// Notes: // - API Info: // https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md public BinanceApi(string key, string secret, CancellationToken shutdown, Logger log) : base(key, secret, shutdown, 6, "https://api.binance.com/", "wss://stream.binance.com:9443/") { try { Log = new Logger("BinanceApi", log); SymbolRules = new SymbolRulesMap(); TickerData = new TickerDataCache(this); MarketData = new MarketDataCache(this); CandleData = new CandleDataCache(this); UserData = new UserDataCache(this); } catch { Dispose(); throw; } }