更多量化交易编程:
K先绘画器
来源于开源项目WnStock
WnStockView.cpp
void CWnStockView::DrawKLine()
{
int j = 0;
CClientDC dc(this);
CWnStockDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CPen cyanPen(PS_SOLID,1,RGB(116, 245, 240));//创建一个宽度为1的实线画笔
CBrush cyanBrush(RGB(116, 245, 240));
CPen redPen(PS_SOLID,1,RGB(240, 0, 0));
CBrush blackBrush(RGB(0, 0, 0));
char chName[200] = {0};
//pDoc->stockDoc->ExchangeK();
CRect rect, kRect, kaRect;
GetClientRect(&rect);
float lw = (rect.right - 200 -62)/pDoc->stockDoc->KDay;//每个K线所占的宽度
int n = pDoc->stockDoc->vKPoint.size(); //获得保存坐标个数
if (n == 0)
{
return;
}
//显示最新的数据
if(n < pDoc->stockDoc->KDay - pDoc->stockDoc->KBegin)
j = 0+ pDoc->stockDoc->KPos;
else
j = n - (pDoc->stockDoc->KDay - pDoc->stockDoc->KBegin) + pDoc->stockDoc->KPos;
int i;
int pos = pDoc->stockDoc->KPos;
for(/*int*/ i = j ; i < n; i++)
{
if((pDoc->stockDoc->vKPoint[i]->close.y) <= (pDoc->stockDoc->vKPoint[i]->open.y)) //收盘价大于开盘价为阳线
{
dc.SelectObject(&redPen);
dc.SelectObject(&blackBrush);
}
else
{
dc.SelectObject(&cyanPen);
dc.SelectObject(&cyanBrush);
}
/* if(62 + (i-j)*lw + pDoc->stockDoc->Get_kPointArray(i).high.x + pDoc->stockDoc->Get_kBegine()*(rect.right - 200 - 62)/pDoc->stockDoc->Get_kDay() > 62 && 62 + (i-j)*lw + pDoc->stockDoc->Get_kPointArray(i).high.x + pDoc->stockDoc->Get_kBegine()*(rect.right - 200 - 62)/pDoc->stockDoc->Get_kDay() < rect.right - 200)*/
//判断坐标是否在绘制K线的区域
if (62 + (i-j)*lw + pDoc->stockDoc->vKPoint[i]->high.x + pDoc->stockDoc->KBegin*lw > 62 && 62 + (i-j)*lw + pDoc->stockDoc->vKPoint[i]->high.x + pDoc->stockDoc->KBegin*lw < rect.right - 200)
{
dc.MoveTo(62 + (i-j)*lw + pDoc->stockDoc->vKPoint[i]->high.x + pDoc->stockDoc->KBegin*lw, pDoc->stockDoc->vKPoint[i]->high.y);
dc.LineTo(62 + (i-j)*lw + pDoc->stockDoc->vKPoint[i]->low.x + pDoc->stockDoc->KBegin*lw, pDoc->stockDoc->vKPoint[i]->low.y);
kRect.left =62 + (i-j)*lw + pDoc->stockDoc->vKPoint[i]->open.x + pDoc->stockDoc->KBegin*lw;
kRect.top = pDoc->stockDoc->vKPoint[i]->open.y;
kRect.right = 62 + (i-j)*lw +pDoc->stockDoc->vKPoint[i]->close.x + pDoc->stockDoc->KBegin*lw;
kRect.bottom = pDoc->stockDoc->vKPoint[i]->close.y;
dc.Rectangle(&kRect); //画矩形
//@20150506解决开盘板没有K线问题,和开盘价等于收盘价没有横线只有竖线问题
if (pDoc->stockDoc->vKPoint[i]->open.y == pDoc->stockDoc->vKPoint[i]->close.y)
{
dc.MoveTo(62 + (i-j)*lw + pDoc->stockDoc->vKPoint[i]->open.x + pDoc->stockDoc->KBegin*lw,pDoc->stockDoc->vKPoint[i]->open.y);
dc.LineTo(62 + (i-j)*lw +pDoc->stockDoc->vKPoint[i]->close.x + pDoc->stockDoc->KBegin*lw,pDoc->stockDoc->vKPoint[i]->close.y);
}
//画K线总量坐标
kaRect.left = 62 + (i-j)*lw + pDoc->stockDoc->vVolumePoint[i]->top.x + pDoc->stockDoc->KBegin*lw;
kaRect.top = pDoc->stockDoc->vVolumePoint[i]->top.y;
kaRect.right = 62 + (i-j)*lw +pDoc->stockDoc->vVolumePoint[i]->bottom.x + pDoc->stockDoc->KBegin*lw;
kaRect.bottom = pDoc->stockDoc->vVolumePoint[i]->bottom.y;
dc.Rectangle(&kaRect);
}
}
//画K线价格坐标值
dc.SetBkMode(TRANSPARENT);
dc.SetTextColor(RGB(240, 0, 0));
dc.SetTextAlign(TA_RIGHT);
float KM = pDoc->stockDoc->KHighMax - pDoc->stockDoc->KLowMin;
for(i = 0; i < 9; i++)
{
sprintf(chName, "%10.2f", pDoc->stockDoc->KHighMax - (KM/9.0)*i);
dc.TextOut(55, 17 + 0.5 * m_interKH + i * m_interKH - 10, chName, lstrlen(chName));
}
sprintf(chName, "%10.2f", pDoc->stockDoc->KHighMax - (KM/9.0)*9);
dc.TextOut(55, 17 + 9.5 * m_interKH - 20, chName, lstrlen(chName));
//画K线成交金量坐标值
dc.SetTextColor(RGB(116, 245, 240));
sprintf(chName, "%8.0d万", pDoc->stockDoc->KMaxVolume/10000);
dc.TextOut(55, rect.bottom - 50 - 6*m_interKH - 8, chName, lstrlen(chName));
sprintf(chName, "%8.0d万", pDoc->stockDoc->KMaxVolume/10000/2);
dc.TextOut(55, rect.bottom - 50 - 5*m_interKH -8, chName, lstrlen(chName));
sprintf(chName, "%d", 0);
dc.TextOut(55, rect.bottom - 50 - 4*m_interKH -8, chName, lstrlen(chName));
return;
}
tick数据处理器
来源vnpy-2.0.9
vnpy/app/engine.py
def load_tick(
self,
vt_symbol: str,
days: int,
callback: Callable[[TickData], None]
):
""""""
symbol, exchange = extract_vt_symbol(vt_symbol)
end = datetime.now()
start = end - timedelta(days)
ticks = database_manager.load_tick_data(
symbol=symbol,
exchange=exchange,
start=start,
end=end,
)
for tick in ticks:
callback(tick)
vnpy/trader/utility
class BarGenerator:
"""
For:
1. generating 1 minute bar data from tick data
2. generateing x minute bar/x hour bar data from 1 minute data
Notice:
1. for x minute bar, x must be able to divide 60: 2, 3, 5, 6, 10, 15, 20, 30
2. for x hour bar, x can be any number
"""
def __init__(
self,
on_bar: Callable,
window: int = 0,
on_window_bar: Callable = None,
interval: Interval = Interval.MINUTE
):
"""Constructor"""
self.bar = None
self.on_bar = on_bar
self.interval = interval
self.interval_count = 0
self.window = window
self.window_bar = None
self.on_window_bar = on_window_bar
self.last_tick = None
self.last_bar = None
def update_tick(self, tick: TickData):
"""
Update new tick data into generator.
"""
new_minute = False
# Filter tick data with 0 last price
if not tick.last_price:
return
if not self.bar:
new_minute = True
elif self.bar.datetime.minute != tick.datetime.minute:
self.bar.datetime = self.bar.datetime.replace(
second=0, microsecond=0
)
self.on_bar(self.bar)
new_minute = True
if new_minute:
self.bar = BarData(
symbol=tick.symbol,
exchange=tick.exchange,
interval=Interval.MINUTE,
datetime=tick.datetime,
gateway_name=tick.gateway_name,
open_price=tick.last_price,
high_price=tick.last_price,
low_price=tick.last_price,
close_price=tick.last_price,
open_interest=tick.open_interest
)
else:
self.bar.high_price = max(self.bar.high_price, tick.last_price)
self.bar.low_price = min(self.bar.low_price, tick.last_price)
self.bar.close_price = tick.last_price
self.bar.open_interest = tick.open_interest
self.bar.datetime = tick.datetime
if self.last_tick:
volume_change = tick.volume - self.last_tick.volume
self.bar.volume += max(volume_change, 0)
self.last_tick = tick
def update_bar(self, bar: BarData):
"""
Update 1 minute bar into generator
"""
# If not inited, creaate window bar object
if not self.window_bar:
# Generate timestamp for bar data
if self.interval == Interval.MINUTE:
dt = bar.datetime.replace(second=0, microsecond=0)
else:
dt = bar.datetime.replace(minute=0, second=0, microsecond=0)
self.window_bar = BarData(
symbol=bar.symbol,
exchange=bar.exchange,
datetime=dt,
gateway_name=bar.gateway_name,
open_price=bar.open_price,
high_price=bar.high_price,
low_price=bar.low_price
)
# Otherwise, update high/low price into window bar
else:
self.window_bar.high_price = max(
self.window_bar.high_price, bar.high_price)
self.window_bar.low_price = min(
self.window_bar.low_price, bar.low_price)
# Update close price/volume into window bar
self.window_bar.close_price = bar.close_price
self.window_bar.volume += int(bar.volume)
self.window_bar.open_interest = bar.open_interest
# Check if window bar completed
finished = False
if self.interval == Interval.MINUTE:
# x-minute bar
if not (bar.datetime.minute + 1) % self.window:
finished = True
elif self.interval == Interval.HOUR:
if self.last_bar and bar.datetime.hour != self.last_bar.datetime.hour:
# 1-hour bar
if self.window == 1:
finished = True
# x-hour bar
else:
self.interval_count += 1
if not self.interval_count % self.window:
finished = True
self.interval_count = 0
if finished:
self.on_window_bar(self.window_bar)
self.window_bar = None
# Cache last bar object
self.last_bar = bar
def generate(self):
"""
Generate the bar data and call callback immediately.
"""
self.bar.datetime = self.bar.datetime.replace(
second=0, microsecond=0
)
self.on_bar(self.bar)
self.bar = None
行情与交易API
traderapi 6.3.15 main.cpp
int main()
{
system("COLOR 0A");
logfile = fopen("syslog.txt", "w");
string g_chFrontaddr = getConfig("config", "FrontAddr");
cout << "g_chFrontaddr = " << g_chFrontaddr << "n" << endl;
CTraderApi *pUserApi = new CTraderApi;//--------------------------
pUserApi->CreateFtdcTraderApi(".flow");
LOG(pUserApi->GetApiVersion());
cout << endl;
CSimpleHandler sh(pUserApi);
cir:pUserApi->RegisterSpi(&sh);
pUserApi->SubscribePrivateTopic(THOST_TERT_QUICK);
pUserApi->SubscribePublicTopic(THOST_TERT_QUICK);
pUserApi->RegisterFront(const_cast<char *>(g_chFrontaddr.c_str()));
pUserApi->Init();
//WaitForSingleObject(g_hEvent, INFINITE);
//_getch();
while (true)
{
LOG("请确定连接模式:n");
LOG("1.直连模式n");
LOG("2.中继服务器操作员模式(一对多模式)n");
LOG("3.中继服务器非操作员模式(多对多模式)n");
int mode_num;
cin >> mode_num;
switch (mode_num)
{
case 1://直连模式
{
sh.ReqAuthenticate();
WaitForSingleObject(g_hEvent, INFINITE);
sh.ReqUserLogin();
WaitForSingleObject(g_hEvent, INFINITE);
break;
}
case 2://操作员模式
{
sh.ReqAuthenticate();
WaitForSingleObject(g_hEvent, INFINITE);
sh.ReqUserLogin();
WaitForSingleObject(g_hEvent, INFINITE);
sh.SubmitUserSystemInfo();
break;
}
case 3://非操作员模式
{
sh.ReqAuthenticate();
WaitForSingleObject(g_hEvent, INFINITE);
sh.RegisterUserSystemInfo();
sh.ReqUserLogin();
WaitForSingleObject(g_hEvent, INFINITE);
break;
}
default:
LOG("选择的模式有误,请重新输入!n");
_getch();
system("cls");
}
break;
}
_getch();
LOG("日期:");
LOG(pUserApi->GetTradingDay());
cout << endl;
while (true)
{
loop:int input1;
system("cls");
LOG("201.上报用户终端信息n");
LOG("110,交易查询合约行情收行情n");
LOG("101.用户登录请求n");
LOG("102.客户端认证n");
LOG("103.请求登出n");
LOG("1.结算单确认请求n");
LOG("2.用户口令更新请求n");
LOG("3.资金账户口令更新请求n");
LOG("/////////////报单////////////n");
LOG("4.报单模块n");
LOG("////////////查询/////////////n");
LOG("5.查询模块n");
LOG("/////////////行权&做市商////////////n");
LOG("6.行权&做市商n");
LOG("///////////出入金/////////////n");
LOG("7.转账指令n");
LOG("///////////铜期权测试////////////n");
LOG("8.铜期权测试n");
LOG("9.版本6.3.13新加接口n");
LOG("0.清空界面n");
LOG("100.退出程序n");
LOG("请输入你需要的操作序号:");
cin >> input1;
switch (input1)
{
case 201:
{
sh.SubmitUserSystemInfo();
_getch();
break;
}
case 110:
{
string g_chFrontMdaddr = getConfig("config", "FrontMdAddr");
cout << "g_chFrontMdaddr = " << g_chFrontMdaddr << "n" << endl;
CThostFtdcMdApi *pUserMdApi =
CThostFtdcMdApi::CreateFtdcMdApi(".liu");
CSimpleMdHandler ash(pUserMdApi);
pUserMdApi->RegisterSpi(&ash);
pUserMdApi->RegisterFront(const_cast<char *>(g_chFrontMdaddr.c_str()));
pUserMdApi->Init();
WaitForSingleObject(xinhao, INFINITE);
sh.ReqQryInstrument();//查询合约
WaitForSingleObject(xinhao, INFINITE);
ash.SubscribeMarketData();//订阅行情
_getch();
pUserMdApi->Release();
break;
}
case 101:
{
sh.ReqUserLogin();
_getch();
break;
}
case 102:
{
sh.ReqAuthenticate();
_getch();
break;
}
case 103:
{
sh.ReqUserLogout();
_getch();
goto cir;
}
case 1://结算单确认请求
{
sh.ReqSettlementInfoConfirm();//结算单确认请求
WaitForSingleObject(g_hEvent, INFINITE);
_getch();
system("cls");
break;
}
case 2://用户口令更新请求
{
sh.ReqUserPasswordUpdate();//用户口令更新请求
WaitForSingleObject(g_hEvent, INFINITE);
_getch();
system("cls");
break;
}
case 3://资金账户口令更新请求
{
sh.ReqTradingAccountPasswordUpdate();//资金账户口令更新请求
WaitForSingleObject(g_hEvent, INFINITE);
_getch();
system("cls");
break;
}
case 4://报单录入请求
{
orderinsert:system("cls");
int orderinsert_num;
LOG("4.报入一笔立即单n");
LOG("5.撤销上一笔报单n");
LOG("6.报入预埋单-限价单立即单n");
LOG("7.撤销预埋单-(上一个预埋单)n");
LOG("8.报入预埋撤单n");
LOG("9.撤销预埋撤单-(上一个预埋撤单)n");
LOG("10.报入条件单n");
LOG("11.撤销条件单-(上一个条件单)n");
LOG("25.大商所止损单n");
LOG("26.大商所止盈单n");
LOG("27.FOK全成全撤n");
LOG("28.FAK部成部撤n");
LOG("29.市价单n");
LOG("30.套利指令n");
LOG("31.互换单n");
LOG("0.返回上一层n");
cin >> orderinsert_num;
switch (orderinsert_num)
{
case 0:
goto loop;
case 4://报入普通立即单
{
int frequence = 0;
LOG("请输入报单频率:n");
cin >> frequence;
//sh.ReqOrderInsert_Ordinary();//报入普通立即单
//_getch();
//break;
for (int a = 0; a < frequence; a++)
{
sh.ReqOrderInsert_Ordinary();
}
}
case 5://撤销上一笔报单
{
sh.ReqOrderAction_Ordinary();//撤销上一笔报单
_getch();
break;
}
case 6://报入预埋单
{
sh.ReqParkedOrderInsert();//报入预埋单
_getch();
break;
}
case 7://删除预埋单
{
sh.ReqRemoveParkedOrder();//删除预埋单
_getch();
break;
}
case 8://报入预埋撤单
{
sh.ReqParkedOrderAction();//报入预埋撤单
_getch();
break;
}
case 9://删除预埋单撤单
{
sh.ReqRemoveParkedOrderAction();//删除预埋单撤单
_getch();
break;
}
case 10://报入条件单
{
it:LOG("1.最新价大于条件价n");
LOG("2.最新价大于等于条件价n");
LOG("3.最新价小于条件价n");
LOG("4.最新价小于等于条件价n");
LOG("5.卖一价大于条件价n");
LOG("6.卖一价大于等于条件价n");
LOG("7.卖一价小于条件价n");
LOG("8.卖一价小于等于条件价n");
LOG("9.买一价大于条件价n");
LOG("10.买一价大于等于条件价n");
LOG("11.买一价小于条件价n");
LOG("12.买一价小于等于条件价n");
LOG("13.返回上一层n");
LOG("请输入你需要报入的条件单类型:n");
int num;
cin >> num;
if (num < 1 || num>13)
{
LOG("输入的序号有误,请重新输入.n");
_getch();
goto it;
}
else if (num == 13)
{
goto orderinsert;
}
else
{
sh.ReqOrderInsert_Condition(num);//报入条件单
_getch();
break;
}
}
case 11://报入条件单撤单
{
sh.ReqOrderAction_Condition();//报入条件单撤单
_getch();
break;
}
case 25://大商所止损单
{
sh.ReqOrderInsert_Touch();
_getch();
break;
}
case 26://大商所止盈单
{
sh.ReqOrderInsert_TouchProfit();
_getch();
break;
}
case 27://FOK全成全撤
{
sh.ReqOrderInsert_VC_CV();
_getch();
break;
}
case 28://FAK部成部撤
{
sh.ReqOrderInsert_VC_AV();
_getch();
break;
}
case 29://市价单
{
sh.ReqOrderInsert_AnyPrice();
_getch();
break;
}
case 30://套利指令
{
sh.ReqOrderInsert_Arbitrage();
_getch();
break;
}
case 31://互换单
{
sh.ReqOrderInsert_IsSwapOrder();
_getch();
break;
}
default:
LOG("请输入正确的序号n");
_getch();
goto orderinsert;
}
goto orderinsert;
}
case 5://查询界面
{
search:system("cls");
int choose_num;
LOG("11.查询成交n");
LOG("12.查询预埋单n");
LOG("13.查询预埋撤单n");
LOG("14.查询报单n");
LOG("15.撤单对应查询编号n");
LOG("16.请求查询资金账户n");//ReqQryTradingAccount
LOG("17.请求查询投资者持仓n");//ReqQryInvestorPosition
LOG("18.请求查询投资者持仓明细n");//ReqQryInvestorPositionDetail
LOG("19.请求查询交易所保证金率n");//ReqQryExchangeMarginRate
LOG("20.请求查询合约保证金率n");//ReqQryInstrumentMarginRate
LOG("21.请求查询合约手续费率n");//ReqQryInstrumentCommissionRate
LOG("22.请求查询做市商合约手续费率n");//ReqQryMMInstrumentCommissionRate
LOG("23.请求查询做市商期权合约手续费n"); //ReqQryMMOptionInstrCommRate
LOG("24.请求查询报单手续费n");//ReqQryInstrumentOrderCommRate
LOG("25.请求查询期权合约手续费n");//ReqQryOptionInstrCommRate
LOG("26.请求查询合约n");//ReqQryInstrument
LOG("27.请求查询投资者结算结果n");//ReqQrySettlementInfo
LOG("28.请求查询转帐流水n");//ReqQryTransferSerial
LOG("29.请求查询询价n");
LOG("30.请求查询报价n");
LOG("31.请求查询执行宣告n");
LOG("32.请求查询转帐银行n");
LOG("33.请求查询交易通知n");
LOG("34.请求查询交易编码n");
LOG("35.请求查询结算信息确认n");
LOG("36.请求查询产品组n");
LOG("37.请求查询投资者单元n");
LOG("38.期货发起查询银行余额请求n");
LOG("39.请求查询经纪公司交易参数n");
LOG("0.返回上一层n");
LOG("请输入选择的序号:n");
cin >> choose_num;
switch (choose_num)
{
case 11://请求查询成交
{
sh.ReqQryTrade();//请求查询成交
_getch();
break;
}
case 12://请求查询服务器预埋单
壯陽藥
{
sh.ReqQryParkedOrder();//请求查询服务器预埋单
_getch();
break;
}
case 13://请求查询服务器预埋撤单
{
sh.ReqQryParkedOrderAction();//请求查询服务器预埋撤单
_getch();
break;
}
case 14://请求查询报单
{
sh.ReqQryOrder();//请求查询报单
_getch();
break;
}
case 15://撤销查询的报单回报
{
action:int action_num;
LOG("请输入需要撤单的序号:n");
cin >> action_num;
LOG("%dn", action_num);
if (action_num < 1 || action_num > vector_OrderSysID.size())
{
LOG("输入的序号有误,请重新输入.n");
_getch();
goto action;
}
sh.ReqOrderAction_forqry(action_num);//撤销查询的报单回报
_getch();
break;
}
case 16://请求查询资金账户
{
sh.ReqQryTradingAccount();//请求查询资金账户
_getch();
break;
}
case 17://请求查询投资者持仓
{
sh.ReqQryInvestorPosition();//请求查询投资者持仓
_getch();
break;
}
case 18://请求查询投资者持仓明细
{
sh.ReqQryInvestorPositionDetail();//请求查询投资者持仓明细
_getch();
break;
}
case 19://请求查询交易所保证金率
{
sh.ReqQryExchangeMarginRate();//请求查询交易所保证金率
_getch();
break;
}
case 20://请求查询合约保证金率
{
sh.ReqQryInstrumentMarginRate();//请求查询合约保证金率
_getch();
break;
}
case 21://请求查询合约手续费率
{
sh.ReqQryInstrumentCommissionRate();//请求查询合约手续费率
_getch();
break;
}
case 22://请求查询做市商合约手续费率
{
sh.ReqQryMMInstrumentCommissionRate();//请求查询做市商合约手续费率
_getch();
break;
}
case 23://请求查询做市商期权合约手续费
{
sh.ReqQryMMOptionInstrCommRate();//请求查询做市商合约手续费率
_getch();
break;
}
case 24://请求查询报单手续费
{
sh.ReqQryInstrumentOrderCommRate();//请求查询报单手续费
_getch();
break;
}
case 25://请求查询期权合约手续费
{
sh.ReqQryOptionInstrCommRate();//请求查询期权合约手续费
_getch();
break;
}
case 26://请求查询合约
{
sh.ReqQryInstrument();//请求查询合约
_getch();
break;
}
case 27://请求查询投资者结算结果
{
sh.ReqQrySettlementInfo();//请求查询投资者结算结果
_getch();
break;
}
case 28://请求查询转帐流水
{
sh.ReqQryTransferSerial();//请求查询投资者结算结果
_getch();
break;
}
case 29://请求查询询价
{
sh.ReqQryForQuote();//请求查询询价
_getch();
break;
}
case 30://请求查询报价
{
sh.ReqQryQuote();//请求查询报价
_getch();
break;
}
case 31://请求查询执行宣告
{
sh.ReqQryExecOrder();//请求查询执行宣告
_getch();
break;
}
case 32://请求查询转帐银行
{
sh.ReqQryTransferBank();
_getch();
break;
}
case 33://请求查询交易通知
{
sh.ReqQryTradingNotice();
_getch();
break;
}
case 34://请求查询交易编码
{
sh.ReqQryTradingCode();
_getch();
break;
}
case 35://请求查询结算信息确认
{
sh.ReqQrySettlementInfoConfirm();
_getch();
break;
}
case 36://请求查询产品组
{
sh.ReqQryProductGroup();
_getch();
break;
}
case 37://请求查询投资者单元
{
sh.ReqQryInvestUnit();
_getch();
break;
}
case 38://期货发起查询银行余额请求
{
sh.ReqQueryBankAccountMoneyByFuture();
_getch();
break;
}
case 39://请求查询经纪公司交易参数
{
sh.ReqQryBrokerTradingParams();
_getch();
break;
}
case 0:
{
goto loop;
}
default: {
LOG("请输入正确的序号n");
_getch();
goto search;
}
}
goto search;
}
case 6://行权&做市商
{
Exec:system("cls");
int num_xingquan;
LOG("32.执行宣告录入请求n");
LOG("33.执行宣告操作请求n");
LOG("34.放弃行权n");
LOG("35.询价录入请求n");
LOG("36.做市商报价录入请求n");
LOG("37.做市商报价撤销请求n");
LOG("0.返回上一层")
LOG("请选择你需要的编码");
cin >> num_xingquan;
switch (num_xingquan)
{
case 32://执行宣告录入请求
{
sh.ReqExecOrderInsert(0);
_getch();
break;
}
case 33://执行宣告操作请求
{
sh.ReqExecOrderAction();
_getch();
break;
}
case 34://放弃行权
{
sh.ReqExecOrderInsert(1);
_getch();
break;
}
case 35://询价录入请求
{
string g_chFrontMdaddr = getConfig("config", "FrontMdAddr");
cout << "g_chFrontMdaddr = " << g_chFrontMdaddr << "n" << endl;
CThostFtdcMdApi *pUserMdApi =
CThostFtdcMdApi::CreateFtdcMdApi();
CSimpleMdHandler ash(pUserMdApi);
pUserMdApi->RegisterSpi(&ash);
pUserMdApi->RegisterFront(const_cast<char *>(g_chFrontMdaddr.c_str()));
pUserMdApi->Init();
WaitForSingleObject(xinhao, INFINITE);
ash.SubscribeMarketData();//行情订阅询价请求
sh.ReqForQuoteInsert();//交易请求询价
_getch();
pUserMdApi->Release();
break;
}
case 36://做市商报价录入请求
{
sh.ReqQuoteInsert();
_getch();
break;
}
case 37://做市商报价撤销请求
{
sh.ReqQuoteAction();
_getch();
break;
}
case 0:
{
goto loop;
}
default:
LOG("输入的编码有误,请重新输入n");
_getch();
//goto Exec;
}
goto Exec;
}
case 7://期货资金转账
{
futrue:system("cls");
int num_future;
LOG("38.期货发起银行资金转期货请求n");
LOG("39.期货发起期货资金转银行请求n");
LOG("0.返回上一层n");
LOG("请输入你需要的操作序号:");
cin >> num_future;
switch (num_future)
{
case 38://期货发起银行资金转期货请求
{
sh.ReqFromBankToFutureByFuture();
_getch();
break;
}
case 39://期货发起期货资金转银行请求
{
sh.ReqFromFutureToBankByFuture();
_getch();
break;
}
case 0:
{
goto loop;
}
default:
LOG("输入的编码有误,请重新输入n");
_getch();
//goto futrue;
}
goto futrue;
}
case 8://铜期权测试
{
qiquan:system("cls");
int num_qiquan;
LOG("//////////////铜期权测试////////////n");
LOG("1.期权自对冲录入请求n");
LOG("2.期权自对冲操作请求n");
LOG("3.请求查询期权自对冲n");
LOG("0.返回上一层n");
LOG("请选择你需要的编码:n");
cin >> num_qiquan;
switch (num_qiquan)
{
case 1:
{
sh.ReqOptionSelfCloseInsert();
_getch();
break;
}
case 2:
{
sh.ReqOptionSelfCloseAction();
_getch();
break;
}
case 3:
{
sh.ReqQryOptionSelfClose();
_getch();
break;
}
case 0:
goto loop;
break;
default:
LOG("输入的序号有误,请重新输入。nn");
_getch();
goto qiquan;
}
goto qiquan;
}
case 9://版本6.3.13新加接口
{
NewVersion:
system("cls");
int num_Newversion;
LOG("新版本测试n");
LOG("1.查询用户当前支持的认证模式(目前暂不启用)n");
LOG("2.用户发出获取图形验证码请求(目前暂不启用)n");
LOG("3.用户发出获取短信验证码请求(目前暂不启用)n");
LOG("4.用户发出带有图片验证码的登陆请求(目前暂不启用)n");
LOG("5.用户发出带有短信验证码的登陆请求(目前暂不启用)n");
LOG("6.用户发出带有动态口令的登陆请求(目前暂不启用)n");
LOG("0.返回上一层n");
LOG("请选择你需要的编码:n");
cin >> num_Newversion;
switch (num_Newversion)
{
case 1://查询用户当前支持的认证模式
{
sh.ReqUserAuthMethod();
_getch();
break;
}
case 2://用户发出获取图形验证码请求
{
sh.ReqGenUserCaptcha();
_getch();
break;
}
case 3://用户发出获取短信验证码请求
{
sh.ReqGenUserText();
_getch();
break;
}
case 4://用户发出带有图片验证码的登陆请求
{
sh.ReqUserLoginWithCaptcha();
_getch();
break;
}
case 5://用户发出带有短信验证码的登陆请求
{
sh.ReqUserLoginWithText();
_getch();
break;
}
case 6://用户发出带有动态口令的登陆请求
{
sh.ReqUserLoginWithOTP();
_getch();
break;
}
case 0:
goto loop;
break;
default:
LOG("输入的序号有误,请重新输入。nn");
_getch();
goto NewVersion;
}
goto NewVersion;
}
case 0:
system("cls");
break;
case 100:
pUserApi->Release();
exit(-1);
}
}
return 0;
}