public static List <ResponseSessionRecord> GenerateResponseSessionRecords(TradeMode mode, int numRecords) { var backtestRecords = new List <ResponseSessionRecord>(); Random random = new Random(); int iRandomResponseIndex = random.Next(1, _responseTypes.Length + 1) - 1; var responseType = _responseTypes[iRandomResponseIndex]; var date = DateTime.Now.AddDays(-20).AddMinutes(random.Next(1, 59)).AddSeconds(random.Next(1, 59)); for (int i = 0; i < 20; i++) { double pnlSwitch = random.NextDouble() > 0.5 ? 1 : -1; DateTime tradeDate = date.AddDays(-random.Next(10, 100)); string parameters = "XMACoefficient=" + random.Next(0, 50) + "|IntervalSize=" + random.Next(25, 75) + "|" + tradeDate.Date.ToString("MM/dd/yyy"); backtestRecords.Add(new ResponseSessionRecord { GUID = responseType + "|" + parameters, Mode = mode, NumTrades = random.Next(5, 100), PNL = Math.Round(pnlSwitch * 100 * random.NextDouble(), 2), WinLossRatio = Math.Round(1 + random.NextDouble(), 2) }); } return(backtestRecords); }
public decimal TradeProduct(Order order, TradeMode tradeMode) { if (order == null) { throw new ArgumentNullException(nameof(order)); } foreach (var orderLine in order.OrderLines) { var matchProduct = Products.First(p => p.ProductName == orderLine.ProductName /*&& orderLine.ProductAttributes.SequenceEqual(p.ProductAttributes)*/); var matchVariant = matchProduct.ProductVariants.First(v => v.ProductVariantId == orderLine.ProductVariantId); if (tradeMode == TradeMode.Buy) { matchProduct.UnitsInStock += orderLine.Quantity; return(matchVariant.BuyPrice * orderLine.Quantity * -1); } else { if (matchProduct.UnitsInStock < orderLine.Quantity) { throw new OutOfStockException(); } matchProduct.UnitsInStock -= orderLine.Quantity; return(matchVariant.SellPrice * orderLine.Quantity); } } return(0); }
private static void SetTradeMode(TradeMode Mode) { var setting = Settings.Where(z => z.SettingName == "TRADE_MODE").First(); if (Mode == TradeMode.Normal) { setting.ValueString = "NORMAL"; } if (Mode == TradeMode.Hit) { setting.ValueString = "HIT"; } if (Mode == TradeMode.Aggressive) { setting.ValueString = "AGGRESSIVE"; } if (Mode == TradeMode.BestBidOffer) { setting.ValueString = "BEST"; } if (Mode == TradeMode.BestAgressive) { setting.ValueString = "BESTAGGRESSIVE"; } }
public static MsgTrade Create(int uniqueId, TradeMode mode) { var packet = new MsgTrade { Size = (ushort)sizeof(MsgTrade), Id = 1056, UniqueId = uniqueId, Mode = mode, }; return(packet); }
private static void SetTradeMode(TradeMode Mode) { var setting = Settings.Where(z => z.SettingName == "TRADE_MODE").First(); if (Mode == TradeMode.Normal) setting.ValueString = "NORMAL"; if (Mode == TradeMode.Hit) setting.ValueString = "HIT"; if (Mode == TradeMode.Aggressive) setting.ValueString = "AGGRESSIVE"; if (Mode == TradeMode.BestBidOffer) setting.ValueString = "BEST"; if (Mode == TradeMode.BestAgressive) setting.ValueString = "BESTAGGRESSIVE"; }
private static PaymentResult ChangeBalance(Wallet wallet, TradeMode tradeMode, decimal totalFee, string tradeCode, string bizSource, long handlerId) { if (string.IsNullOrEmpty(bizSource)) { throw new ArgumentNullException("bizSource"); } if ((tradeMode == TradeMode.Payoff && totalFee < 0) || (tradeMode == TradeMode.Payout && totalFee > 0)) { totalFee = 0 - totalFee; } var addWithdrawBalance = ModuleEnvironment.RealityMoneyBizSourceScopeList.Contains(bizSource); var journal = new WalletJournal(); journal.WalletId = wallet.WalletId; journal.TradeMode = tradeMode; journal.TargetTradeCode = tradeCode; journal.BizSource = bizSource; journal.TotalFee = totalFee; journal.HandlerId = handlerId; using (var scope = new System.Transactions.TransactionScope()) { var changed = wallet.AddBalance(totalFee, addWithdrawBalance); if (changed) { journal.Save(); scope.Complete(); var paidDetail = new Dictionary <string, object>(); paidDetail.Add("TradeCode", tradeCode); paidDetail.Add("WalletId", wallet.WalletId); paidDetail.Add("WalletType", wallet.WalletType); paidDetail.Add("JournalId", journal.JournalId); paidDetail.Add("BizSource", journal.BizSource); paidDetail.Add("TotalFee", journal.TotalFee); return(new PaymentResult() { Success = true, PaidDetail = paidDetail.ToJson() }); } return(new PaymentResult() { Success = false }); } }
/// <summary> /// The basic method that can be used for creating orders and trading on the exchange. /// See https://github.com/wex-exchange/api-doc/blob/master/trade-api.md#Trade /// </summary> /// <param name="pair">Pair</param> /// <param name="type">Order type: buy or sell</param> /// <param name="rate">The rate at which you need to buy/sell</param> /// <param name="amount">The amount you need to buy/sell</param> /// <param name="mode">Order mode</param> public TradeAnswer Trade( WexPair pair, TradeType type, decimal rate, decimal amount, TradeMode mode = TradeMode.Limit) { var args = new Dictionary <string, string>() { { "method", "Trade" }, { "pair", WexPairHelper.ToString(pair) }, { "type", TradeTypeHelper.ToString(type) }, { "rate", DecimalToString(rate) }, { "amount", DecimalToString(amount) }, { "mode", TradeModeHelper.ToString(mode) } }; string query_answer = QueryExec(args); var json_result = ParseAnswer(query_answer); return(TradeAnswer.ReadFromJObject(json_result)); }
internal SymbolInfo(MT4 conn, SDParser p) { // IsSelected = p.popBoolean(); IsFloatingSpread = p.popBoolean(); // SessionDeals = p.popLong(); SessionBuyOrders = p.popLong(); SessionSellOrders = p.popLong(); Volume = p.popLong(); VolumeHigh = p.popLong(); VolumeLow = p.popLong(); // Digits = p.popInt(); Spread = p.popInt(); StopsLevel = p.popInt(); FreezeLevel = p.popInt(); // ContractPriceCalculationMode = ((PriceCalculationMode[])Enum.GetValues(typeof(PriceCalculationMode)))[p.popInt()]; TradeMode = ((TradeMode[])Enum.GetValues(typeof(TradeMode)))[p.popInt()]; SwapMode = ((SwapMode[])Enum.GetValues(typeof(SwapMode)))[p.popInt()]; SwapRollover3Days = ((DayOfWeek[])Enum.GetValues(typeof(DayOfWeek)))[p.popInt()]; TradeExecutionMode = ((TradeExecutionMode[])Enum.GetValues(typeof(TradeExecutionMode)))[p.popInt()]; // Time = conn.ToDate(p.popDouble()); StartTime = conn.ToDate(p.popDouble()); ExpirationTime = conn.ToDate(p.popDouble()); // ExpirationModes = ExpirationModeValues(p.popInt()); FillingModes = FillingModeValues(p.popInt()); OrderModes = OrderModeValues(p.popInt()); // BaseCurrency = p.pop(); ProfitCurrency = p.pop(); MarginCurrency = p.pop(); Description = p.pop(); Path = p.pop(); // Bid = p.popDouble(); BidHigh = p.popDouble(); BidLow = p.popDouble(); Ask = p.popDouble(); AskHigh = p.popDouble(); AskLow = p.popDouble(); Last = p.popDouble(); LastHigh = p.popDouble(); LastLow = p.popDouble(); Point = p.popDouble(); TradeTickValue = p.popDouble(); TradeTickValueProfit = p.popDouble(); TradeTickValueLoss = p.popDouble(); TradeTickSize = p.popDouble(); TradeContractSize = p.popDouble(); MinVolume = p.popDouble(); MaxVolume = p.popDouble(); StepVolume = p.popDouble(); LimitVolume = p.popDouble(); LongSwap = p.popDouble(); ShortSwap = p.popDouble(); InitialMargin = p.popDouble(); MaintenanceMargin = p.popDouble(); LongMargin = p.popDouble(); ShortMargin = p.popDouble(); LimitMargin = p.popDouble(); StopMargin = p.popDouble(); StopLimitMargin = p.popDouble(); SessionVolume = p.popDouble(); SessionTurnover = p.popDouble(); SessionInterest = p.popDouble(); SessionBuyOrdersVolume = p.popDouble(); SessionSellOrdersVolume = p.popDouble(); SessionOpenPrice = p.popDouble(); SessionClosePrice = p.popDouble(); SessionAverageWeightedPrice = p.popDouble(); SessionSettlementPrice = p.popDouble(); SessionMinLimitPrice = p.popDouble(); SessionMaxLimitPrice = p.popDouble(); }
public static string ToString(TradeMode v) { return(Enum.GetName(typeof(TradeMode), v).ToLowerInvariant()); }