Exemple #1
0
        public BitmexSocketClient(BitmexSocketClientOptions bitmexSocketClientOptions) : base(nameof(BitmexSocketClient), bitmexSocketClientOptions, bitmexSocketClientOptions.ApiCredentials == null ? null : new BitmexAuthenticationProvider(bitmexSocketClientOptions.ApiCredentials))
        {
            isTestnet = !bitmexSocketClientOptions.IsTestnet;

            if (bitmexSocketClientOptions.SendPingManually)
            {
                SendPeriodic(TimeSpan.FromSeconds(10), connection => "ping");
            }
            if (bitmexSocketClientOptions.LoadInstruments)
            {
                using (var bitmexClient = new BitmexClient(new BitmexClientOptions(bitmexSocketClientOptions.IsTestnet)))
                {
                    var instruments = bitmexClient.GetInstruments(new Objects.Requests.BitmexRequestWithFilter().WithResultsCount(500).AddColumnsToGetInRequest(new string[] { "symbol", "tickSize" }));
                    if (instruments)
                    {
                        for (int i = 0; i < instruments.Data.Count; i++)
                        {
                            InstrumentsIndexesAndTicks.Add(instruments.Data[i].Symbol, new BitmexInstrumentIndexWithTick(i, instruments.Data[i].TickSize));
                        }
                    }
                    else
                    {
                        log.Write(LogVerbosity.Error, "Instrument indicies and price ticks for calculation was not obtained");
                    }
                }
            }
        }
Exemple #2
0
        private void Update(List <BitmexOrderBookEntry> entries)
        {
            try
            {
                if (IsInititalBookSetted)
                {
                    if (entries == null || !entries.Any())
                    {
                        return;
                    }
                    foreach (var e in entries)
                    {
                        e.SetPrice(InstrumentIndex, InstrumentTickSize);
                    }
                    UpdateOrderBook(LastId, NextId(), entries.Where(e => e.Side == OrderBookEntryType.Bid), entries.Where(e => e.Side == OrderBookEntryType.Ask));
                    LastAction = DateTime.UtcNow;
                }
                else
                {
                    log.Write(LogLevel.Error, $"Orderbook was not updated cause not initiated");
                    using (var client = new BitmexClient(new BitmexClientOptions(isTestnet)))
                    {
                        log.Write(LogLevel.Debug, $"Setting orderdbook through api");

                        var ob = client.GetOrderBook(Symbol, 0);
                        if (ob)
                        {
                            SetInitialOrderBook(NextId(), ob.Data.Where(x => x.Side == OrderBookEntryType.Bid), ob.Data.Where(x => x.Side == OrderBookEntryType.Ask));
                            IsInititalBookSetted = true;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                log.Write(LogLevel.Error, $"Orderbook was not updated {ex.ToString()}");
            }
        }