public void StartProcessingLiveTrades()
        {
            if (_isStarted)
            {
                throw new InvalidOperationException($"{nameof(TradeProcessingService)} was already started processing live trades.");
            }

            _isStarted = true;
            _logger.Debug("Starting processing live trades.");
            _tradeRegistrar.UserTraded += OnUserTraded;
            var symbolPair = SymbolPair.Create(_config.FirstSymbol, _config.SecondSymbol);

            _client.SubscribeToTradesStream(symbolPair.ToString(), trade =>
            {
                var ping = (DateTime.UtcNow - trade.TradeTime).TotalSeconds;
                if (ping > _config.Limiters.MaximalAllowedTradeSyncSeconds / 2 ||
                    ping < _config.Limiters.MaximalAllowedTradeSyncSeconds / -2)
                {
                    _logger.Warning($"Detected trade sync time downgrade with ping {ping} seconds. Try synchronizing machine time or checking the config value with name: {nameof(_config.Limiters.MaximalAllowedTradeSyncSeconds)}");
                }

                if (trade.Quantity <= _config.Limiters.MinimalTradeQuantity)
                {
                    return;
                }

                _logger.Verbose($"Detected trade with Id {trade.TradeId}");
                _tradeRegistrar.RegisterTrade(trade.ToTradeModel(symbolPair));
            });
        }
Exemplo n.º 2
0
        public BinanceAutoTrader(CoreConfiguration config, AttempCalculatorService attempCalculator, IRepository repo, ILogger logger)
        {
            _config           = config ?? throw new ArgumentNullException(nameof(config));
            _attempCalculator = attempCalculator ?? throw new ArgumentNullException(nameof(attempCalculator));
            _repo             = repo ?? throw new ArgumentNullException(nameof(repo));
            _logger           = logger ?? throw new ArgumentNullException(nameof(logger));
            _symbolPair       = SymbolPair.Create(_config.FirstSymbol, _config.SecondSymbol);
            UpdateCurrentWallet();

            ProfitableUserTradedHandler = EventHandlerPredicate;
        }
Exemplo n.º 3
0
 public static Trade ToTradeModel(this BinanceStreamTrade streamTrade, SymbolPair symbolPair)
 {
     return(new Trade()
     {
         SymbolPair = symbolPair,
         TradeId = streamTrade.TradeId,
         TradeTime = streamTrade.TradeTime,
         Price = streamTrade.Price,
         Quantity = streamTrade.Quantity,
         BuyerOrderId = streamTrade.BuyerOrderId,
         SellerOrderId = streamTrade.SellerOrderId,
     });
 }