本文整理汇总了C#中Strategy.Init方法的典型用法代码示例。如果您正苦于以下问题:C# Strategy.Init方法的具体用法?C# Strategy.Init怎么用?C# Strategy.Init使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Strategy
的用法示例。
在下文中一共展示了Strategy.Init方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: setStrategyInit
/// <summary>
/// 初始化策略
/// </summary>
/// <param name="strategy"></param>
/// <param name="mdMode"></param>
/// <param name="codes"></param>
/// <param name="strategyId"></param>
/// <param name="bar_cfg"></param>
/// <param name="bTime"></param>
/// <param name="eTime"></param>
/// <returns></returns>
public static int setStrategyInit(Strategy strategy,int mdMode,string codes,String strategyId,string bar_cfg)
{
if (String.IsNullOrEmpty(codes))
{
return -1;
}
if (bar_cfg == null)
{
bar_cfg = "bar.60";
}
if (string.IsNullOrEmpty(strategyId))
{
strategyId = DEFAULT_STRATAGY_ID;
}
string subscribe_symbols = "";
List<string> codeList = codes.Split(",".ToCharArray()).ToList();
foreach (string c in codeList)
{
subscribe_symbols += MdComm.getJJCfgCode(c, "tick", bar_cfg) + ",";
}
int ret = -1;
switch (mdMode)
{
case 1:
ret = strategy.Init("18221685724",
"yjb_1983",
strategyId,
subscribe_symbols,
MDMode.MD_MODE_NULL,
"localhost:8001");
break;
case 2:
ret = strategy.Init("18221685724",
"yjb_1983",
strategyId,
subscribe_symbols,
MDMode.MD_MODE_LIVE,
"localhost:8001");
break;
case 3:
ret = strategy.Init("18221685724",
"yjb_1983",
strategyId,
subscribe_symbols,
MDMode.MD_MODE_SIMULATED,
"localhost:8001");
break;
case 4:
ret = strategy.Init("18221685724",
"yjb_1983",
strategyId,
subscribe_symbols,
MDMode.MD_MODE_PLAYBACK,
"localhost:8001");
break;
default:
ret = strategy.Init("18221685724",
"yjb_1983",
strategyId,
subscribe_symbols,
MDMode.MD_MODE_SIMULATED,
"localhost:8001");
break;
}
if (ret != 0)
{
System.Console.WriteLine("Init error: {0}", ret);
}
return ret;
}
示例2: StartStrategy
public void StartStrategy(Strategy strategy, StrategyMode mode)
{
lock (this)
{
this.subscriptions.Clear();
Strategy = strategy;
Mode = mode;
if (this.framework.Mode == FrameworkMode.Simulation)
{
this.framework.Clock.DateTime = this.framework.ProviderManager.DataSimulator.DateTime1;
this.framework.ExchangeClock.DateTime = DateTime.MinValue;
}
if (this.framework.EventManager.Status != EventManagerStatus.Running)
this.framework.EventManager.Start();
SetStatusType(StrategyStatusType.Started);
if (Persistence == StrategyPersistence.Full || Persistence == StrategyPersistence.Load)
{
this.framework.PortfolioManager.Load(strategy.Name);
this.framework.OrderManager.Load(strategy.Name, -1);
this.framework.OrderServer.SeriesName = strategy.Name;
this.framework.OrderManager.IsPersistent = true;
}
else
{
this.framework.OrderManager.IsPersistent = false;
}
strategy.Init();
if ((Persistence == StrategyPersistence.Full || Persistence == StrategyPersistence.Save) && !strategy.Portfolio.IsLoaded)
this.framework.PortfolioManager.Save(strategy.Portfolio);
strategy.EmitStrategyStart();
if (!this.framework.IsExternalDataQueue)
{
var dictionary = new Dictionary<IDataProvider, InstrumentList>();
while (this.subscriptions.Count != 0)
{
var dictionary2 = new Dictionary<IDataProvider, InstrumentList>(this.subscriptions);
this.subscriptions.Clear();
foreach (var current in dictionary2)
{
InstrumentList instrumentList = null;
if (!dictionary.TryGetValue(current.Key, out instrumentList))
{
instrumentList = new InstrumentList();
dictionary[current.Key] = instrumentList;
}
InstrumentList instrumentList2 = new InstrumentList();
foreach (Instrument current2 in current.Value)
{
if (!instrumentList.Contains(current2))
{
instrumentList.Add(current2);
instrumentList2.Add(current2);
}
}
if (current.Key is SellSideStrategy)
{
this.framework.SubscriptionManager?.Subscribe(current.Key, instrumentList2);
}
}
}
SetParametersGroup();
Status = StrategyStatus.Running;
this.subscriptions = dictionary;
if (this.subscriptions.Count == 0 && mode == StrategyMode.Backtest)
{
Console.WriteLine($"{DateTime.Now } StrategyManager::StartStrategy {strategy.Name} has no data requests in backtest mode, stopping...");
StopStrategy();
}
else
{
foreach (var current3 in this.subscriptions)
{
if (!(current3.Key is SellSideStrategy))
this.framework.SubscriptionManager?.Subscribe(current3.Key, current3.Value);
}
if (mode != StrategyMode.Backtest)
strategy.FundamentalProvider?.Connect();
}
}
else
{
SetParametersGroup();
Status = StrategyStatus.Running;
}
}
}