-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinitwindow.cpp
264 lines (244 loc) · 11.6 KB
/
initwindow.cpp
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
#include "include/common.h"
void InitWindow::init_data_page(){
_datapage = new datapage();
((QGridLayout*)(data_page->layout()))->addWidget(_datapage);
}
void InitWindow::init_order_page(){
_orderpage = new orderpage();
((QGridLayout*)(order_page->layout()))->addWidget(_orderpage);
connect(this,SIGNAL(addorder(QString,QString,QString)),_orderpage,SLOT(addorder(QString,QString,QString)));
connect(this,SIGNAL(setorderstatus(QString,QString)),_orderpage,SLOT(setstatus(QString,QString)));
}
void InitWindow::init_account_page(){
_accountpage = new accountpage();
((QGridLayout*)(account_page->layout()))->addWidget(_accountpage);
}
void InitWindow::init_strategy_page(){
_strategypage = new stratgymanagepage();
((QGridLayout*)(strategy_page->layout()))->addWidget(_strategypage);
connect(_strategypage,SIGNAL(stratgy_changed()),this,SLOT(on_stratgy_changed()));
}
void InitWindow::init_trading_page(){
_tradingpage = new tradingpage();
QComboBox* cb = _tradingpage->get_stratgyselector();
QList<little_stratgymanageitem*> list = _strategypage->get_stratgies();
for(int i=0;i<list.size();i++){
cb->addItem(list.at(i)->getname());
}
connect(_tradingpage,SIGNAL(signal_start()),this,SLOT(on_trading_start()));
connect(_tradingpage,SIGNAL(signal_stop()),this,SLOT(on_trading_stop()));
connect(this,SIGNAL(appendText(QString)),_tradingpage,SLOT(appendText(QString)));
((QGridLayout*)(trading_page->layout()))->addWidget(_tradingpage);
}
void InitWindow::on_enlarge(LineChartBlockView* view){
}
InitWindow::InitWindow()
{
trading_status = 0;
//this->setMinimumSize(1600,960);
this->setStyleSheet(QStringLiteral("background-color:rgb(44,44,44);"));
MainView = new QHBoxLayout();
MenuLayout = new QVBoxLayout();
Menu_Page = new QLabel();//MenuLayout和PageLayout分隔
PageLayout = new QVBoxLayout();
Menu_Page->setMinimumWidth(1);
Menu_Page->setMaximumWidth(1);
Menu_Page->setStyleSheet(QStringLiteral("background-color:rgb(255,255,255);"));
MainView->addLayout(MenuLayout);
MainView->addWidget(Menu_Page);
MainView->addLayout(PageLayout);
title = new QLabel();
title->setMinimumHeight(64);
title->setMaximumHeight(64);
title->setFont(QFont("Arial Black",20,QFont::Bold));
title->setText("HTFS");
title->setStyleSheet(QStringLiteral("color: rgb(255, 255, 255);"));
account_manage = new clickablelabel();
account_manage->setPixmap(QPixmap(u8":/img/我的.png").scaled(100,50,Qt::KeepAspectRatio));
account_manage->setAlignment(Qt::AlignCenter);
account_manage->setMinimumHeight(100);
data_view = new clickablelabel(u8"实时数据");
data_view->setPixmap(QPixmap(u8":/img/行情.png").scaled(100,50,Qt::KeepAspectRatio));
data_view->setAlignment(Qt::AlignCenter);
data_view->setMinimumHeight(100);
strategy_manage = new clickablelabel(u8"策略配置");
strategy_manage->setPixmap(QPixmap(u8":/img/策略.png").scaled(100,50,Qt::KeepAspectRatio));
strategy_manage->setAlignment(Qt::AlignCenter);
strategy_manage->setMinimumHeight(100);
order_manage = new clickablelabel(u8"订单管理");
order_manage->setPixmap(QPixmap(u8":/img/订单.png").scaled(100,50,Qt::KeepAspectRatio));
order_manage->setAlignment(Qt::AlignCenter);
order_manage->setMinimumHeight(100);
trading = new clickablelabel();
trading->setPixmap(QPixmap(u8":/img/交易.png").scaled(100,50,Qt::KeepAspectRatio));
trading->setAlignment(Qt::AlignCenter);
trading->setMinimumHeight(100);
verticalSpacer = new QSpacerItem(20,40,QSizePolicy::Minimum, QSizePolicy::Expanding);
MenuLayout->addWidget(title);
MenuLayout->addWidget(data_view);
MenuLayout->addWidget(trading);
MenuLayout->addWidget(strategy_manage);
MenuLayout->addWidget(order_manage);
MenuLayout->addWidget(account_manage);
MenuLayout->addSpacerItem(verticalSpacer);
Pages = new QStackedWidget();
//Pages->setStyleSheet(QStringLiteral("background-color: rgb(40,43, 59);"));
data_page = new QWidget();
data_page->setLayout(new QGridLayout());
strategy_page = new QWidget();
strategy_page->setLayout(new QGridLayout());
account_page = new QWidget();
account_page->setLayout(new QGridLayout());
order_page = new QWidget();
order_page->setLayout(new QGridLayout());
trading_page = new QWidget();
trading_page->setLayout(new QGridLayout());
Pages->addWidget(data_page);
Pages->addWidget(trading_page);
Pages->addWidget(strategy_page);
Pages->addWidget(account_page);
Pages->addWidget(order_page);
label_10 = new QLabel();
workspace = new QLabel(u8"行情数据");
workspace->setFont(QFont(u8"黑体",16));
workspace->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
workspace->setStyleSheet(QStringLiteral("color: rgb(255, 255, 255);"));
PageLayout->addWidget(workspace);
PageLayout->addWidget(Pages);
PageLayout->addWidget(label_10);
Pages->setCurrentIndex(0);
connect(data_view, SIGNAL(clicked()), this, SLOT(on_data_view_clicked()));
connect(trading, SIGNAL(clicked()), this, SLOT(on_trading_clicked()));
connect(strategy_manage, SIGNAL(clicked()), this, SLOT(on_strategy_manage_clicked()));
connect(account_manage, SIGNAL(clicked()), this, SLOT(on_account_manage_clicked()));
connect(order_manage, SIGNAL(clicked()), this, SLOT(on_order_manage_clicked()));
init_data_page();
init_strategy_page();
init_trading_page();
init_order_page();
init_account_page();
this->setLayout(MainView);
}
void InitWindow::on_data_view_clicked(){
Pages->setCurrentIndex(0);
workspace->setText(u8"行情数据");
}
void InitWindow::on_trading_clicked(){
Pages->setCurrentIndex(1);
workspace->setText(u8"交易");
}
void InitWindow::on_strategy_manage_clicked(){
Pages->setCurrentIndex(2);
workspace->setText(u8"策略配置");
}
void InitWindow::on_account_manage_clicked(){
Pages->setCurrentIndex(3);
workspace->setText(u8"账户管理");
}
void InitWindow::on_order_manage_clicked(){
Pages->setCurrentIndex(4);
workspace->setText(u8"订单管理");
}
void InitWindow::on_stratgy_changed(){
QComboBox* cb = _tradingpage->get_stratgyselector();
cb->clear();
QList<little_stratgymanageitem*> list = _strategypage->get_stratgies();
for(int i=0;i<list.size();i++){
cb->addItem(list.at(i)->getname());
}
}
void InitWindow::on_trading_start(){
if(trading_status==1)return;
QList<little_stratgymanageitem*> list = _strategypage->get_stratgies();
QPlainTextEdit* record = _tradingpage->get_recordtext();
if(list.size()==0){
record->appendPlainText(u8"未选择策略,请检查您的策略配置");
}
else{
trading_status = 1;
QComboBox* cb = _tradingpage->get_stratgyselector();
little_stratgymanageitem* nowstratgy = list.at(cb->currentIndex());
record->appendPlainText(u8"------------------------------------------------");
record->appendPlainText(u8"交易开始");
double r;//年利率
double q;//年红利
double futures_commission;//期货双边手续费
double futures_cost;//期货买卖冲击成本
double stock_commission;//股票买卖双边手续费
double stock_cost;//股票买卖冲击成本
double stamp_duty;//股票交易印花税
double stock_impact_cost;//股票买卖冲击成本
double stock_index_error;//股票指数跟踪误差
double borrowing_cost;//借贷利差成本
double security;
QString name;
nowstratgy->getvalues(&name,
&r,
&q,
&futures_commission,
&futures_cost,
&stock_commission,
&stock_cost,
&stamp_duty,
&stock_impact_cost,
&stock_index_error,
&borrowing_cost,
&security);
record->appendPlainText(u8"现在正在使用的策略为:"+name);
record->appendPlainText(u8"\t年利率 "+QString::number(r));
record->appendPlainText(u8"\t年红利 "+QString::number(q));
record->appendPlainText(u8"\t期货双边手续费 "+QString::number(futures_commission));
record->appendPlainText(u8"\t期货买卖冲击成本 "+QString::number(futures_cost));
record->appendPlainText(u8"\t股票买卖双边手续费 "+QString::number(stock_commission));
record->appendPlainText(u8"\t股票买卖冲击成本 "+QString::number(stock_cost));
record->appendPlainText(u8"\t股票交易印花税 "+QString::number(stamp_duty));
record->appendPlainText(u8"\t股票买卖冲击成本 "+QString::number(stock_impact_cost));
record->appendPlainText(u8"\t股票指数跟踪误差 "+QString::number(stock_index_error));
record->appendPlainText(u8"\t借贷利差成本 "+QString::number(borrowing_cost));
record->appendPlainText(u8"\t安全系数 "+QString::number(borrowing_cost));
int market_net;
int trading_net;
_accountpage->getnetconf(&market_net,&trading_net);
record->appendPlainText(u8"网络配置:");
record->appendPlainText(u8"\t市场配置:link"+QString::number(market_net+1));
record->appendPlainText(u8"\t交易配置:link"+QString::number(trading_net+1));
record->appendPlainText(u8"被监控的合约:");
for(auto& i:*trade_handler::instr_set){
record->appendPlainText("\t"+i->instrment_id);
}
/*TO-DO*/
trade_handler::trade_switch=true;
trade_handler::strategy->set_name(name.toStdString());
trade_handler::strategy->setAnnual_interest_rate(r);
trade_handler::strategy->setAnnual_bonus_rate(q);
trade_handler::strategy->setFuture_commission(futures_commission);
trade_handler::strategy->setImpact_cost(futures_cost);
trade_handler::strategy->setstock_commision_rate(stock_commission);
trade_handler::strategy->setStock_stamp_duty_rate(stock_cost);
trade_handler::strategy->setStock_stamp_duty_rate(stamp_duty);
trade_handler::strategy->setStock_impact_cost(stock_impact_cost);
trade_handler::strategy->setIndex_track_error_rate(stock_index_error);
trade_handler::strategy->setCost_borrow_spread(borrowing_cost);
trade_handler::strategy->setSecurity_factor(security);
trade_handler::strategy->set_valid_strategy(true);
trade_handler::trade_switch=true;
}
}
void InitWindow::on_trading_stop(){
if(trading_status==0)return;
trading_status = 0;
_tradingpage->get_recordtext()->appendPlainText(u8"交易结束");
_tradingpage->get_recordtext()->appendPlainText(u8"------------------------------------------------");
/*TO-DO*/
trade_handler::strategy->set_valid_strategy(false);
trade_handler::trade_switch=false;
}
void InitWindow::addorder_request(QString id, QString time, QString status){
emit addorder(id,time,status);
}
void InitWindow::setorderstatus_request(QString id, QString status){
emit setorderstatus(id,status);
}
void InitWindow::appendText_request(QString text){
emit appendText(text);
}