public void Open(BfTradingMarketConfiguration config = null)
        {
            Config = config ?? new BfTradingMarketConfiguration();

            new BfTradingMarketTickerSource(this)
            .Subscribe(ticker =>
            {
                Ticker = ticker;
                TickerChanged?.Invoke(ticker);
            }).AddTo(_disposables);

            if (Client.IsPrivateApiEnabled)
            {
                // Get positions
                Observable.Timer(TimeSpan.FromSeconds(0), Config.PositionUpdateInterval).Subscribe(count => OnPositionUpdate()).AddTo(_disposables);

                // Get active orders
                Client.GetParentOrders(ProductCode, BfOrderState.Active).GetResult().ForEach(e =>
                {
                    _parentOrders.Add(Client.GetParentOrder(ProductCode, e.ParentOrderId).GetResult());
                });

                Client.GetChildOrders(ProductCode, BfOrderState.Active).GetResult().ForEach(e => _childOrders.Add(e));
            }

            IsOpened = true;
        }
Exemple #2
0
        private void RegisterTradeChannel(Pusher pusher, CurrencyPair pair)
        {
            var tradeChannel = pusher.Subscribe($"live_trades{GetSubscriptionName(pair)}");

            tradeChannel.Subscribed += _chatChannel_Subscribed;

            tradeChannel.Bind("trade", (dynamic data) =>
            {
                var ticker          = _tickerDict[pair];
                ticker.CurrencyPair = pair;
                ticker.DateTime     = TimeHelper.GetTime((long)data.timestamp);
                ticker.Id           = data.id;
                ticker.Volume       = data.amount;
                ticker.Price        = data.price;
                ticker.TradeType    = (data.type == 0);
                TickerChanged?.Invoke(pair, ticker);
            });
        }