static void Main(string[] args) { var mainStrategy = new MainStrategy(); mainStrategy.InitTable(); mainStrategy.InitGame(); mainStrategy.StartGame(); Console.ReadKey(); }
public void test_mainstrat() { var ms = new MainStrategy(new MainStrategyArguments { UnderwriterID = 1, CustomerID = 14036, NewCreditLine = NewCreditLineOption.UpdateEverythingAndApplyAutoRules, AvoidAutoDecision = 0, FinishWizardArgs = null, CashRequestID = null, CashRequestOriginator = CashRequestOriginator.Other }); ms.Execute(); }
} // Name /// <exception cref="StrategyAlert">Condition. </exception> public override void Execute() { //this.Result.Value = "STARTED"; // check customer exists ICustomerRepository custRep = ObjectFactory.GetInstance <ICustomerRepository>(); Customer customer = custRep.Get(this.CustomerID); if (customer == null) { // this.Result.Value = "CUSTOMER_NOT_FOUND"; return; } // if if (customer.IsAlibaba == false) { // this.Result.Value = "ALIMEMBER_NOT_FOUND"; return; } // if try { MainStrategy strategy = new MainStrategy(new MainStrategyArguments { UnderwriterID = 1, // TODO: apply real underwriter ID CustomerID = customer.Id, NewCreditLine = NewCreditLineOption.UpdateEverythingAndApplyAutoRules, AvoidAutoDecision = 0, FinishWizardArgs = null, CashRequestID = null, CashRequestOriginator = CashRequestOriginator.RequalifyCustomerStrategy }); strategy.Execute(); } catch (Exception ex1) { throw new StrategyAlert( this, string.Format( "Failed to run main strategy for 'RequalifyCustomer' customer: {0}, {1}", customer.Id, ex1.Message ), ex1 ); } // try } // Execute
public static List <MainStrategy> CoinCompare(Dictionary <string, TransforfField> arg1, Dictionary <string, TransforfField> arg2, string mainStockEx, string secoondStockEx) { Dictionary <string, TransforfField> main = arg1.Where(d => arg2.ContainsKey(d.Key)).ToDictionary(x => x.Key, y => new TransforfField() { asks = y.Value.asks.Take(20).ToDictionary(c => c.Key, v => v.Value), bids = y.Value.bids.Take(30).ToDictionary(c => c.Key, v => v.Value) }); Dictionary <string, TransforfField> second = arg2.Where(d => arg1.ContainsKey(d.Key)).ToDictionary(x => x.Key, y => new TransforfField() { asks = y.Value.asks.Take(20).ToDictionary(c => c.Key, v => v.Value), bids = y.Value.bids.Take(30).ToDictionary(c => c.Key, v => v.Value) }); #region сравнение валют и запись из в стратегию List <MainStrategy> MainSt = new List <MainStrategy>(); foreach (KeyValuePair <string, TransforfField> i in main) { TransforfField temp; if (second.ContainsKey(i.Key)) { temp = second[i.Key]; } else { continue; } if (temp.asks.Count == 0) { continue; } if (temp.bids.Count == 0) { continue; } if (i.Value.asks.Count == 0) { continue; } if (i.Value.bids.Count == 0) { continue; } if (IsProfit(temp.bids.First().Key, i.Value.asks.First().Key)) { MainStrategy TempSt = new MainStrategy(); TempSt.MarketName = i.Key; TempSt.BuyStockEX = mainStockEx; TempSt.SellStockEX = secoondStockEx; if (temp.asks.Count == 0) { continue; } if (temp.bids.Count == 0) { continue; } if (i.Value.asks.Count == 0) { continue; } if (i.Value.bids.Count == 0) { continue; } //buy on [livecoin] main sell on [poloniex] several while (IsProfit(temp.bids.First().Key, i.Value.asks.First().Key)) { if (i.Value.asks.First().Value > temp.bids.First().Value) { //записать в стратегию значение цены и количество в цикле пока профит if (TempSt.StrategyBuy.Data.ContainsKey(i.Value.asks.First().Key)) { TempSt.StrategyBuy.Data[i.Value.asks.First().Key] += temp.bids.First().Value; } else { TempSt.StrategyBuy.Data.Add(i.Value.asks.First().Key, temp.bids.First().Value); } if (TempSt.StrategySell.Data.ContainsKey(temp.bids.First().Key)) { TempSt.StrategySell.Data[temp.bids.First().Key] += temp.bids.First().Value; } else { TempSt.StrategySell.Data.Add(temp.bids.First().Key, temp.bids.First().Value); } //отнять в списках большее значение i.Value.asks[i.Value.asks.First().Key] -= temp.bids.First().Value; //удалить из списков меньшее значение temp.bids.Remove(temp.bids.First().Value); } else if (i.Value.asks.First().Value < temp.bids.First().Value) { //записать в стратегию значение цены и количество if (TempSt.StrategyBuy.Data.ContainsKey(i.Value.asks.First().Key)) { TempSt.StrategyBuy.Data[i.Value.asks.First().Key] += i.Value.asks.First().Value; } else { TempSt.StrategyBuy.Data.Add(i.Value.asks.First().Key, i.Value.asks.First().Value); } if (TempSt.StrategySell.Data.ContainsKey(temp.bids.First().Key)) { TempSt.StrategySell.Data[temp.bids.First().Key] += i.Value.asks.First().Value; } else { TempSt.StrategySell.Data.Add(temp.bids.First().Key, i.Value.asks.First().Value); } //отнять в списках большее значение temp.bids[temp.bids.First().Key] -= i.Value.asks.First().Value; //удалить из списков меньшее значение i.Value.asks.Remove(i.Value.asks.First().Key); } if (temp.asks.Count == 0) { break; } if (temp.bids.Count == 0) { break; } if (i.Value.asks.Count == 0) { break; } if (i.Value.bids.Count == 0) { break; } //равные значения будут нужны для возврата валюты //else if (temp.bids.First()[1] == i.Value.asks.First()[1]) //{ // //записать в стратегию значение цены и количество // MainSt.StrategyBuy.Data[temp.bids.First()[0]] += i.Value.asks.First()[1]; // MainSt.StrategySell.Data[i.Value.asks.First()[0]] += i.Value.asks.First()[1]; // //удалить из списков меньшее значение // temp.bids.First().Clear(); // i.Value.asks.First().Clear(); //} } MainSt.Add(TempSt); } else if (IsProfit(i.Value.bids.First().Key, temp.asks.First().Key)) { //buy on [poloniex] main sell on [livecoin] several MainStrategy TempSt = new MainStrategy(); TempSt.MarketName = i.Key; TempSt.BuyStockEX = secoondStockEx; TempSt.SellStockEX = mainStockEx; //buy on [livecoin] main sell on [poloniex] several while (IsProfit(i.Value.bids.First().Key, temp.asks.First().Key)) { if (temp.asks.First().Value > i.Value.bids.First().Value) { //записать в стратегию значение цены и количество в цикле пока профит if (TempSt.StrategyBuy.Data.ContainsKey(temp.asks.First().Key)) { TempSt.StrategyBuy.Data[temp.asks.First().Key] += i.Value.bids.First().Value; } else { TempSt.StrategyBuy.Data.Add(temp.asks.First().Key, i.Value.bids.First().Value); } if (TempSt.StrategySell.Data.ContainsKey(i.Value.bids.First().Key)) { TempSt.StrategySell.Data[i.Value.bids.First().Key] += i.Value.bids.First().Value; } else { TempSt.StrategySell.Data.Add(i.Value.bids.First().Key, i.Value.bids.First().Value); } //отнять в списках большее значение temp.asks[temp.asks.First().Key] -= -i.Value.bids.First().Value; //удалить из списков меньшее значение i.Value.bids.Remove(i.Value.bids.First().Key); } else if (temp.asks.First().Value < i.Value.bids.First().Value) { //записать в стратегию значение цены и количество if (TempSt.StrategyBuy.Data.ContainsKey(temp.asks.First().Key)) { TempSt.StrategyBuy.Data[temp.asks.First().Key] += temp.asks.First().Value; } else { TempSt.StrategyBuy.Data.Add(temp.asks.First().Key, temp.asks.First().Value); } if (TempSt.StrategySell.Data.ContainsKey(i.Value.bids.First().Key)) { TempSt.StrategySell.Data[i.Value.bids.First().Key] += temp.asks.First().Value; } else { TempSt.StrategySell.Data.Add(i.Value.bids.First().Key, temp.asks.First().Value); } //отнять в списках большее значение i.Value.bids[i.Value.bids.First().Key] -= temp.asks.First().Value; //удалить из списков меньшее значение temp.asks.Remove(temp.asks.First().Key); } if (temp.asks.Count == 0) { break; } if (temp.bids.Count == 0) { break; } if (i.Value.asks.Count == 0) { break; } if (i.Value.bids.Count == 0) { break; } } MainSt.Add(TempSt); } } return(MainSt); #endregion }
public static MainStrategy CoinCompare(TransformOrders arg1, TransformOrders arg2, Stock mainStockEx, Stock secoondStockEx, string MarketName) { if (arg1 == null || arg2 == null) { return(null); } TransformOrders main = new TransformOrders() { asks = arg2.asks.Take(30).ToDictionary(c => c.Key, v => v.Value), bids = arg2.bids.Take(30).ToDictionary(c => c.Key, v => v.Value) }; TransformOrders second = new TransformOrders() { asks = arg1.asks.Take(30).ToDictionary(c => c.Key, v => v.Value), bids = arg1.bids.Take(30).ToDictionary(c => c.Key, v => v.Value) }; #region сравнение валют и запись из в стратегию if (IsProfit(second.bids.First().Key, main.asks.First().Key)) { MainStrategy TempSt = new MainStrategy(); TempSt.MarketName = MarketName; TempSt.BuyStockEX = mainStockEx; TempSt.SellStockEX = secoondStockEx; //buy on [livecoin] main sell on [poloniex] several while (IsProfit(second.bids.First().Key, main.asks.First().Key)) { if (main.asks.First().Value > second.bids.First().Value) { //записать в стратегию значение цены и количество в цикле пока профит if (TempSt.StrategyBuy.ContainsKey(main.asks.First().Key)) { TempSt.StrategyBuy[main.asks.First().Key] += second.bids.First().Value; } else { TempSt.StrategyBuy.Add(main.asks.First().Key, second.bids.First().Value); } if (TempSt.StrategySell.ContainsKey(second.bids.First().Key)) { TempSt.StrategySell[second.bids.First().Key] += second.bids.First().Value; } else { TempSt.StrategySell.Add(second.bids.First().Key, second.bids.First().Value); } //отнять в списках большее значение main.asks[main.asks.First().Key] -= second.bids.First().Value; //удалить из списков меньшее значение second.bids.Remove(second.bids.First().Key); } else if (main.asks.First().Value < second.bids.First().Value) { //записать в стратегию значение цены и количество if (TempSt.StrategyBuy.ContainsKey(main.asks.First().Key)) { TempSt.StrategyBuy[main.asks.First().Key] += main.asks.First().Value; } else { TempSt.StrategyBuy.Add(main.asks.First().Key, main.asks.First().Value); } if (TempSt.StrategySell.ContainsKey(second.bids.First().Key)) { TempSt.StrategySell[second.bids.First().Key] += main.asks.First().Value; } else { TempSt.StrategySell.Add(second.bids.First().Key, main.asks.First().Value); } //отнять в списках большее значение second.bids[second.bids.First().Key] -= main.asks.First().Value; //удалить из списков меньшее значение main.asks.Remove(main.asks.First().Key); } if (second.asks.Count == 0) { break; } if (second.bids.Count == 0) { break; } if (main.asks.Count == 0) { break; } if (main.bids.Count == 0) { break; } //равные значения будут нужны для возврата валюты //else if (temp.bids.First()[1] == i.Value.asks.First()[1]) //{ // //записать в стратегию значение цены и количество // MainSt.StrategyBuy.Data[temp.bids.First()[0]] += i.Value.asks.First()[1]; // MainSt.StrategySell.Data[i.Value.asks.First()[0]] += i.Value.asks.First()[1]; // //удалить из списков меньшее значение // temp.bids.First().Clear(); // i.Value.asks.First().Clear(); //} } return(TempSt); } return(new MainStrategy()); #endregion }