-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainForm.cs
138 lines (112 loc) · 5.04 KB
/
MainForm.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
using Akka.Actor;
using Quanter.BusinessEntity;
using Quanter.Market;
using Quanter.Persistence;
using Quanter.Strategy;
using Quanter.Trader.Messages;
using System;
using System.ComponentModel;
using System.Windows.Forms;
namespace Quanter.Trader.Gui
{
public partial class MainForm : Form
{
private event EventHandler<StrategiesResponse> strategiesDataAvailable; // 所有的策略列表,我的策略列表,
private ActorSystem actorSystem;
private IActorRef persistenceActor;
private IActorRef strategyActor;
private IActorRef marketActor;
private IActorRef userActor;
public MainForm()
{
InitializeComponent();
//actorSystem = ActorSystem.Create("strategies");
//var clientActor = actorSystem.ActorOf(Props.Create<StockTraderClientActor>());
// 登录
//ClientRequest loginReq = new ClientRequest()
//{
// Action = RequestType.LOGIN,
// Body = new User() { Username = "joe", Password = "123456" }
//};
//Stopwatch watch = new Stopwatch();
//watch.Start();
//var resp0 = clientActor.Ask<ClientResponse>(loginReq, TimeSpan.FromSeconds(15));
//resp0.Wait();
//Console.WriteLine("返回:{0}, 耗时:{1}", resp0.Result.Body, watch.ElapsedMilliseconds);
//// 获取所有的策略列表
//var resp = clientActor.Ask<ClientResponse>(new ClientRequest() { Action = RequestType.GET_ALL_STRATEGIES }, TimeSpan.FromSeconds(5));
//resp.Wait();
//StrategiesResponse rep = (StrategiesResponse)(resp.Result.Body);
//rep.Strategies.AsParallel<StrategyDesc>().ForAll<StrategyDesc>(sd => Console.WriteLine("策略 {0}", sd.Name));
// 启动行情
//clientActor.Tell(new ClientRequest() { Action = RequestType.START_MARKET });
//// 获取我的策略
//clientActor.Tell(new ClientRequest() { Action = RequestType.GET_MY_STRATEGIES });
//// 启动我的策略
//clientActor.Tell(new ClientRequest() { Action = RequestType.START_MY_STRATEGIES });
//Thread.Sleep(1000);
//clientActor.Tell(new ClientRequest() { Action = RequestType.STOP_MY_STRATEGIES });
//// 停止行情
//clientActor.Tell(new ClientRequest() { Action = RequestType.STOP_MARKET });
btnInit_Click(null, null);
}
private void _init()
{
actorSystem = ActorSystem.Create("strategiesServer");
strategyActor = actorSystem.ActorOf(Props.Create<StrategyManagerActor>(), ConstantsHelper.AKKA_PATH_STRATEGY_MANAGER);
persistenceActor = actorSystem.ActorOf(Props.Create<PersistenceActor>(), ConstantsHelper.AKKA_PATH_PERSISTENCE);
marketActor = actorSystem.ActorOf(Props.Create<SecuritiesMarketManagerActor>(), ConstantsHelper.AKKA_PATH_MARKET_MANAGER);
}
protected override void OnClosing(CancelEventArgs e)
{
actorSystem.Shutdown();
base.OnClosing(e);
}
private void btnInit_Click(object sender, EventArgs e)
{
_init();
}
private void btnStartMarket_Click(object sender, EventArgs e)
{
marketActor.Tell(new MarketRequest() { Type = MarketRequest.RequestType.START });
}
private void btnStopMarket_Click(object sender, EventArgs e)
{
marketActor.Tell(new MarketRequest() { Type = MarketRequest.RequestType.STOP });
}
private void btnStartStrategy_Click(object sender, EventArgs e)
{
}
private void btnRegStrategy_Click(object sender, EventArgs e)
{
// Load一个新的策略实例
EStrategy strategy1 = new EStrategy()
{
Id = 1,
Type = "Quanter.Strategy.Demo.DemoStrategyActor, Quanter.Strategy.Demo",
Name= "Demo示例",
Desc = "Demo实例"
};
EStrategy strategy2 = new EStrategy()
{
Id = 2,
Type = "Quanter.Strategy.XueQiuStrategy.TraceXueQiuStrategyActor, Quanter.Strategy.XueQiuStrategy",
Name = "雪球策略",
Desc = "雪球实例"
};
EStrategy strategy3 = new EStrategy()
{
Id = 3,
Type = "Quanter.Strategy.RationBStrategyActor, Quanter.Strategy.RationB",
Name = "分级策略",
Desc = "雪球实例"
};
StrategyRequest req = new StrategyRequest() { Type = StrategyRequestType.CREATE, Body = strategy1 };
strategyActor.Tell(req);
//req = new StrategyRequest() { Type = StrategyRequestType.CREATE, Body = strategy2 };
//strategyActor.Tell(req);
//req = new StrategyRequest() { Type = StrategyRequestType.CREATE, Body = strategy3 };
//strategyActor.Tell(req);
}
}
}