private static MailMessage GeneratePendingOfferEmail(string rioUrl, TradeDto currentTrade, OfferDto offer, PostingDto posting, SitkaSmtpClientService smtpClient) { var offerAction = currentTrade.CreateAccount.AccountID == offer.CreateAccount.AccountID ? posting.PostingType.PostingTypeID == (int)PostingTypeEnum.OfferToBuy ? "sell" : "buy" : posting.PostingType.PostingTypeID == (int)PostingTypeEnum.OfferToBuy ? "buy" : "sell"; var toAccount = offer.CreateAccount.AccountID == posting.CreateAccount.AccountID ? currentTrade.CreateAccount : posting.CreateAccount; var fromAccount = offer.CreateAccount.AccountID == posting.CreateAccount.AccountID ? posting.CreateAccount : currentTrade.CreateAccount; var properPreposition = offerAction == "sell" ? "to" : "from"; var messageBody = $@" Hello, <br /><br /> An offer to {offerAction} water {properPreposition} Account #{fromAccount.AccountNumber} ({fromAccount.AccountName}) has been presented for your review. <br /><br /> <a href=""{rioUrl}/trades/{currentTrade.TradeNumber}"">Respond to this offer</a> {smtpClient.GetDefaultEmailSignature()}"; var mailMessage = new MailMessage { Subject = "New offer to review", Body = messageBody }; foreach (var user in toAccount.Users) { mailMessage.To.Add(new MailAddress(user.Email, user.FullName)); } return(mailMessage); }
public ActionResult TradeModal(int id) { TradeDto model = new TradeDto(); if (id == 0) { model.EntryDate = DateTime.Now; model.Size = 1; if (this._tradeRepository.Count() > 0) { Trade lastTrade = this._tradeRepository.GetAll().Where(x => x.TradingAccount.Active).OrderByDescending(x => x.EntryDate).First(); model.EntryDate = lastTrade.EntryDate; model.MarketId = lastTrade.MarketId; model.Size = lastTrade.Size; } model.ExitDate = model.EntryDate.AddHours(1); } else { Trade trade = this._tradeRepository.GetAllIncluding(x => x.Market).Single(x => x.Id == id); trade.MapTo(model); } return(PartialView("Modals/_TradeModal", model)); }
private static MailMessage GenerateRescindedOfferEmail(string rioUrl, OfferDto offer, TradeDto currentTrade, PostingDto posting, SitkaSmtpClientService smtpClient) { var offerAction = currentTrade.CreateAccount.AccountID == offer.CreateAccount.AccountID ? posting.PostingType.PostingTypeID == (int)PostingTypeEnum.OfferToBuy ? "sell" : "buy" : posting.PostingType.PostingTypeID == (int)PostingTypeEnum.OfferToBuy ? "buy" : "sell"; var toAccount = offer.CreateAccount.AccountID == posting.CreateAccount.AccountID ? currentTrade.CreateAccount : posting.CreateAccount; var fromAccount = offer.CreateAccount.AccountID == posting.CreateAccount.AccountID ? posting.CreateAccount : currentTrade.CreateAccount; var properPreposition = offerAction == "sell" ? "to" : "from"; var messageBody = $@" Hello, <br /><br /> An offer to {offerAction} water {properPreposition} Account #{fromAccount.AccountNumber} ({fromAccount.AccountName}) was rescinded by the other party. You can see details of your transactions in the Water Accounting Platform Landowner Dashboard. <br /><br /> <a href=""{rioUrl}/landowner-dashboard/{toAccount.AccountNumber}"">View Landowner Dashboard</a> {smtpClient.GetDefaultEmailSignature()}"; var mailMessage = new MailMessage { Subject = $"Trade {currentTrade.TradeNumber} Rescinded", Body = messageBody }; foreach (var user in toAccount.Users) { mailMessage.To.Add(new MailAddress(user.Email, user.FullName)); } return(mailMessage); }
public void SaveOptionTrade(TradeDto dto, DateTime date) { Trade trade = new Trade(); if (dto.IsNew) { trade = dto.MapTo <Trade>(); } else { trade = this._repository.Get(dto.Id); bool exitReasonChanged = dto.ExitReason != trade.ExitReason && dto.ExitReason != TradeExitReasons.None; dto.MapTo(trade); if (exitReasonChanged) { trade.ExitDate = date; } } trade.Reconcile(); if (dto.IsNew) { this._repository.Insert(trade); } }
public void StoreTrade(TradeDto trade) { lock (_trades) { _trades.Enqueue(trade); } }
public IActionResult Trade(TradeDto trades) { var tradeDtos = _mapper.Map <TradeDto>(trades); _magazineService.createTrade(tradeDtos); var getTodaySum = _magazineService.GetTodaySum(); return(Ok(new { thisDay = getTodaySum })); }
public Task Publish(TradeDto trade) { if (_contextHolder.BlotterHubClients == null) { return(Task.FromResult(false)); } Log.InfoFormat("Broadcast new trade to blotters: {0}", trade); return(_contextHolder.BlotterHubClients.Group(BlotterHub.BlotterGroupName).OnNewTrade(new [] { trade })); }
public static Trade FromModel(TradeDto dto) => new Trade() { Exchange = dto.Exchange, Symbol = dto.Symbol, Side = dto.Side, Size = dto.Size, Price = dto.Price, TradeId = dto.TradeId, Timestamp = dto.Timestamp };
public static Trade ToTrade(this TradeDto dto) { return(new Trade() { Id = dto.id, Price = (decimal)dto.price, Quantity = (decimal)dto.quantity, Type = dto.type, Time = ToDateTime(dto.time, true) }); }
public TradeViewModel(TradeDto source) { Id = source.Id; AskCurrencyCode = source.AskCurrencyCode; BidCurrencyCode = source.BidCurrencyCode; SoldAmount = source.SoldAmount; BoughtAmount = source.BoughtAmount; BrokerRate = source.BrokerRate; ClientRate = source.ClientRate; ClientName = source.ClientName; Time = source.Time; }
public void StoreTrade(TradeDto trade) { lock (_trades) { _trades.Enqueue(trade); if (_trades.Count > MaxTrades) { _trades.Dequeue(); } } }
public void OnTrade(TradeDto trade) { _eventLoopScheduler.Schedule(() => { var currencyPair = trade.CurrencyPair; var currencyPairTracker = GetTrackerFor(currencyPair); currencyPairTracker.OnTrade(trade, _priceCache); PublishPositionReport(); }); }
public void OnTrade(TradeDto trade) { _eventLoopScheduler.Schedule(() => { var currencyPair = trade.CurrencyPair; Log.Information("Trade detected {trade}", JsonConvert.SerializeObject(trade)); var currencyPairTracker = GetTrackerFor(currencyPair); currencyPairTracker.OnTrade(trade, _priceCache); PublishPositionReport(); }); }
public ITrade Create(TradeDto trade) { return(new Trade( trade.CurrencyPair, trade.Direction == DirectionDto.Buy ? Direction.BUY : Direction.SELL, trade.Notional, trade.DealtCurrency, trade.SpotRate, trade.Status == TradeStatusDto.Done ? TradeStatus.Done : TradeStatus.Rejected, trade.TradeDate, trade.TradeId, trade.TraderName, trade.ValueDate)); }
public async Task <TradeDto> Execute(TradeRequestDto tradeRequest, string user) { var status = TradeStatusDto.Done; switch (tradeRequest.Symbol) { case "EURJPY": await Task.Delay(TimeSpan.FromSeconds(5)); break; case "GBPUSD": await Task.Delay(TimeSpan.FromSeconds(1.5)); break; default: await Task.Delay(TimeSpan.FromSeconds(.5)); break; } if (tradeRequest.Symbol == "GBPJPY") { status = TradeStatusDto.Rejected; } var trade = new TradeDto { CurrencyPair = tradeRequest.Symbol, Direction = tradeRequest.Direction, Notional = tradeRequest.Notional, SpotRate = tradeRequest.SpotRate, Status = status, TradeDate = DateTime.UtcNow, ValueDate = tradeRequest.ValueDate, TradeId = Interlocked.Increment(ref _tradeId), TraderName = user, DealtCurrency = tradeRequest.DealtCurrency }; _tradeRepository.StoreTrade(trade); _analyticsService.OnTrade(trade); // publish trade asynchronously await _blotterPublisher.Publish(trade); return(trade); }
public Trade createTrade(TradeDto trade) { var tradeEF = _mapper.Map <Trade>(trade); tradeEF.BuyDate = DateTime.Now.ToString(); if (tradeEF.QuantityProduct > 0) { var findProduct = _context.Magazines.Find(tradeEF.MagazineId); findProduct.Id = findProduct.Id; findProduct.Name = findProduct.Name; findProduct.Price = findProduct.Price; findProduct.Quantity = findProduct.Quantity - tradeEF.QuantityProduct; _context.Magazines.Update(findProduct); _context.Trades.Add(tradeEF); _context.SaveChanges(); } return(tradeEF); }
public void OnTrade(TradeDto trade, IDictionary <string, PriceDto> priceCache) { if (trade.Status != TradeStatusDto.Done) { return; } if (trade.Direction == DirectionDto.Buy) { _baseTradedAmount += trade.Notional; _counterTradedAmount += (trade.Notional * trade.SpotRate); } else { _baseTradedAmount -= trade.Notional; _counterTradedAmount -= (trade.Notional * trade.SpotRate); } _tradeCount++; OnPrice(priceCache, true); }
public async Task <TradeDto> CreateAsync(TradeModel tradeModel, decimal totalEnrichmentPercent) { var trade = new TradeDto() { SellingCurrency = tradeModel.SellingCurrency.ToEnum <Currency>(true), BuyingCurrency = tradeModel.BuyingCurrency.ToEnum <Currency>(true), SoldAmount = tradeModel.SoldAmount, ClientName = tradeModel.ClientName }; var latestRates = _rateService.GetLatestRates(); var rateBuyingCurrency = _rateService.GetBrokerRate(latestRates, trade.BuyingCurrency); var rateGBP = _rateService.GetBrokerRate(latestRates, Currency.GBP); trade.BrokerRate = _rateService.GetBrokerRate(latestRates, trade.SellingCurrency) / rateBuyingCurrency; trade.PurchasedAmount = trade.SoldAmount / (trade.BrokerRate / (1M + (totalEnrichmentPercent / 100))); trade.ProfitInBuyingCurrency = trade.PurchasedAmount - (trade.SoldAmount / trade.BrokerRate); trade.ProfitInGBP = trade.ProfitInBuyingCurrency / (rateBuyingCurrency / rateGBP); var result = _tradeService.AddOnDate(trade); await _tradeService.SaveChangesAsync(); return(result); }
public async Task Add(TradeDto value) { await Clients.All.Add(value); }
public ActionResult Trade_Destroy([DataSourceRequest] DataSourceRequest request, TradeDto model) { if (model != null) { this._tradeRepository.Delete(model.Id); } return(Json(new[] { model }.ToDataSourceResult(request, ModelState))); }
public async Task Delete(TradeDto value) { await Clients.All.Delete(value); }
public async Task Update(TradeDto value) { await Clients.All.Update(value); }
public bool Save(TradeDto dto) { bool reconcileTradingAccount = false; Trade trade = new Trade(); if (dto.IsNew) { trade = dto.MapTo <Trade>(); trade.TradingAccountId = this._tradingAccountAppService.GetActive().Id; trade.TradingDayId = this._tradingDayAppService.Get(trade.EntryDate).Id; MarketLogEntry tradeEnterLogEntry = new MarketLogEntry(); tradeEnterLogEntry.MarketId = trade.MarketId; tradeEnterLogEntry.MarketLogEntryType = MarketLogEntryTypes.TradeEnter; if (trade.EntryScreenshotDbId.HasValue) { tradeEnterLogEntry.ScreenshotDbId = trade.EntryScreenshotDbId; } tradeEnterLogEntry.Text = String.Format("{0} {1} @ {2:C}<br/>{3}", trade.TradeType == TradeTypes.Long ? "Buy" : "Sell", trade.Size, trade.EntryPrice, trade.EntryRemarks); tradeEnterLogEntry.TimeStamp = trade.EntryDate; tradeEnterLogEntry.TradingAccountId = trade.TradingAccountId; tradeEnterLogEntry.TradingDayId = trade.TradingDayId; this._marketLogEntryRepository.Insert(tradeEnterLogEntry); if (trade.ExitReason != TradeExitReasons.None) { trade.Market = this._marketRepository.Get(trade.MarketId); trade.Reconcile(); reconcileTradingAccount = true; } } else { trade = this._repository.Get(dto.Id); bool exitReasonChanged = dto.ExitReason != trade.ExitReason && dto.ExitReason != TradeExitReasons.None; dto.MapTo(trade); if (exitReasonChanged) { trade.Market = this._marketRepository.Get(trade.MarketId); trade.Reconcile(); reconcileTradingAccount = true; } } if (reconcileTradingAccount) { MarketLogEntry tradeExitLogEntry = new MarketLogEntry(); tradeExitLogEntry.MarketId = trade.MarketId; tradeExitLogEntry.MarketLogEntryType = MarketLogEntryTypes.TradeExit; if (trade.ExitScreenshotDbId.HasValue) { tradeExitLogEntry.ScreenshotDbId = trade.ExitScreenshotDbId; } tradeExitLogEntry.Text = String.Format("{0}: {1} {2} @ {3:C}, P/L: {4:C}<br/>{5}", trade.ExitReason.GetDisplay(), trade.TradeType == TradeTypes.Long ? "Sell" : "Buy", trade.Size, trade.ExitPrice, trade.ProfitLoss, trade.ExitRemarks); tradeExitLogEntry.TimeStamp = trade.ExitDate.Value; tradeExitLogEntry.TradingAccountId = trade.TradingAccountId; tradeExitLogEntry.TradingDayId = trade.TradingDayId; this._marketLogEntryRepository.Insert(tradeExitLogEntry); } if (dto.IsNew) { this._repository.Insert(trade); } return(reconcileTradingAccount); }
public ActionResult Trade_Update([DataSourceRequest] DataSourceRequest request, TradeDto model) { if (model != null && ModelState.IsValid) { this._tradeAppService.Save(model); } return(Json(new[] { model }.ToDataSourceResult(request, ModelState))); }
private static List <MailMessage> GenerateAcceptedOfferEmail(string rioUrl, OfferDto offer, TradeDto currentTrade, PostingDto posting, WaterTransferDto waterTransfer, SitkaSmtpClientService smtpClient) { AccountDto buyer; AccountDto seller; if (currentTrade.CreateAccount.AccountID == posting.CreateAccount.AccountID) { if (posting.PostingType.PostingTypeID == (int)PostingTypeEnum.OfferToBuy) { buyer = posting.CreateAccount; seller = currentTrade.CreateAccount; } else { buyer = currentTrade.CreateAccount; seller = posting.CreateAccount; } } else { if (posting.PostingType.PostingTypeID == (int)PostingTypeEnum.OfferToBuy) { buyer = posting.CreateAccount; seller = currentTrade.CreateAccount; } else { buyer = currentTrade.CreateAccount; seller = posting.CreateAccount; } } var mailMessages = new List <MailMessage>(); var messageBody = $@"Your offer to trade water has been accepted. <ul> <li><strong>Buyer:</strong> {buyer.AccountName} ({string.Join(", ", buyer.Users.Select(x=>x.Email))})</li> <li><strong>Seller:</strong> {seller.AccountName} ({string.Join(", ", seller.Users.Select(x => x.Email))})</li> <li><strong>Quantity:</strong> {offer.Quantity} acre-feet</li> <li><strong>Unit Price:</strong> {offer.Price:$#,##0.00} per acre-foot</li> <li><strong>Total Price:</strong> {(offer.Price * offer.Quantity):$#,##0.00}</li> </ul> To finalize this transaction, the buyer and seller must complete payment and any other terms of the transaction. Once payment is complete, the trade must be confirmed by both parties within the Water Accounting Platform before the district will recognize the transfer. <br /><br /> <a href=""{rioUrl}/register-transfer/{waterTransfer.WaterTransferID}"">Confirm Transfer</a> {smtpClient.GetDefaultEmailSignature()}"; var mailTos = (new List <AccountDto> { buyer, seller }).SelectMany(x => x.Users); foreach (var mailTo in mailTos) { var mailMessage = new MailMessage { Subject = $"Trade {currentTrade.TradeNumber} Accepted", Body = $"Hello {mailTo.FullName},<br /><br />{messageBody}" }; mailMessage.To.Add(new MailAddress(mailTo.Email, mailTo.FullName)); mailMessages.Add(mailMessage); } return(mailMessages); }
public Task Delete(TradeDto level) { _context.Clients.All.SendAsync("Delete", level); return(Task.CompletedTask); }
public void OnTrade(TradeDto trade) { Log.Information("Received done trade"); _analyticsEngine.OnTrade(trade); }
public Task Update(TradeDto level) { _logger.LogInformation($"Update received from TradeService {level}"); _context.Clients.All.SendAsync("Update", level); return(Task.CompletedTask); }
public static WaterTransferDto CreateNew(RioDbContext dbContext, OfferDto offerDto, TradeDto tradeDto, PostingDto postingDto) { var waterTransfer = new WaterTransfer { OfferID = offerDto.OfferID, AcreFeetTransferred = offerDto.Quantity, TransferDate = offerDto.OfferDate }; var waterTransferRegistrationBuyer = new WaterTransferRegistration() { WaterTransfer = waterTransfer, WaterTransferTypeID = (int)WaterTransferTypeEnum.Buying, StatusDate = DateTime.Now, WaterTransferRegistrationStatusID = (int)WaterTransferRegistrationStatusEnum.Pending }; var waterTransferRegistrationSeller = new WaterTransferRegistration() { WaterTransfer = waterTransfer, WaterTransferTypeID = (int)WaterTransferTypeEnum.Selling, StatusDate = DateTime.Now, WaterTransferRegistrationStatusID = (int)WaterTransferRegistrationStatusEnum.Pending }; if (postingDto.PostingType.PostingTypeID == (int)PostingTypeEnum.OfferToSell) { waterTransferRegistrationSeller.AccountID = postingDto.CreateAccount.AccountID; waterTransferRegistrationBuyer.AccountID = tradeDto.CreateAccount.AccountID; } else { waterTransferRegistrationSeller.AccountID = tradeDto.CreateAccount.AccountID; waterTransferRegistrationBuyer.AccountID = postingDto.CreateAccount.AccountID; } dbContext.WaterTransfer.Add(waterTransfer); dbContext.WaterTransferRegistration.Add(waterTransferRegistrationBuyer); dbContext.WaterTransferRegistration.Add(waterTransferRegistrationSeller); dbContext.SaveChanges(); dbContext.Entry(waterTransfer).Reload(); return(GetByWaterTransferID(dbContext, waterTransfer.WaterTransferID)); }