private void HandleTradeException(TradeDetail trade, OrderException tradeException) { _console.WriteLineWithTimestamp(tradeException.Message); _console.WriteLineWithTimestamp($"Trade failed - {trade.Id}"); var databaseTradeRecord = BuildTradeRecord(trade, tradeException.ExceptionCode, tradeException.Message); WriteToDatabase(databaseTradeRecord); }
/// <summary> /// 每月定時撥點 /// </summary> //private void AutoAllotPoint(ApplicationUser user, Decimal point) //{ // if (user.Parent == null) return; // // 父帳號點數不足以提供子帳號補點 // if (user.Parent.SmsBalance < point) // { // string subject = "自動補點失敗"; // string body = !user.AllotSetting.MonthlyAllot // ? string.Format("使用者 {0} 點數不足以執行子帳號 {1} 自動補點作業。子帳號目前點數 {2} 已達指定下限點數 {3},需自動補點至指定點數 {4},目前點數{5},但須要{6} 點", // user.Parent.UserName, // user.UserName, // user.SmsBalance, // user.AllotSetting.LimitMinPoint, // user.AllotSetting.LimitMaxPoint, // user.Parent.SmsBalance, // point) // : string.Format("使用者 {0} 點數不足以執行子帳號 {1} 自動補點作業。目前點數{2},但須要{3} 點", // user.Parent.UserName, // user.UserName, // user.Parent.SmsBalance, // point); // string[] destinations = { user.Parent.Email }; // BackgroundJob.Enqueue<GMailService>(x => x.Send(subject, body, destinations)); // // 紀錄LogService // this.logService.Error(body); // } // else // { // AllotPoint(user.Parent, user, point, bSrcCheckCredit: true, bDstCheckCredit: false); // user.AllotSetting.LastAllotTime = now; // this.unitOfWork.Repository<AllotSetting>().Update(user.AllotSetting); // } //} /// <summary> /// 每月定時撥點 /// </summary> //public void CheckMonthlyAllot() //{ // DateTime utcNow = DateTime.UtcNow; // var users = this.unitOfWork.Repository<ApplicationUser>().GetMany(p => // p.AllotSetting != null && // p.AllotSetting.MonthlyAllot == true && // p.AllotSetting.MonthlyAllotDay == utcNow.Day).ToList(); // foreach (var user in users) // { // if (user.AllotSetting.LastAllotTime != null && // user.AllotSetting.LastAllotTime.Value - utcNow < TimeSpan.FromDays(1)) continue; // AutoAllotPoint(user, user.AllotSetting.MonthlyAllotPoint); // } //} public void AllotPoint(ApplicationUser src, ApplicationUser dst, Decimal point, bool bSrcCheckCredit, bool bDstCheckCredit) { DateTime utcNow = DateTime.UtcNow; if (src.SmsBalance - point < 0) { throw new Exception(string.Format("點數不足,使用者{0}目前點數{1}點,無法提撥{2}點給使用者{3}", src.UserName, src.SmsBalance, point, dst.UserName)); } // 撥點 var userRepository = this.unitOfWork.Repository <ApplicationUser>(); dst.SmsBalance += point; src.SmsBalance -= point; userRepository.Update(dst); userRepository.Update(src); // 寫入交易明細 var tradeDetailRepository = this.unitOfWork.Repository <TradeDetail>(); var srcTradeDetail = new TradeDetail { TradeTime = utcNow, TradeType = TradeType.ExportPoints, Point = -1 * point, OwnerId = src.Id, TargetId = dst.Id, Remark = string.Format("點數轉出至{0}", dst.UserName) }; var dstTradeDetail = new TradeDetail { TradeTime = utcNow, TradeType = TradeType.ImportPoints, Point = point, OwnerId = dst.Id, TargetId = src.Id, Remark = string.Format("{0}撥款給您", src.UserName) }; tradeDetailRepository.Insert(srcTradeDetail); tradeDetailRepository.Insert(dstTradeDetail); // 自動補點與點數預警 if (bDstCheckCredit) { CheckCredit(dst); } if (bSrcCheckCredit) { CheckCredit(src); } }
public async Task ProcessMessage(TradeDetail trade) { try { CopyMatchMetadata(trade); var strategyTradeManagers = _managerFactory.GetStrategyTradeManagerPair(trade.StrategyId); var openingOrderSummary = await strategyTradeManagers.OpeningOrderManager.PlaceOpeningOrder(trade, new List <TradeDetail>()); await strategyTradeManagers.ClosingOrderManager.ManageCloseout(openingOrderSummary); var databaseTradeRecord = BuildTradeRecord(trade, "COMPLETE", null); databaseTradeRecord.OpeningId = openingOrderSummary.OpenOrderResponse.BetId; WriteToDatabase(databaseTradeRecord); _console.WriteLineWithTimestamp($"Trade complete - {trade.Id}"); } catch (OrderCancelledException e) { _console.WriteLineWithTimestamp(e.Message); _console.WriteLineWithTimestamp($"Trade cancelled - {trade.Id}"); var databaseTradeRecord = BuildTradeRecord(trade, e.ExceptionCode, null); databaseTradeRecord.OpeningId = e.BetId; WriteToDatabase(databaseTradeRecord); } catch (NoPriceWithRequiredStakeAvailableException e) { HandleTradeException(trade, e); } catch (OrderActionErrorException e) { HandleTradeException(trade, e); } catch (MarketSuspendedException e) { HandleTradeException(trade, e); } catch (InsufficientFundsException e) { HandleTradeException(trade, e); } catch (Exception e) { _console.WriteLineWithTimestamp(e.Message); _console.WriteLineWithTimestamp(e.StackTrace); _console.WriteLineWithTimestamp($"Trade failed - {trade.Id}"); var databaseTradeRecord = BuildTradeRecord(trade, "ERROR", e.Message); WriteToDatabase(databaseTradeRecord); } }
public Tuple <IEnumerable <BPiaoBaoTPos.Domain.Models.TradeDetail>, int> GetTradeDetail(string code, string key, DateTime?startTime, DateTime?endTime, string posNo, int startIndex, int count) { CashbagHelper ch = new CashbagHelper(WebUrlTPos + "QueryTrade", "GET"); Dictionary <string, string> dictionary = new Dictionary <string, string>(); dictionary.Add("code", code); dictionary.Add("key", key); if (startTime.HasValue) { dictionary.Add("StartDate", startTime.Value.ToString("yyyyMMddHHmmss")); } if (endTime.HasValue) { dictionary.Add("EndDate", endTime.Value.ToString("yyyyMMddHHmmss")); } dictionary.Add("POSNumber", posNo); var page = Math.Ceiling((double)startIndex / count) + 1; dictionary.Add("CurrentPage", page.ToString()); dictionary.Add("PageSize", count.ToString()); dictionary.Add("currentTime", DateTime.Now.ToString("yyyyMMddHHmmss")); string data = ch.ParamsURLEncode(dictionary); var result = ch.GetBackJsonData(data); if (result.status == false) { throw new CustomException(500, result.message.ToString()); } List <TradeDetail> list = new List <TradeDetail>(); var rows = JArray.FromObject(result.result.rows); int totalcount = result.result.total; foreach (var item in rows) { TradeDetail tradedetail = new TradeDetail() { BatchNo = item.OutOrderNo, BusinessmanName = item.CompanyFullName, ReceivMoney = item.Amount, PosGain = item.POSAmount, PosNo = item.POSNumber, PosRate = item.Rate, TradeCardNo = item.CardNo, TradeCardType = item.CardType, TradeMoney = item.OrderAmount, TradeTime = item.CreateDate }; list.Add(tradedetail); } Tuple <IEnumerable <TradeDetail>, int> tuple = new Tuple <IEnumerable <TradeDetail>, int>(list, totalcount); return(tuple); }
/// <summary> /// 處理取回派回結果後,根據派送成功或者失敗,決定是否回補點數。 /// </summary> private void HandleSendMessageHistory( SendMessageRule sendMessageRule, SendMessageQueue sendMessageQueue, SendMessageHistory sendMessageHistory) { if (sendMessageHistory.Delivered) { return; } if (sendMessageHistory.Price != 0) { return; // 如果簡訊商就算傳送失敗,但有收取簡訊費用,就不回補點數 } if (sendMessageHistory.ProviderName == SmsProviderType.Every8d.ToString()) { return; // Every8d 會重送,不需要回補點數 } DateTime utcNow = DateTime.UtcNow; // 補點 decimal point = sendMessageHistory.MessageCost; var userRepository = this.unitOfWork.Repository <ApplicationUser>(); var user = sendMessageRule.CreatedUser; user.SmsBalance += point; userRepository.Update(user); // 寫入交易明細 var tradeDetailRepository = this.unitOfWork.Repository <TradeDetail>(); var tradeDetail = new TradeDetail { TradeTime = utcNow, TradeType = TradeType.CoverOfSendMessage, Point = point, OwnerId = user.Id, TargetId = sendMessageHistory.Id.ToString(), Remark = string.Format("{0}(簡訊編號:{1},序列編號:{2}),收訊門號{3}發送失敗({4}),回補點數{5}點", AttributeHelper.GetColumnDescription(sendMessageRule.SendTimeType), sendMessageRule.Id, sendMessageQueue.Id, sendMessageHistory.DestinationAddress, //AttributeHelper.GetColumnDescription(sendMessageHistory.DeliveryStatus), sendMessageHistory.DeliveryStatusString, point) }; tradeDetailRepository.Insert(tradeDetail); // 自動補點與點數預警 // 回補點數,不用自動補點與點數預警 //CheckCredit(user); }
/// <summary> /// 撤銷撥點 /// </summary> public void DismissAllot(TradeDetail tradeDetail) { var tradeDetailRepository = this.unitOfWork.Repository <TradeDetail>(); var userRepository = this.unitOfWork.Repository <ApplicationUser>(); if (tradeDetail.TradeType != TradeType.ExportPoints) { throw new Exception("只有交易類型為【點數匯出】,才能執行撤銷撥點"); } ApplicationUser dst = userRepository.GetById(tradeDetail.TargetId); ApplicationUser src = userRepository.GetById(tradeDetail.OwnerId); if (dst == null) { return; // 使用者已經被刪除 } decimal point = Math.Abs(tradeDetail.Point); /* tradeDetail.Point 為負數 */ decimal actualPoint = Math.Min(dst.SmsBalance, point); if (actualPoint != point) { // 使用者已經使用部分點數 this.logService.Error("使用者 {0} 針對 {1} 撤銷撥點作業只完成部分,預期撤銷點數 {2},實際撤銷點數 {3}", src.UserName, dst.UserName, point, actualPoint); } dst.SmsBalance -= actualPoint; src.SmsBalance += actualPoint; userRepository.Update(dst); userRepository.Update(src); // 刪除兩筆 TradeDetail TradeDetail anotherTradeDetail = tradeDetailRepository.Get(p => p.TradeTime == tradeDetail.TradeTime && p.TradeType == TradeType.ImportPoints && p.OwnerId == tradeDetail.TargetId && p.TargetId == tradeDetail.OwnerId); if (anotherTradeDetail != null) { tradeDetailRepository.Delete(anotherTradeDetail); } if (tradeDetail != null) { tradeDetailRepository.Delete(tradeDetail); } }
/// <summary> /// 回收所有點數 /// </summary> /// <param name="currentUser">目前操作[回收所有點數]動作的使用者</param> /// <param name="user">要被回收點數的使用者</param> public void RecoveryPoint(ApplicationUser currentUser, ApplicationUser user) { DateTime utcNow = DateTime.UtcNow; ApplicationUser src = user; ApplicationUser dst = user.Parent; decimal point = src.SmsBalance; if (dst == null) { return; } // 撥點 var userRepository = this.unitOfWork.Repository <ApplicationUser>(); dst.SmsBalance += point; src.SmsBalance -= point; userRepository.Update(dst); userRepository.Update(src); // 寫入交易明細 var tradeDetailRepository = this.unitOfWork.Repository <TradeDetail>(); var srcTradeDetail = new TradeDetail { TradeTime = utcNow, TradeType = TradeType.ExportRecoveryPoints, Point = -1 * point, OwnerId = src.Id, TargetId = dst.Id, Remark = string.Format("使用者{0}執行回收點數,所有點數回收至{1}", currentUser.UserName, dst.UserName) }; var dstTradeDetail = new TradeDetail { TradeTime = utcNow, TradeType = TradeType.ImportRecoveryPoints, Point = point, OwnerId = dst.Id, TargetId = src.Id, Remark = string.Format("使用者{0}執行回收點數,回收所有{1}點數", currentUser.UserName, src.UserName) }; tradeDetailRepository.Insert(srcTradeDetail); tradeDetailRepository.Insert(dstTradeDetail); // 回收點數,不需要點數預警 //if (bDstCheckCredit) CheckCredit(dst); //if (bSrcCheckCredit) CheckCredit(src); }
private Trade BuildTradeRecord(TradeDetail trade, string status, string message) { return(new Trade() { Id = trade.Id, MarketName = trade.MarketName, Match = trade.Match, Notes = message, RunnerName = trade.RunnerName, Side = trade.Side, Status = status, StrategyId = trade.StrategyId, Tracking = trade.Tracking, TrackingTradeOffset = trade.TrackingTradeOffset }); }
public void UpdateSendMessageRule(SendMessageRule sendMessageRule, decimal beforeTotalMessageCost, decimal afterTotalMessageCost) { DateTime utcNow = DateTime.UtcNow; // 只針對預先扣除的簡訊類型,對於打算要發送的內容進行扣點 if (ShouldWithhold(sendMessageRule.SendTimeType)) { // 扣點或補點 decimal point = afterTotalMessageCost - beforeTotalMessageCost; if (point == 0) { return; } var userRepository = this.unitOfWork.Repository <ApplicationUser>(); var user = sendMessageRule.CreatedUser; user.SmsBalance -= point; userRepository.Update(user); // 寫入交易明細 TradeType tradeType = (point > 0) ? TradeType.DeductionOfSendMessage : TradeType.CoverOfSendMessage; string remark = (point > 0) ? string.Format("{0}(簡訊編號:{1}),更新發送內容,追加差額點數{2}點", AttributeHelper.GetColumnDescription(sendMessageRule.SendTimeType), sendMessageRule.Id, Math.Abs(point)) : string.Format("{0}(簡訊編號:{1}),更新發送內容,回補差額點數{2}點", AttributeHelper.GetColumnDescription(sendMessageRule.SendTimeType), sendMessageRule.Id, Math.Abs(point)); var tradeDetailRepository = this.unitOfWork.Repository <TradeDetail>(); var tradeDetail = new TradeDetail { TradeTime = utcNow, TradeType = tradeType, Point = -1 * point, OwnerId = user.Id, TargetId = sendMessageRule.Id.ToString(), Remark = remark }; tradeDetailRepository.Insert(tradeDetail); // 自動補點與點數預警 CheckCredit(user); } }
public void DeleteUser(ApplicationUser user) { DateTime utcNow = DateTime.UtcNow; ApplicationUser parentUser = user.Parent; if (parentUser == null) { return; } // 回補點數 decimal point = user.SmsBalance; if (point == 0) { return; } var userRepository = this.unitOfWork.Repository <ApplicationUser>(); parentUser.SmsBalance += point; userRepository.Update(parentUser); // 寫入交易明細 var tradeDetailRepository = this.unitOfWork.Repository <TradeDetail>(); var tradeDetail = new TradeDetail { TradeTime = utcNow, TradeType = TradeType.Cover, Point = point, OwnerId = parentUser.Id, TargetId = user.Id, Remark = string.Format("刪除子帳號{0},將該帳號所有點數(共{1}點),回補給您", user.UserName, user.SmsBalance) }; tradeDetailRepository.Insert(tradeDetail); // 自動補點與點數預警(不需要) // CheckCredit(user); }
/// <summary> /// 刪除使用者之前,回補點數 /// </summary> /// <param name="sendMessageRules"></param> public void DeleteSendMessageRules(List <SendMessageRule> sendMessageRules) { var ruleIdsInSendMessageQueue = this.unitOfWork.Repository <SendMessageQueue>().GetAll().Select(p => p.SendMessageRuleId).ToList(); // 過濾需要回補點數的簡訊規則 // - 已經預先扣除 -> ShouldWithhold(p.SendTimeType) // - 尚未發送 -> !ruleIdsInSendMessageQueue.Contains(p.Id) var targets = sendMessageRules.Where(p => ShouldWithhold(p.SendTimeType) && !ruleIdsInSendMessageQueue.Contains(p.Id)).ToList(); if (targets.Count != 0) { // 補點 decimal point = targets.Sum(p => p.TotalMessageCost); var userRepository = this.unitOfWork.Repository <ApplicationUser>(); var user = targets.First().CreatedUser; user.SmsBalance += point; userRepository.Update(user); DateTime utcNow = DateTime.UtcNow; foreach (SendMessageRule sendMessageRule in targets) { // 寫入交易明細 var tradeDetailRepository = this.unitOfWork.Repository <TradeDetail>(); var tradeDetail = new TradeDetail { TradeTime = utcNow, TradeType = TradeType.CoverOfSendMessage, Point = point, OwnerId = user.Id, TargetId = sendMessageRule.Id.ToString(), Remark = string.Format("{0}(簡訊編號:{1}),取消發送(共{2}筆收訊人),回補點數{3}點", AttributeHelper.GetColumnDescription(sendMessageRule.SendTimeType), sendMessageRule.Id, this.unitOfWork.Repository <MessageReceiver>().Count(p => p.SendMessageRuleId == sendMessageRule.Id), point) }; tradeDetailRepository.Insert(tradeDetail); } } }
/// <summary> /// 刪除收訊人回補點數 /// </summary> /// <param name="user">The user.</param> /// <param name="messageReceiver">The message receiver.</param> public void DeleteMessageReceiver(SendMessageRule sendMessageRule, MessageReceiver messageReceiver) { DateTime utcNow = DateTime.UtcNow; if (ShouldWithhold(sendMessageRule.SendTimeType)) { decimal point = messageReceiver.MessageCost; var userRepository = this.unitOfWork.Repository <ApplicationUser>(); var user = sendMessageRule.CreatedUser; user.SmsBalance += point; userRepository.Update(user); var sendMessageRuleRepository = this.unitOfWork.Repository <SendMessageRule>(); sendMessageRule.TotalReceiverCount -= 1; sendMessageRule.TotalMessageCost -= point; sendMessageRule.RemainingSmsBalance += point; sendMessageRuleRepository.Update(sendMessageRule); // 寫入交易明細 var tradeDetailRepository = this.unitOfWork.Repository <TradeDetail>(); var tradeDetail = new TradeDetail { TradeTime = utcNow, TradeType = TradeType.CoverOfSendMessage, Point = point, OwnerId = user.Id, TargetId = messageReceiver.Id.ToString(), Remark = string.Format("{0}(簡訊編號:{1}),刪除收訊人{2},回補{3}點", AttributeHelper.GetColumnDescription(sendMessageRule.SendTimeType), sendMessageRule.Id, messageReceiver.Mobile, messageReceiver.MessageCost) }; tradeDetailRepository.Insert(tradeDetail); // 自動補點與點數預警 CheckCredit(user); } }
/// <summary> /// 針對預先扣點的發送時間類型,進行黑名單的收訊者 - 退還點數 /// </summary> /// <param name="sendMessageRule"></param> public void HandleReceiversInBlackList(SendMessageRule sendMessageRule, IEnumerable <MessageReceiver> receiversInBlackList) { if (!receiversInBlackList.Any()) { return; } DateTime utcNow = DateTime.UtcNow; if (ShouldWithhold(sendMessageRule.SendTimeType)) { // 補點 decimal point = receiversInBlackList.Sum(p => p.MessageCost); var userRepository = this.unitOfWork.Repository <ApplicationUser>(); var user = sendMessageRule.CreatedUser; user.SmsBalance += point; userRepository.Update(user); // 寫入交易明細 var tradeDetailRepository = this.unitOfWork.Repository <TradeDetail>(); var tradeDetail = new TradeDetail { TradeTime = utcNow, TradeType = TradeType.CoverOfSendMessage, Point = point, OwnerId = user.Id, TargetId = sendMessageRule.Id.ToString(), Remark = string.Format("{0}(簡訊編號:{1}),退還黑名單點數(共{2}筆收訊人屬於黑名單),回補{3}點", AttributeHelper.GetColumnDescription(sendMessageRule.SendTimeType), sendMessageRule.Id, receiversInBlackList.Count(), point) }; tradeDetailRepository.Insert(tradeDetail); // 自動補點與點數預警 CheckCredit(user); } }
/// <summary> /// 扣除目前使用者點數,並檢驗點數預警 /// </summary> /// <param name="bCheckCredit">是否執行點數預警</param> public void CreateSendMessageRule(SendMessageRule sendMessageRule, bool bCheckCredit) { DateTime utcNow = DateTime.UtcNow; if (ShouldWithhold(sendMessageRule.SendTimeType)) { // 扣點 decimal point = sendMessageRule.TotalMessageCost; var userRepository = this.unitOfWork.Repository <ApplicationUser>(); var user = sendMessageRule.CreatedUser; user.SmsBalance -= point; userRepository.Update(user); // 寫入交易明細 var tradeDetailRepository = this.unitOfWork.Repository <TradeDetail>(); var tradeDetail = new TradeDetail { TradeTime = utcNow, TradeType = TradeType.DeductionOfSendMessage, Point = -1 * point, OwnerId = user.Id, TargetId = sendMessageRule.Id.ToString(), Remark = string.Format("{0}(簡訊編號:{1}),建立完成(共{2}筆收訊人),扣除{3}點", AttributeHelper.GetColumnDescription(sendMessageRule.SendTimeType), sendMessageRule.Id, this.unitOfWork.Repository <MessageReceiver>().Count(p => p.SendMessageRuleId == sendMessageRule.Id), point) }; tradeDetailRepository.Insert(tradeDetail); // 自動補點與點數預警 if (bCheckCredit) { CheckCredit(user); } } }
private void CopyMatchMetadata(TradeDetail trade) { var fileName = new FileInfo(trade.Match.WhoScoredData.MatchMetadataLocation).Name; _file.Copy(trade.Match.WhoScoredData.MatchMetadataLocation, @"C:/Users/Cobalt4/TradeDecisionData/" + fileName); }
public void Initialize() { mockSleepService = new Mock <ISleepService>(); mockSleepService.Setup(x => x.Sleep(It.IsAny <int>())); mockRunnerService = new Mock <IRunnerService>(); mockRunnerService.Setup(x => x.GetRunnerDetails(It.IsAny <string>(), It.IsAny <long>())).Returns(Task.FromResult(new TradePlacement.Models.Api.Runner() { ExchangePrices = new ExchangePrices() { AvailableToBack = new List <PriceSize>() { new PriceSize() { Price = 5, Size = 10 } }, AvailableToLay = new List <PriceSize>() { new PriceSize() { Price = 8, Size = 15 } } }, Orders = new List <Order>() { new Order() { BetId = "ABC", }, new Order() { BetId = "XYZ", SizeRemaining = 0 } } })); mockOrderPlacer = new Mock <IOrderPlacer>(); mockOrderPlacer.Setup(x => x.PlaceOrder(It.IsAny <OrderWrapper>())).Returns(Task.FromResult(new PlaceExecutionReport() { InstructionReports = new List <PlaceInstructionReport>() { new PlaceInstructionReport() { BetId = "XYZ" } } })); mockClosingStakeCalculator = new Mock <IClosingStakeCalculator>(); mockClosingStakeCalculator.Setup(x => x.GetFullHedgeStake(It.IsAny <List <Order> >(), It.IsAny <double>())).Returns(new KeyValuePair <Side, double>(Side.BACK, 200)); tradeDetail = new TradeDetail() { Tracking = 100 }; orderWrapper = new OrderWrapper("A", 1, Side.BACK, new OrderTick(2, 3), PersistenceType.LAPSE); orderWrapper.AddBetId("ABC"); }
private async Task RunTrade(TradeDetail trade) { var messageProcessor = new TradeMessageProcessor(new ManagerFactory(_console), new TradeStore(), _console, _file); await messageProcessor.ProcessMessage(trade); }
public Task <OpenOrderResult> PlaceOpeningOrder(TradeDetail trade, IEnumerable <TradeDetail> relatedTrades) { throw new NotImplementedException(); }
public async Task ShouldCallGetPriceWithCorrectParameters() { var orderPlacer = new Mock <IOrderPlacer>(); orderPlacer.Setup(x => x.PlaceOrder(It.IsAny <OrderWrapper>())).Returns(Task.FromResult(new PlaceExecutionReport() { InstructionReports = new List <PlaceInstructionReport>() { new PlaceInstructionReport() { BetId = "BetId" } } })); var runnerService = new Mock <IRunnerService>(); var runner = new TradePlacement.Models.Api.Runner() { ExchangePrices = new ExchangePrices() { AvailableToBack = new List <PriceSize>() { new PriceSize() { Price = 10, Size = 20 } } }, Orders = new List <Order>() { new Order() { BetId = "BetId" } } }; runnerService.Setup(x => x.GetRunnerDetails(It.IsAny <string>(), It.IsAny <long>())).Returns(Task.FromResult(runner)); var orderPriceFinder = new Mock <IOrderPriceFinder>(); orderPriceFinder.Setup(x => x.GetPrice(It.IsAny <Side>(), It.IsAny <ExchangePrices>())).Returns(new OrderTick(1, 2)); var sleepService = new Mock <ISleepService>(); sleepService.Setup(x => x.Sleep(It.IsAny <int>())); var manager = new OpeningOrderManager(orderPlacer.Object, runnerService.Object, sleepService.Object, orderPriceFinder.Object); var tradeDetail = new TradeDetail() { Match = new TradePlacement.Models.Match() { BetfairData = new BetfairEvent() { Markets = new List <Market>() { new Market() { MarketId = "A", MarketName = "Name", Runners = new List <TradePlacement.Models.Runner>() { new TradePlacement.Models.Runner() { Id = 1, Name = "Runner" } } } } } }, MarketName = "Name", RunnerName = "Runner" }; await manager.PlaceOpeningOrder(tradeDetail, null); orderPriceFinder.Verify(x => x.GetPrice(tradeDetail.Side, runner.ExchangePrices)); }
public OpenOrderResult(TradeDetail openOrderRequest, OrderWrapper openOrderResponse) { OpenOrderRequest = openOrderRequest; OpenOrderResponse = openOrderResponse; }