3.3 The general architecture of the strategic process, a strategic framework

Author: The Little Dream, Created: 2016-11-12 14:36:54, Updated: 2019-08-01 09:23:53

The general architecture of the strategic process, a strategic framework


  • The general structure of the strategy

    In the 2.6 Futures section, we have already used the CTP commodity futures commonly used procedural architecture (inquiry method) in the first instance.

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);                         //  需要有轮询间隔, 以免访问过于频繁。
      }
}

So what is the general architecture of a digital currency strategy? It's also a round-the-clock strategy, but it's actually simpler than a commodity futures strategy:

//other functions
function f1(){
    //...
}
//...
function loop(){
    // do somethings
    f1();
    //...
    //API...
}
function main(){
    //初始化
    //...
    
    while(true){
        loop();
        Sleep(1000);
    }
}

The question is: is the architecture consultative, is there a parallel execution mechanism?
The inventor quantification platform has partially packaged the API to support concurrency mechanisms, as shown below: (see API documentation for more details)

img

  • Simulated multitasking

    Code architecture: (I'm also a cockroach myself, the architecture is to learn Z, if there are errors, please point out)
// 其它函数
function buy(){
    Log("buy");
}
//任务生成器构造函数
function MakeTasksController(){
    var TasksController = {};
    TasksController.tasks = [];  // 任务数组
    TasksController.initTask = function(cmd){ // 初始化要执行的任务参数、设置
        var task = {
            //各种任务 数据
            cmd : 0,     // 命令: 0:waiting , 1: buy 
            state: 0,    // 状态: 0:uncomplete  1: complete
            //...
        };
        task.cmd = cmd;
        //task.XX  初始化
        TasksController.tasks.push(task);   // 存入 任务数组
    };
    TasksController.DealWithTasks = function(){  // 处理  tasks 数组内 储存的task
        _.each(TasksController.tasks, function(task){  // 迭代 执行全部任务
            // 处理任务task ,保存每个任务的状态数据,直到任务完成。在处理任务的具体代码中 不做死循环处理。 
            // 即每个任务不独占时间。下次轮询 读取task 数据继续任务。从而实现模拟多任务模式。 
            // ...
            if(task.cmd === 1){
                buy();
                task.state = 1; // 任务执行完成就调用 赋值语句 给task.state 标记赋值
            }
        });
    };
    TasksController.CheckTask = function(){
        var process = 0;
        _.each(TasksController.tasks, function(task){
            if(task.state === 1){
                // 任务已经完成,弹出完成的任务。
                Log("task.cmd:", task.cmd, "已完成!");
            }else{
                process++;
            }
        });
        if(process === 0){
            TasksController.tasks = [];    // 清空 任务数组
        }
    };
    return TasksController;
}
function main(){
    var tasksController = MakeTasksController();
    var count = 0;
    while(true){
        //触发新建任务,例子。
        if(count === 100){
            tasksController.initTask(1);   //  初始化任务,   buy 任务  即  1 
            //...  初始其它任务。
        }
        //...      
        tasksController.DealWithTasks();  // 处理任务
        tasksController.CheckTask();      // 检查任务处理
        count++;
        Sleep(200);   //  任务很多的时候 可以适当减小 Sleep 的参数值
    }
}
  • How many modules should a complete trading system contain?

    The first is the earnings statistics module. 2, UI interface, data feedback, and status display. 3, the interactive module. 4, Chart Module. 5, Strategic logic (specific trading algorithms) 6, the transaction module. 7, data processing modules.

    A simple strategic framework:A simple strategy framework (which can be modified and extended on your own)

    This strategy framework is basically the same as the previous learning content. All aspects of the code are combined, and if you read the code carefully, you will find it very familiar. It can be run directly, but without writing any triggering code, and can be self-extended. In the next chapter, we're going to expand this strategy framework and make it work.


More

Kevin is not here.This is not only a matter of learning the content, but also the attitude.

wulaStart learning the way, Zan.