private bool HandleObjectMessage(string msg) { // ******************** // ADD OBJECT HANDLERS BELOW // ******************** return (ErrorResponse.TryHandle(msg, Streams.ErrorSubject) || SubscribeResponse.TryHandle(msg, Streams.SubscribeSubject) || BookResponse.TryHandle(msg, Streams.BookSubject) || TradeResponse.TryHandle(msg, Streams.TradesSubject) || QuoteResponse.TryHandle(msg, Streams.QuoteSubject) || LiquidationResponse.TryHandle(msg, Streams.LiquidationSubject) || PositionResponse.TryHandle(msg, Streams.PositionSubject) || MarginResponse.TryHandle(msg, Streams.MarginSubject) || OrderResponse.TryHandle(msg, Streams.OrderSubject) || WalletResponse.TryHandle(msg, Streams.WalletSubject) || ExecutionResponse.TryHandle(msg, Streams.ExecutionSubject) || FundingResponse.TryHandle(msg, Streams.FundingsSubject) || InstrumentResponse.TryHandle(msg, Streams.InstrumentSubject) || TradeBinResponse.TryHandle(msg, Streams.TradeBinSubject) || InfoResponse.TryHandle(msg, Streams.InfoSubject) || AuthenticationResponse.TryHandle(msg, Streams.AuthenticationSubject)); }
private bool HandleObjectMessage(string msg) { var response = BitmexJsonSerializer.Deserialize <JObject>(msg); // ******************** // ADD OBJECT HANDLERS BELOW // ******************** return (TradeResponse.TryHandle(response, Streams.TradesSubject) || TradeBinResponse.TryHandle(response, Streams.TradeBinSubject) || BookResponse.TryHandle(response, Streams.BookSubject) || QuoteResponse.TryHandle(response, Streams.QuoteSubject) || LiquidationResponse.TryHandle(response, Streams.LiquidationSubject) || PositionResponse.TryHandle(response, Streams.PositionSubject) || MarginResponse.TryHandle(response, Streams.MarginSubject) || OrderResponse.TryHandle(response, Streams.OrderSubject) || WalletResponse.TryHandle(response, Streams.WalletSubject) || InstrumentResponse.TryHandle(response, Streams.InstrumentSubject) || ErrorResponse.TryHandle(response, Streams.ErrorSubject) || SubscribeResponse.TryHandle(response, Streams.SubscribeSubject) || InfoResponse.TryHandle(response, Streams.InfoSubject) || AuthenticationResponse.TryHandle(response, Streams.AuthenticationSubject)); }
private void HandleMarginResponse(MarginResponse response) { if (response.Data.Count() == 0) { return; } try { MarginStatsMutex.WaitOne(); if (response.Action == BitmexAction.Partial || response.Action == BitmexAction.Insert || response.Action == BitmexAction.Update) { MarginStats ma = null; MarginStats mb = null; foreach (Margin m in response.Data) { if (m.Account == Accounts[MTAccount.A]) { _view.AccountAID = m.Account.ToString(); _marginStatsHandler.UpdateBalances(ZoneRecoveryAccount.A, m.WalletBalance, m.MarginBalance, m.AvailableMargin); ma = _marginStatsHandler.GetMarginBalances(ZoneRecoveryAccount.A); _view.TotalFundsA = BitmexConverter.ConvertToBtc("XBt", ma.WalletBalance).ToString(); _view.AvailableFundsA = BitmexConverter.ConvertToBtc("XBt", ma.MarginBalance).ToString(); _view.MarginBalanceA = BitmexConverter.ConvertToBtc("XBt", ma.AvailableMargin).ToString(); } else if (m.Account == Accounts[MTAccount.B]) { _view.AccountBID = m.Account.ToString(); _marginStatsHandler.UpdateBalances(ZoneRecoveryAccount.B, m.WalletBalance, m.MarginBalance, m.AvailableMargin); mb = _marginStatsHandler.GetMarginBalances(ZoneRecoveryAccount.B); _view.TotalFundsB = BitmexConverter.ConvertToBtc("XBt", mb.WalletBalance).ToString(); _view.AvailableFundsB = BitmexConverter.ConvertToBtc("XBt", mb.MarginBalance).ToString(); _view.MarginBalanceB = BitmexConverter.ConvertToBtc("XBt", mb.AvailableMargin).ToString(); } } var a = string.IsNullOrEmpty(_view.TotalFundsA) ? 0.0 : double.Parse(_view.TotalFundsA); var b = string.IsNullOrEmpty(_view.TotalFundsB) ? 0.0 : double.Parse(_view.TotalFundsB); _view.CashImbalance = "L " + Math.Round((a / (a + b) * 100), 2).ToString() + " - S " + Math.Round((b / (b + a) * 100), 2).ToString(); } } catch (Exception exc) { string message = $"[HandleMargin]: {exc.Message}"; Log.Error(message); Console.WriteLine(message); } finally { MarginStatsMutex.ReleaseMutex(); } }
private void HandleWalletSafe(MarginResponse response) { try { HandleWallet(response); } catch (Exception e) { Log.Error(e, $"[Bitmex] Failed to handle wallet info, error: '{e.Message}'"); } }
private void HandleWallet(MarginResponse response) { WalletChangedSubject.OnNext(response.Data.Select(ConvertWallet).ToArray()); }