Some tips for re-testing the wrong packaging

Author: Zero, Created: 2015-07-20 22:01:59, Updated: 2015-07-20 22:06:32

An error caused by an exchange network can cause a function call such as exchange.GetAccount to fail, at which point it is necessary to try again, but the code that appears once for each function is too annoying to lock.

This function is placed at the beginning.

function EnsureCall(method) {
    var r;
    while (!(r = method.apply(this, Array.prototype.slice.call(arguments).slice(1)))) {
        Sleep(300);
    }
    return r;
}```
然后比如获取账户信息可以这样
```var account = EnsureCall(exchange.GetAccount);```
获取深度可以这样
```var depth = EnsureCall(exchange.GetDepth);```
要传入参数可以这样
```var records = EnsureCall(exchange.GetRecords, PERIOD_M5);```
这样以来,不管交易所网络如何不稳定, EnsureCall会重试得到的都是有效的数据, 不用每个函数都为了容错封装一次了.

当然你也可以把EnsureCall改名为EC或者Call之类好记又短的名子, 这样更方便.

More

simple-chunIs there a PY version of this?

solorezfunction EnsureCall ((method) { I'm not sure. while (!(r = method.apply(this, Array.prototype.slice.call ((arguments).slice))) { Sleep ((300); I'm not sure. and return r; I'm not sure. function main (() { InitAccount = EnsureCall ((exchange.GetAccount))); Log (InitAccount); I'm not sure. This is the first time I have ever seen an error like the one above.

solorezI think it's best to take this into consideration when you do the next API.

solorezDid God test it? Why did I get this error when I used it: This is a list of all the different ways Dn-filebox.qbox.me/bdfed9d5bfd320ceaa06732c84ef0dd1662dc3f8.png is credited in the database.

Zero```EnsureCall ((exchange.GetAccount) ``GetAccount does not need to be added after (((