_C
Retry function for interface fault tolerance handling.
_C(pfn)
_C(pfn, ...args)Examples
-
For fault tolerance of functions without parameters:
javascriptfunction main(){ var ticker = _C(exchange.GetTicker) // Adjust the retry interval of _C() function to 2 seconds _CDelay(2000) var depth = _C(exchange.GetDepth) Log(ticker) Log(depth) }pythondef main(): ticker = _C(exchange.GetTicker) _CDelay(2000) depth = _C(exchange.GetDepth) Log(ticker) Log(depth)c++void main() { auto ticker = _C(exchange.GetTicker); _CDelay(2000); auto depth = _C(exchange.GetDepth); Log(ticker); Log(depth); } -
For fault tolerance of functions with parameters:
javascriptfunction main(){ var records = _C(exchange.GetRecords, PERIOD_D1) Log(records) }pythondef main(): records = _C(exchange.GetRecords, PERIOD_D1) Log(records)c++void main() { auto records = _C(exchange.GetRecords, PERIOD_D1); Log(records); } -
Can also be used for fault tolerance handling of custom functions:
javascriptvar test = function(a, b){ var time = new Date().getTime() / 1000 if(time % b == 3){ Log("Condition met!", "#FF0000") return true } Log("Retrying!", "#FF0000") return false } function main(){ var ret = _C(test, 1, 5) Log(ret) }pythonimport time def test(a, b): ts = time.time() if ts % b == 3: Log("Condition met!", "#FF0000") return True Log("Retrying!", "#FF0000") return False def main(): ret = _C(test, 1, 5) Log(ret)c++// C++ does not support this method for custom function fault tolerance
Returns
| Type | Description |
All platform-supported types except false values and null values (any). | The return value when the callback function is executed. |
Arguments
| Name | Type | Required | Description |
pfn | function | Yes | The parameter |
arg | string / number / bool / object / array / function / any (any type supported by the platform) | No | Parameters for the callback function. There may be multiple |
Remarks
The _C() function will continuously call the specified function until it returns successfully (it will retry calling pfn when the function referenced by parameter pfn returns null or false).
For example _C(exchange.GetTicker). The default retry interval is 3 seconds. You can call the _CDelay() function to set the retry interval.
For example _CDelay(1000) means changing the retry interval of the _C() function to 1 second.
The following functions can be (but are not limited to) handled for fault tolerance:
exchange.GetTicker()exchange.GetDepth()exchange.GetTrades()exchange.GetRecords()exchange.GetAccount()exchange.GetOrders()exchange.GetOrder()exchange.GetPositions()
All the above functions can be called through the _C() function to achieve fault tolerance. The _C() function is not limited to fault tolerance for the above functions. The parameter pfn is a function reference, not a function call. Note that you should use _C(exchange.GetTicker) instead of _C(exchange.GetTicker()).