public override void Init(int botId, string name, CSettingsBot settingsBot,
                                  Dictionary <string, string> dictSettingsStrategy, CPlaza2Connector plaza2Connector)
        {
            base.Init(botId, name, settingsBot,
                      dictSettingsStrategy, plaza2Connector);

            SetState(EnmStratStates._000_PreInitial);
        }
Exemplo n.º 2
0
        /* private object GeSettingsSupervisor(XmlNode node)
         * {
         *
         *   XmlNodeList xnList = node.SelectNodes("StrategySettings/limits/limit");
         *   CBotSupervisorSettings bss = new CBotSupervisorSettings();
         *   foreach (XmlNode lim in xnList)
         *   {
         *       string isin = lim.Attributes["isin"].Value.ToString();
         *
         *       bss.DictInstrumentLimits[isin] = new CBotSupervisorInstrumentLimits();
         *       bss.DictInstrumentLimits[isin].MaxOpenedPos = Convert.ToInt32(lim.Attributes["MaxOpenedPos"].Value.ToString());
         *       bss.DictInstrumentLimits[isin].MaxLossVM = Convert.ToDecimal(lim.Attributes["MaxLossVM"].Value.ToString());
         *   }
         *
         *   return (object)bss;
         *
         * }
         */


        public void CreateOneBotFromConfig(Dictionary <string, object> botConfig, List <Dictionary <string, object> > lstBotsInstrumentsConfig, int num, ref List <CBotBase> listBots,
                                           bool needSynchroOnLoad)
        {
            try
            {
                Log("Start CreateOneBotFromConfig");
                string type = (string)botConfig["type"];

                bool bEnabled        = Convert.ToBoolean(botConfig["Enabled"].ToString());
                bool bExternal       = Convert.ToBoolean(botConfig["External"].ToString());
                bool bNeedTFAnalyzer = Convert.ToBoolean(botConfig["NeedTFAnalyzer"].ToString());

                decimal maxLossVMClosedTotal = Convert.ToDecimal(botConfig["MaxLossVMClosedTotal"]);

                int StockExhId = Convert.ToInt16(botConfig["StockExchId"]);


                System.Xml.XmlDocument document = new System.Xml.XmlDocument();
                document.LoadXml((string)botConfig["StrategySettings"]);


                XmlNode xmlNLStrategySettings = document.SelectSingleNode("StrategySettings");

                Dictionary <string, string> dictSettingsStrategy = new Dictionary <string, string>();
                foreach (XmlNode nd in xmlNLStrategySettings)
                {
                    dictSettingsStrategy[nd.Name] = nd.InnerText;
                }

                enmStrategysCode code = m_dictBotNameCode[type];



                string botName = GenerateBotName(type, num);



                Dictionary <string, CBotLimits>       dictBotIsinLimits        = new Dictionary <string, CBotLimits>();
                Dictionary <string, CTradingSettings> dictBotIsinTradeSettings = new Dictionary <string, CTradingSettings>();



                var res = lstBotsInstrumentsConfig.FindAll(a => (int)a["BotId"] == num);
                if (res != null)
                {
                    List <string> listIsins = new List <string>();


                    foreach (var instConf in res)
                    {
                        string instrument = (string)instConf["Instrument"];
                        dictBotIsinLimits[instrument] = new CBotLimits((int)instConf["MaxSendOrderRuntime"],
                                                                       (int)instConf["MaxPosition"],
                                                                       (int)instConf["MaxAddedOrder"],
                                                                       (decimal)instConf["MaxLossVM"]);

                        long SL  = 0;
                        long TP  = 0;
                        int  lot = 0;

                        if (instConf["StopLoss"] != null)
                        {
                            SL = Convert.ToInt32(instConf["StopLoss"]);
                        }

                        if (instConf["TakeProfit"] != null)
                        {
                            TP = Convert.ToInt32(instConf["TakeProfit"]);
                        }

                        if (instConf["Lot"] != null)
                        {
                            lot = Convert.ToInt32(instConf["Lot"]);
                        }


                        dictBotIsinTradeSettings[instrument] = new CTradingSettings(SL, TP, lot);

                        listIsins.Add(instrument);
                    }



                    CSettingsBot settingsBot = new CSettingsBot(code, bEnabled, listIsins, dictBotIsinLimits,
                                                                dictBotIsinTradeSettings, bExternal, bNeedTFAnalyzer, maxLossVMClosedTotal);


                    object stratSettings = null;
                    settingsBot.StrategySettings = stratSettings;


                    CBotBase bot = null;
                    if (!bExternal)
                    {
                        if (code == enmStrategysCode.StrategyTest)
                        {
                            bot = new CBotTester(num, botName, settingsBot, dictSettingsStrategy, _dealingServer);
                        }
                        else if (code == enmStrategysCode.StrategyTesterPos)
                        {
                            bot = new CBotTesterPos(num, botName, settingsBot, dictSettingsStrategy, _dealingServer);
                        }
                        else if (code == enmStrategysCode.StrategyHighLowContra)
                        {
                            bot = new CBotHighLowContra(num, botName, settingsBot, dictSettingsStrategy, _dealingServer);
                        }
                        else if (code == enmStrategysCode.StrategyTesterCrossFirst)
                        {
                            bot = new CBotTesterCrossFirst(num, botName, settingsBot, dictSettingsStrategy, _dealingServer);
                        }
                        else if (code == enmStrategysCode.StrategyTesterCrossSecond)
                        {
                            bot = new CBotTesterCrossSecond(num, botName, settingsBot, dictSettingsStrategy, _dealingServer);
                        }
                        else if (code == enmStrategysCode.StrategyTesterLimits)
                        {
                            bot = new CBotTesterLimits(num, botName, settingsBot, dictSettingsStrategy, _dealingServer);
                        }
                        else if (code == enmStrategysCode.StrategyTrader)
                        {
                            bot = new CBotTrader(num, botName, settingsBot, dictSettingsStrategy, _dealingServer);
                        }

                        Log("Created bot num=" + num + " botName=" + botName);
                        //listBots.Last().Start();
                    }
                    else
                    {
                        // if (code == enmStrategysCode.StrategyTesterExternal)
                        //   bot = CreateExternalBot(num, type, botName, settingsBot, dictSettingsStrategy, typeof(CBotTesterExternal).Assembly);
                    }

                    if (bot != null)
                    {
                        listBots.Add(bot);
                        _dealingServer.DictBots[bot.BotId] = bot;
                        bot.Start();
                        if (needSynchroOnLoad)
                        {
                            bot.SynchronizeOnBotReload();
                        }
                        //listBots.Last().Start();
                    }
                    Log("End CreateOneBotFromConfig");


                    ;
                }



                /*
                 * XmlNodeList xnList = botXML.SelectNodes("isins/isin");
                 *
                 *
                 * List<string> listIsins = new List<string>();
                 * Dictionary<string, CBotLimits> dictBotIsinLimits = new Dictionary<string, CBotLimits>();
                 * Dictionary<string, CTradingSettings> dictBotIsinTradeSettings = new Dictionary<string, CTradingSettings>();
                 * foreach (XmlNode lst in xnList)
                 * {
                 *  string isin = lst.InnerText;
                 *  listIsins.Add(isin);
                 *
                 *  dictBotIsinLimits[isin] = new CBotLimits(lst.Attributes["MaxSendOrderRuntime"].Value.ToString(), lst.Attributes["MaxPosition"].Value.ToString(),
                 *                                               lst.Attributes["MaxAddedOrder"].Value.ToString(), lst.Attributes["MaxLossVM"].Value.ToString());
                 *
                 *
                 *  long SL = 0;
                 *  long TP = 0;
                 *  int lot = 0;
                 *  if (lst.Attributes["StopLoss"] != null)
                 *      SL = Convert.ToInt32((lst.Attributes["StopLoss"].Value.ToString()));
                 *
                 *  if (lst.Attributes["TakeProfit"] != null)
                 *      TP = Convert.ToInt32((lst.Attributes["TakeProfit"].Value.ToString()));
                 *
                 *  if (lst.Attributes["Lot"] != null)
                 *      lot = Convert.ToInt32((lst.Attributes["Lot"].Value.ToString()));
                 *
                 *
                 *  dictBotIsinTradeSettings[isin] = new CTradingSettings(SL, TP, lot);
                 *
                 * }
                 *
                 * object stratSettings = null;
                 * //if (type == "Supervisor") stratSettings = GeSettingsSupervisor(botXML);
                 *
                 *
                 *
                 * XmlNode xmlNLStrategySettings = botXML.SelectSingleNode("StrategySettings");
                 * Dictionary<string, string> dictSettingsStrategy = new Dictionary<string, string>();
                 * foreach (XmlNode nd in xmlNLStrategySettings)
                 *  dictSettingsStrategy[nd.Name] = nd.InnerText;
                 *
                 *
                 *
                 * CSettingsBot settingsBot = new CSettingsBot(code, bEnabled, listIsins, dictBotIsinLimits,
                 *                                          dictBotIsinTradeSettings, bExternal, bNeedTFAnalyzer,maxLossVMClosedTotal);
                 * settingsBot.StrategySettings = stratSettings;
                 * //--- exp ------
                 *
                 *
                 * CBotBase bot = null;
                 *
                 * //TO DO refactor it
                 * //-----------
                 * if (!bExternal)
                 * {
                 *  if (code == enmStrategysCode.StrategyTest)
                 *      bot = new CBotTester(num, botName, settingsBot, dictSettingsStrategy, _dealingServer);
                 *  else if (code == enmStrategysCode.StrategyTesterPos)
                 *      bot = new CBotTesterPos(num, botName, settingsBot, dictSettingsStrategy, _dealingServer);
                 *  else if (code == enmStrategysCode.StrategyHighLowContra)
                 *      bot = new CBotHighLowContra(num, botName, settingsBot, dictSettingsStrategy, _dealingServer);
                 *  else if (code == enmStrategysCode.StrategyTesterCrossFirst)
                 *      bot = new CBotTesterCrossFirst(num, botName, settingsBot, dictSettingsStrategy, _dealingServer);
                 *  else if (code == enmStrategysCode.StrategyTesterCrossSecond)
                 *      bot = new CBotTesterCrossSecond(num, botName, settingsBot, dictSettingsStrategy, _dealingServer);
                 *  else if (code == enmStrategysCode.StrategyTesterLimits)
                 *      bot = new CBotTesterLimits(num, botName, settingsBot, dictSettingsStrategy, _dealingServer);
                 *  else if (code == enmStrategysCode.StrategyTrader)
                 *      bot = new CBotTrader (num, botName, settingsBot, dictSettingsStrategy, _dealingServer);
                 *
                 *                      Log("Created bot num="+num+" botName="+botName);
                 *  //listBots.Last().Start();
                 * }
                 * else
                 * {
                 * // if (code == enmStrategysCode.StrategyTesterExternal)
                 *   //   bot = CreateExternalBot(num, type, botName, settingsBot, dictSettingsStrategy, typeof(CBotTesterExternal).Assembly);
                 *
                 * }
                 *
                 * if (bot != null)
                 * {
                 *  listBots.Add(bot);
                 *  _dealingServer.DictBots[bot.BotId] = bot;
                 *  bot.Start();
                 *  if (needSynchroOnLoad)
                 *      bot.SynchronizeOnBotReload();
                 *  //listBots.Last().Start();
                 *
                 * }
                 *              Log("End CreateOneBotFromConfig");
                 */
            }
            catch (Exception e)
            {
                Error("CBotFactory.CreateOneBotFromConfig", e);
            }
        }
 public CBotTesterExternal(int botId, string name, CSettingsBot settingsBot,
                           Dictionary <string, string> dictSettingsStrategy, CPlaza2Connector plaza2Connector) :
     base(botId, name, settingsBot, dictSettingsStrategy, plaza2Connector)
 {
     // SetState(EnmStratStates._000_PreInitial);
 }