The resource loading... loading...

_C

Retry function for interface fault tolerance.

The return value of the callback function when it is executed. All types are supported by the system except logical false value and null value.

_C(pfn) _C(pfn, …args)

The parameter pfn is a function reference, which is a callback function. pfn true function Parameters to callback functions, there may be more than one parameter arg. The type and number of parameters arg depends on the parameters of the callback function. arg false string, number, bool, object, array, function, all types are supported by the system, such as null values

function main(){
    var ticker = _C(exchange.GetTicker)
    // Adjust _C() function retry interval to 2 seconds
    _CDelay(2000)
    var depth = _C(exchange.GetDepth)
    Log(ticker)
    Log(depth)
}
def main():
    ticker = _C(exchange.GetTicker)
    _CDelay(2000)
    depth = _C(exchange.GetDepth)
    Log(ticker)
    Log(depth)
void main() {
    auto ticker = _C(exchange.GetTicker);
    _CDelay(2000);
    auto depth = _C(exchange.GetDepth);
    Log(ticker);
    Log(depth);
}

For error-tolerant functions without parameters:

function main(){
    var records = _C(exchange.GetRecords, PERIOD_D1)
    Log(records)
}
def main():
    records = _C(exchange.GetRecords, PERIOD_D1)
    Log(records)
void main() {
    auto records = _C(exchange.GetRecords, PERIOD_D1);
    Log(records);
}

For functions with parameters that are error tolerant:

var test = function(a, b){
    var time = new Date().getTime() / 1000
    if(time % b == 3){
        Log("Eligible!", "#FF0000")
        return true
    }
    Log("Retry!", "#FF0000")
    return false
}            

function main(){
    var ret = _C(test, 1, 5)
    Log(ret)
}
import time
def test(a, b):
    ts = time.time()
    if ts % b == 3:
        Log("Eligible!", "#FF0000")
        return True
    Log("Retry!", "#FF0000")
    return False            

def main():
    ret = _C(test, 1, 5)
    Log(ret)
// C++ does not support fault tolerance for custom functions in this way

It can also be used for fault tolerance of custom functions:

The _C() function will keep calling the specified function until it returns successfully (the function referenced by the parameter pfn returns null or false when called will retry calling pfn). 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 to change the retry interval of the _C() function to 1 second. Fault tolerance can be done for, but is not limited to, the following functions:

  • exchange.GetTicker()
  • exchange.GetDepth()
  • exchange.GetTrades()
  • exchange.GetRecords()
  • exchange.GetAccount()
  • exchange.GetOrders()
  • exchange.GetOrder()
  • exchange.GetPositions() All can be called by the _C() function for fault tolerance. The _C() function is not limited to the above listed function fault tolerance, the parameter pfn is a function reference rather than a function call. Note that it is _C(exchange.GetTicker), not _C(exchange.GetTicker()).
_N _Cross