Esempio n. 1
0
            public MarketStream(CurrencyPair pair, MarketDataCache owner)
            {
                try
                {
                    Cache       = owner;
                    Pair        = pair;
                    MarketDepth = new MarketDepth(pair);

                    // Create the stream connection and start buffering events
                    m_pending = new List <MarketUpdate>();
                    Socket    = new WebSocket(Api.Shutdown);

                    // Request a full snapshot to initialise the order book
                    var ob = Api.GetOrderBook(Pair, 1000, Api.Shutdown).Result;
                    lock (MarketDepth)
                    {
                        MarketDepth.B2QOffers.Assign(ob.B2QOffers);
                        MarketDepth.Q2BOffers.Assign(ob.Q2BOffers);
                        MarketDepth.SequenceNo = ob.SequenceNo;
                    }
                }
                catch
                {
                    Dispose();
                    throw;
                }
            }
Esempio n. 2
0
        // 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;
            }
        }