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")); }
public async Task <IActionResult> PutSimpleArbitrage([FromRoute] int id, [FromBody] SimpleArbitrage simpleArbitrage) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != simpleArbitrage.Id) { return(BadRequest()); } _context.Entry(simpleArbitrage).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SimpleArbitrageExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PostSimpleArbitrage([FromBody] SimpleArbitrage simpleArbitrage) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.SimpleArbitrages.Add(simpleArbitrage); await _context.SaveChangesAsync(); return(CreatedAtAction("GetSimpleArbitrage", new { id = simpleArbitrage.Id }, simpleArbitrage)); }
public SimpleArbitrage Add(SimpleArbitrage simpleArbitrage) { if (simpleArbitrage.IsTransient()) { return(_context.SimpleArbitrages .Add(simpleArbitrage) .Entity); } else { return(simpleArbitrage); } }
public static SimpleArbitrageResponse ToSimpleArbitrageResponse(this SimpleArbitrage simpleArbitrage) { return(new SimpleArbitrageResponse { ArbitrageId = simpleArbitrage.ArbitrageId, BuyOrder = simpleArbitrage.BuyOrder, SellOrder = simpleArbitrage.SellOrder, EstimateProfits = simpleArbitrage.EstimateProfits, ActualProfits = simpleArbitrage.ActualProfits, ArbitrageData = simpleArbitrage.ArbitrageData, Status = simpleArbitrage.Status.Name, IsSuccess = simpleArbitrage.IsSuccess, FailureReason = simpleArbitrage.FailureReason }); }
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"));*/ }
public SimpleArbitrageOpenedDomainEvent(SimpleArbitrage simpleArbitrage) { SimpleArbitrage = simpleArbitrage; }
public SimpleArbitrage Update(SimpleArbitrage simpleArbitrage) { return(_context.SimpleArbitrages .Update(simpleArbitrage) .Entity); }
public async Task Handle(ExchangeMarketUpdatedDomainEvent exchangeMarketUpdatedDomainEvent, CancellationToken cancellationToken) { /*_logger.CreateLogger(nameof(ExchangeMarketUpdatedDomainEvent)) * .LogTrace($"Order with Id: {orderShippedDomainEvent.Order.Id} has been successfully updated with " + * $"a status order id: {OrderStatus.Shipped.Id}");*/ try { var marketId = exchangeMarketUpdatedDomainEvent.Market.MarketId; IEnumerable <SimpleArbitrage> simpleArbitrages; var isFound = await ProfitCalculator.FindProfits(out simpleArbitrages, marketId.BaseCurrency, marketId.QuoteCurrency, exchangeMarketUpdatedDomainEvent.Market, exchangeMarketUpdatedDomainEvent.ExchangeId); if (isFound) { SimpleArbitrage profitableWithEnoughBalances = null; foreach (var simpleArbitrage in simpleArbitrages) { this._eventBus.Publish(new ProfitRoomFoundedIntegrationEvent( simpleArbitrage.BuyOrder.ExchangeId, simpleArbitrage.BuyOrder.BaseCurrency, simpleArbitrage.BuyOrder.QuoteCurrency, simpleArbitrage.BuyOrder.Price, simpleArbitrage.BuyOrder.Quantity, simpleArbitrage.SellOrder.ExchangeId, simpleArbitrage.SellOrder.BaseCurrency, simpleArbitrage.SellOrder.QuoteCurrency, simpleArbitrage.SellOrder.Price, simpleArbitrage.SellOrder.Quantity, simpleArbitrage.EstimatedProfits )); if (profitableWithEnoughBalances == null) { var consideration = simpleArbitrage.TakeBalanceIntoConsideration( this._exchangeRepository.GetAsync(simpleArbitrage.BuyOrder.ExchangeId).Result.GetAssetBalance(simpleArbitrage.BuyOrder.QuoteCurrency), this._exchangeRepository.GetAsync(simpleArbitrage.SellOrder.ExchangeId).Result.GetAssetBalance(simpleArbitrage.SellOrder.BaseCurrency) ); if (consideration.EstimatedProfits > 0) { profitableWithEnoughBalances = consideration; } } } if (profitableWithEnoughBalances != null) { this._eventBus.Publish(new ProfitRoomFoundedWithEnoughBalancesIntegrationEvent( profitableWithEnoughBalances.BuyOrder.ExchangeId, profitableWithEnoughBalances.BuyOrder.BaseCurrency, profitableWithEnoughBalances.BuyOrder.QuoteCurrency, profitableWithEnoughBalances.BuyOrder.Price, profitableWithEnoughBalances.BuyOrder.Quantity, profitableWithEnoughBalances.SellOrder.ExchangeId, profitableWithEnoughBalances.SellOrder.BaseCurrency, profitableWithEnoughBalances.SellOrder.QuoteCurrency, profitableWithEnoughBalances.SellOrder.Price, profitableWithEnoughBalances.SellOrder.Quantity, profitableWithEnoughBalances.EstimatedProfits )); } } else { /*string log = "Last calculation result:" + "\n" + "Time:" + DateTime.UtcNow.ToShortTimeString() + "\n" + "Market:" + simpleArbitrage.BuyOrder.BaseCurrency + simpleArbitrage.BuyOrder.QuoteCurrency + "\n" + "Buy From:" + "ExchangeId => " + simpleArbitrage.BuyOrder.ExchangeId + "\n" + "Buy Price:" + simpleArbitrage.BuyOrder.Price + "\n" + "Buy Amount:" + simpleArbitrage.BuyOrder.Quantity + "\n" + "Sell To:" + "ExchangeId => " + simpleArbitrage.SellOrder.ExchangeId + "\n" + "Sell Price:" + simpleArbitrage.SellOrder.Price + "\n" + "Sell Amount:" + simpleArbitrage.SellOrder.Quantity + "\n" + "Estimated Profits" + simpleArbitrage.EstimatedProfits + "\n"; + this._testLogger.PrependLog(log);*/ } } catch (Exception ex) { Debug.Write("Handle Event: ExchangeMarketUpdatedDomainEvent." + "Result: Failure." + "Error Message: " + ex.Message ); throw ex; } }
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"));*/ }