Playing JavaScript with old people - creating a buyer/seller tool (7) Useful tool to know why!

Author: The Little Dream, Created: 2017-03-16 12:29:51, Updated: 2017-10-11 10:37:54

                                  // 把 AccountToTable 引用传递给 导出函数 (接口)

// Test with the main function function main (() { var p = $.NewPositionManager (); and p.OpenShort ((MA701, 1); p.OpenShort ((MA705, 1); Log ((p.GetPosition ((MA701, PD_SHORT))); Log ((p.GetAccount (())); Log ((p.Account (()); Sleep ((60000 * 10); p.CoverAll (((); and LogProfit ((p.Profit))); Log (($.IsTrading ((MA701))); // Use transaction queues to complete unblocked transaction tasks when multi-varieties var q = $.NewTaskQueue (); q.pushTask ((exchange, MA701, buy, 3, function ((task, ret) { // The last parameter function ((task, ret) {...} is an anonymous function that acts as a callback function for the task object. Log ((task.desc, ret) // In the callback function, a description of the task is output, and the return value of the task completed, which are presets and will not be executed immediately. if (ret) { q.pushTask ((exchange, MA701, closebuy, 1, 123, function ((task, ret) { // In the callback function of the first pressed queue task, the pressed match task to the task queue is used to implement pairing transactions. // triggers a matching operation in the callback function as soon as the first task transaction is completed. Log ((q, task.desc, ret, and task.arg) is the name of the file. It's not. I'm not sure. It's not. while (true) { // Call poll to complete unfinished tasks when idle Q. poll ((() Sleep ((1000) is the name of the I'm not sure. I'm not sure.


- #### 通篇看完,我想你们应该对这个模块有了一定的了解。

这个模块代码分两种 模式:
- 1、单品种的交易模式

  这个只能用于一个品种的商品期货合约的买卖处理,整体流程是线性的。
  
- 2、多品种模拟并发交易模式:

  这个就可以用来做多品种的策略,比如多品种的海龟交易法。(多品种的好处就是分散资金,一定程度上控制风险。)
  
  这个模式的设计思路就是遇到任何错误都不等待重试,马上返回对应的错误码,这样多个任务执行时,虽然程序执行流程还是线性的。但是都已很快的速度执行,不独占过多时间,类似CPU并发机制。并且各个任务都有自身的变量寄存数据结构,在错误返回后再次执行的时候会继续任务的执行直到完成,模拟出并发执行的效果。适合用于多品种策略系统使用(各品种交易在时间序列上的互相影响降至较低程度)。
  
  并且使用了回调函数,在任务完成时可以自动触发一些设计好的代码。
  
  这种思路很值得学习。
  
下一篇,我们会用这些JS代码创造出一个真正的策略。


#### 先写到这,欢迎读者给我留言!提出建议和意见,如果感觉好玩可以分享给更多热爱程序热爱交易的朋友 
https://www.fmz.com/bbs-topic/737

### 程序员 littleDream 原创

More