The resource loading... loading...

exchange.SetData

The exchange.SetData() function is used to set the data loaded when the strategy is running.

The length of the string after parameter value JSON encoding. number

exchange.SetData(key, value)

The name of the data collection. key true string The data to be loaded by the exchange.SetData() function has a data structure of an array. The data structure is the same as the data format requested by the exchange.GetData() function when requesting external data, i.e.: "schema": ["time", "data"]. value true array

/*backtest
start: 2020-01-21 00:00:00
end: 2020-02-12 00:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Bitfinex","currency":"BTC_USD"}]
*/
function main() {
    var data = [
        [1579536000000, "abc"],
        [1579622400000, 123],
        [1579708800000, {"price": 123}],
        [1579795200000, ["abc", 123, {"price": 123}]]
    ]
    exchange.SetData("test", data)
    while(true) {
        Log(exchange.GetData("test"))
        Sleep(1000)
    }
}
'''backtest
start: 2020-01-21 00:00:00
end: 2020-02-12 00:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Bitfinex","currency":"BTC_USD"}]
'''              

def main():
    data = [
        [1579536000000, "abc"],
        [1579622400000, 123],
        [1579708800000, {"price": 123}],
        [1579795200000, ["abc", 123, {"price": 123}]]
    ]
    exchange.SetData("test", data)
    while True:
        Log(exchange.GetData("test"))
        Sleep(1000)
/*backtest
start: 2020-01-21 00:00:00
end: 2020-02-12 00:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Bitfinex","currency":"BTC_USD"}]
*/              

void main() {
    json data = R"([
        [1579536000000, "abc"],
        [1579622400000, 123],
        [1579708800000, {"price": 123}],
        [1579795200000, ["abc", 123, {"price": 123}]]
    ])"_json;
    
    exchange.SetData("test", data);
    while(true) {
        Log(exchange.GetData("test"));
        Sleep(1000);
    }
}

It requires that the data for the parameter value be in the same format as the data variable in the following example. You can see that the timestamp 1579622400000 corresponds to the time 2020-01-22 00:00:00, and that when the strategy program is run after this time, call the exchange.GetData() function to get the data before the next data timestamp 1579708800000, that is, time 2020-01-23 00:00:00. What you get are [1579622400000, 123] the contents of that data, as the program continues to run, the time changes, and so on to get the data item by item. In the following example, at runtime (backtesting or live trading), the current moment reaches or exceeds the timestamp 1579795200000, the exchange.GetData() function is called and the return value is: {"Time":1579795200000,"Data":["abc", 123,{"price":123}]}. "Time":1579795200000 corresponds to 1579795200000 in data [1579795200000, ["abc", 123, {"price": 123}]]. "Data":["abc", 123, {"price": 123}] corresponds to data ["abc", 123, {"price": 123}]] in [1579795200000, ["abc", 123, {"price": 123}]].

The loaded data can be any economic indicators, industry data, relevant indicators, etc., used for strategy quantitative assessment of all quantifiable information.

{@fun/Market/exchange.GetData exchange.GetData}

exchange.GetRate exchange.GetData