量化交易是基于程序化实现的一种策略的运行。需要一个工具来帮助达到目的,这就是接口。
今天来教大家如何使用接口。
下面演示一下,在跑接口返回的数据显示
// 查询各类交易数据
// category: 0=>资金, 1=>股份, 2=>当日委托, 3=>当日成交, 4=>可撤单,
// 5=>股东代码, 6=>融资余额, 7=>融券余额, 8=>可融证券,
// 12=>可申购新股, 13=>新股申购额度, 14=>配号, 15=>中签,
// 16=>未平仓融资合约, 17=>未平仓融券合约, 18=>未平仓两融合约
typedef void (*QueryDataProc)(int clientId, int category, char *result, char *errinfo);
const auto QueryData = reinterpret_cast(GetProcAddress(hDLL, "QueryData"));
assert(QueryData);
std::cout << "========== 查询资金: category = 0 ==========\n";
int category = 0;
QueryData(clientId, category, result, errinfo);
if (NULL != errinfo[0]) {
std::cout << errinfo << std::endl;
} else {
std::cout << result << std::endl;
}
std::cout << std::endl;
std::cout << "========== 查询股份: category = 1 ==========\n";
category = 1;
QueryData(clientId, category, result, errinfo);
if (NULL != errinfo[0]) {
std::cout << errinfo << std::endl;
} else {
std::cout << result << std::endl;
}
std::cout << std::endl;
std::cout << "========== 查询当日委托: category = 2 ==========\n";
category = 2;
QueryData(clientId, category, result, errinfo);
if (NULL != errinfo[0]) {
std::cout << errinfo << std::endl;
} else {
std::cout << result << std::endl;
}
std::cout << std::endl;
下面是委托:
// 委托下单
// category: 0=>买入, 1=>卖出, 2=>融资买入, 3=>融券卖出 4=>买券还券, 5=>卖券还款, 6现券还券
// entrustType: 0=>限价委托(深/沪), 1=>对方最优价(深), 2=>本方最优价(深)
// 3=>即时成交剩余撤销(深), 4=>最优五档剩余撤销(深/沪)
// 5=>全额成交或撤销(深), 6=>最优五档剩余转限(沪)
// gddm: 股东代码, 区分沪/深
// quantity: 股数
typedef void (*SendOrderProc)(int clientId, int category, int entrustType,
const char *gddm, const char *zqdm, float price,
int quantity, char *result, char *errinfo);
const auto SendOrder = reinterpret_cast(GetProcAddress(hDLL, "SendOrder"));
assert(SendOrder);
std::cout << "========== 普通(担保品)买入: category = 0 ==========\n";
category = 0; // 委托类别
int entrustType = 0; // 限价委托
std::string gddm = "1234567890"; // 股东代码(注意区分深圳和上海各自的股东代码)
std::string zqdm = "000001"; // 证券代码
float price = 12.2; // 委托价格
int quantity = 100; // 委托股数
SendOrder(clientId, category, entrustType, gddm.c_str(), zqdm.c_str(), price, quantity, result, errinfo);
if (NULL != errinfo[0]) {
std::cout << errinfo << std::endl;
} else {
std::cout << result << std::endl;
}
std::cout << std::endl;
// 委托撤单
// exchangeId: 0=>深证(东兴证券是A0, 招商证券普通账户是2)
// 1=>上证
typedef void (*CancelOrderProc)(int clientId, const char *exchangeId,
const char *entrustId, char *result,
char *errinfo);
const auto CancelOrder =
reinterpret_cast(GetProcAddress(hDLL, "CancelOrder"));
assert(CancelOrder);
std::cout << "========== 撤单委托 ==========\n";
std::string exchangeId = "1"; // 上海
std::string entrustId = "xxxxxx"; // 委托编号
CancelOrder(clientId, exchangeId.c_str(), entrustId.c_str(), result, errinfo);
if (NULL != errinfo[0]) {
std::cout << errinfo << std::endl;
} else {
std::cout << result << std::endl;
}
std::cout << std::endl;
注意撤单标记对应两市
以上就是实盘交易接口的使用介绍,多种功能完美适用各种策略。对程序化交易来说是不可缺少的。