public async Task Handle(ProfitRoomFoundedIntegrationEvent @event)
        {
            return;

            var exchangeBuyFrom = new Exchange(@event.BuyFrom);
            var exchangeSellTo  = new Exchange(@event.SellTo);

            /*var buyStopLoss = await _stopLossSettingsRepository.GetByExchangeAsync(exchangeBuyFrom);
             * var sellStopLoss = await this._stopLossSettingsRepository.GetByExchangeAsync(exchangeSellTo);*/
            var buyStopLoss = await _stopLossSettingsRepository.GetByIdAsync("0");

            var sellStopLoss = await _stopLossSettingsRepository.GetByIdAsync("1");

            var simpleArbitrage = SimpleArbitrage.CreateFrom(
                @event.EstimatedProfits,
                @event.BuyOrderBaseCurrency,
                @event.SellOrderQuoteCurrency,
                @event.BuyFrom,
                @event.BuyOrderPrice,
                @event.BuyOrderAmounts,
                @event.SellTo,
                @event.SellOrderPrice,
                @event.SellOrderAmounts,
                buyStopLoss ?? new StopLossSetting(exchangeBuyFrom),
                sellStopLoss ?? new StopLossSetting(exchangeSellTo)
                );

            this._simpleArbitrageRepository.Add(simpleArbitrage);

            var success = await this._simpleArbitrageRepository.UnitOfWork.SaveEntitiesAsync();

            Debug.WriteLine("Handle Event: ProfitRoomFoundedIntegrationEvent. \n" +
                            "Result:" + (success == true ? "success" : "false"));
        }
예제 #2
0
        public async Task Handle(ProfitRoomFoundedIntegrationEvent @event)
        {
            return;

            var exchangeBuyFrom = new Exchange(@event.BuyFrom);
            var exchangeSellTo  = new Exchange(@event.SellTo);

            /*var buyStopLoss = await _stopLossSettingsRepository.GetByExchangeAsync(exchangeBuyFrom);
             * var sellStopLoss = await this._stopLossSettingsRepository.GetByExchangeAsync(exchangeSellTo);*/
            var buyStopLoss = await _stopLossSettingsRepository.GetByExchangeAsync(exchangeBuyFrom);

            var sellStopLoss = await _stopLossSettingsRepository.GetByExchangeAsync(exchangeSellTo);

            var simpleArbitrage = SimpleArbitrage.CreateFrom(
                @event.EstimatedProfits,
                @event.BuyOrderBaseCurrency,
                @event.SellOrderQuoteCurrency,
                @event.BuyFrom,
                @event.BuyOrderPrice,
                @event.BuyOrderAmounts,
                @event.SellTo,
                @event.SellOrderPrice,
                @event.SellOrderAmounts,
                buyStopLoss ?? new StopLossSetting(exchangeBuyFrom),
                sellStopLoss ?? new StopLossSetting(exchangeSellTo)
                );

            this._simpleArbitrageRepository.Add(simpleArbitrage);

            var success = await this._simpleArbitrageRepository.UnitOfWork.SaveEntitiesAsync();

            Debug.WriteLine("Handle Event: ProfitRoomFoundedIntegrationEvent. \n" +
                            "To Do: Create A New Simple Arbitrage Into Database. \n" +
                            "Result:" + (success == true ? "success" : "false"));

            /*var exchangeBuyFrom = new Exchange(@event.BuyFrom);
             * var exchangeSellTo = new Exchange(@event.SellTo);
             *
             * var buyStopLoss = await _stopLossSettingsRepository.GetByExchangeAsync(exchangeBuyFrom);
             * var sellStopLoss = await _stopLossSettingsRepository.GetByExchangeAsync(exchangeSellTo);
             *
             * var simpleArbitrage = SimpleArbitrage.CreateFrom(
             *  @event.EstimatedProfits,
             *  @event.BuyOrderBaseCurrency,
             *  @event.SellOrderQuoteCurrency,
             *  @event.BuyFrom,
             *  @event.BuyOrderPrice,
             *  @event.BuyOrderAmounts,
             *  @event.SellTo,
             *  @event.SellOrderPrice,
             *  @event.SellOrderAmounts,
             *  buyStopLoss ?? new StopLossSetting(exchangeBuyFrom),
             *  sellStopLoss ?? new StopLossSetting(exchangeSellTo)
             *  );
             *
             * this._simpleArbitrageRepository.Add(simpleArbitrage);
             *
             * var success = await this._simpleArbitrageRepository.UnitOfWork.SaveEntitiesAsync();*/
            /*var success = true;
             *
             * Debug.WriteLine("Handle Event: ProfitRoomFoundedIntegrationEvent. \n" +
             *  "To Do: Nothing. \n" +
             *  "Result:" + (success == true ? "success" : "false"));*/

            /*var arbitrageSellOrder = simpleArbitrage.SellOrder;
             *
             * var sellOrderToCreate = new Order(
             *  arbitrageSellOrder.ArbitrageOrderId,
             *  arbitrageSellOrder.ExchangeId,
             *  OrderType.SELL_LIMIT.Id,
             *  arbitrageSellOrder.BaseCurrency,
             *  arbitrageSellOrder.QuoteCurrency,
             *  arbitrageSellOrder.Price,
             *  arbitrageSellOrder.Quantity
             *  );
             *
             *
             * this._orderRepository.Add(sellOrderToCreate);
             *
             *
             * success = await this._orderRepository.UnitOfWork.SaveEntitiesAsync();
             * Debug.WriteLine("Handle Event: SimpleArbitrageOpenedDomainEvent. \n" +
             *  "Result:" + (success == true ? "success" : "false"));*/
        }
예제 #3
0
        public async Task Handle(ProfitRoomFoundedWithEnoughBalancesIntegrationEvent @event)
        {
            if (@event.BuyOrderAmounts < 0.0001M || @event.SellOrderAmounts < 0.0001M)
            {
                return;
            }

            lock (_exchangeApiRequestFrequenciesControlService)
            {
                if (!_exchangeApiRequestFrequenciesControlService.IsRequestAllow(@event.BuyFrom) || !_exchangeApiRequestFrequenciesControlService.IsRequestAllow(@event.SellTo))
                {
                    return;
                }
                else
                {
                    this._exchangeApiRequestFrequenciesControlService.UpdateRequestsTime(@event.BuyFrom);
                    this._exchangeApiRequestFrequenciesControlService.UpdateRequestsTime(@event.SellTo);
                }
            }


            var exchangeBuyFrom = new Exchange(@event.BuyFrom);
            var exchangeSellTo  = new Exchange(@event.SellTo);

            /*var buyStopLoss = await _stopLossSettingsRepository.GetByExchangeAsync(exchangeBuyFrom);
             * var sellStopLoss = await this._stopLossSettingsRepository.GetByExchangeAsync(exchangeSellTo);*/
            var buyStopLoss  = _stopLossSettingsRepository.GetByExchangeAsync(exchangeBuyFrom).Result;
            var sellStopLoss = _stopLossSettingsRepository.GetByExchangeAsync(exchangeSellTo).Result;

            var simpleArbitrage = SimpleArbitrage.CreateFrom(
                @event.EstimatedProfits,
                @event.BuyOrderBaseCurrency,
                @event.SellOrderQuoteCurrency,
                @event.BuyFrom,
                @event.BuyOrderPrice,
                @event.BuyOrderAmounts,
                @event.SellTo,
                @event.SellOrderPrice,
                @event.SellOrderAmounts,
                buyStopLoss ?? new StopLossSetting(exchangeBuyFrom),
                sellStopLoss ?? new StopLossSetting(exchangeSellTo)
                );

            this._simpleArbitrageRepository.Add(simpleArbitrage);

            var success = await this._simpleArbitrageRepository.UnitOfWork.SaveEntitiesAsync();



            //Prevent too frequently request.

            /*this._exchangeApiRequestFrequenciesControlService.UpdateRequestsTime(exchangeBuyFrom.ExchangeId);
             * this._exchangeApiRequestFrequenciesControlService.UpdateRequestsTime(exchangeSellTo.ExchangeId);*/

            Debug.WriteLine("Handle Event: ProfitRoomFoundedWithEnoughBalancesIntegrationEvent. \n" +
                            "To Do: Create A New Simple Arbitrage Into Database. \n" +
                            "Result:" + (success == true ? "success" : "false"));



            /*var arbitrageSellOrder = simpleArbitrage.SellOrder;
             *
             * var sellOrderToCreate = new Order(
             *  arbitrageSellOrder.ArbitrageOrderId,
             *  arbitrageSellOrder.ExchangeId,
             *  OrderType.SELL_LIMIT.Id,
             *  arbitrageSellOrder.BaseCurrency,
             *  arbitrageSellOrder.QuoteCurrency,
             *  arbitrageSellOrder.Price,
             *  arbitrageSellOrder.Quantity
             *  );
             *
             *
             * this._orderRepository.Add(sellOrderToCreate);
             *
             *
             * success = await this._orderRepository.UnitOfWork.SaveEntitiesAsync();
             * Debug.WriteLine("Handle Event: SimpleArbitrageOpenedDomainEvent. \n" +
             *  "Result:" + (success == true ? "success" : "false"));*/
        }