策略程序的一般架构、一个策略框架
策略的一般架构
在发明者量化教程 2.6 期货 章节 我们已经初步使用了CTP商品期货常用的程序架构(轮询式)
function MainLoop(){ // 处理具体工作的函数
// deal Main task
}
function main() {
var status = null;
while(true){
status = exchange.IO("status"); // 调用API 确定连接状态
if(status === true){ // 判断状态
LogStatus("已连接!");
MainLoop(); // 连接上 交易所服务器后,执行主要工作函数。
}else{ // 如果没有连接上 即 exchange.IO("status") 函数返回 false
LogStatus("未连接状态!"); // 在状态栏显示 未连接状态。
}
Sleep(1000); // 需要有轮询间隔, 以免访问过于频繁。
}
}
那么数字货币策略的一般架构是什么样的呢? 同样是轮询方式的,其实比商品期货的更加简单:
//other functions
function f1(){
//...
}