资源加载中... loading...

exchange.GetData

The exchange.GetData() function is used to get data loaded by the exchange.SetData() function or provided by an external link.

Records in the data collection. object

exchange.GetData(key) exchange.GetData(key, timeout)

The name of the data collection. key true string Used to set the cache timeout in milliseconds. Defaults to a one minute cache timeout for live tradings. timeout false number

/*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() {
    exchange.SetData("test", [[1579536000000, _D(1579536000000)], [1579622400000, _D(1579622400000)], [1579708800000, _D(1579708800000)]])
    while(true) {
        Log(exchange.GetData("test"))
        Sleep(1000 * 60 * 60 * 24)
    }
}
'''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():
    exchange.SetData("test", [[1579536000000, _D(1579536000000/1000)], [1579622400000, _D(1579622400000/1000)], [1579708800000, _D(1579708800000/1000)]])
    while True:
        Log(exchange.GetData("test"))
        Sleep(1000 * 60 * 60 * 24)
/*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 arr = R"([[1579536000000, ""], [1579622400000, ""], [1579708800000, ""]])"_json;
    arr[0][1] = _D(1579536000000);
    arr[1][1] = _D(1579622400000);
    arr[2][1] = _D(1579708800000);
    exchange.SetData("test", arr);
    while(true) {
        Log(exchange.GetData("test"));
        Sleep(1000 * 60 * 60 * 24);
    }
}

The call to get the data written directly.

/*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() {
    while(true) {
        Log(exchange.GetData("http://xxx.xx.x.xx:9090/data"))
        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():
    while True:
        Log(exchange.GetData("http://xxx.xx.x.xx:9090/data"))
        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() {
    while(true) {
        Log(exchange.GetData("http://xxx.xx.x.xx:9090/data"));
        Sleep(1000);
    }
}

It support for requesting data through external links, the format of the data requested to:

{
    "schema":["time","data"],
    "data":[
        [1579536000000, "abc"],
        [1579622400000, 123],
        [1579708800000, {"price": 123}],
        [1579795200000, ["abc", 123, {"price": 123}]]
    ]
}

Where schema is the data format for each record in the body of the loaded data, which is fixed to ["time", "data"] corresponding to the format of the entry-by-entry data in the data attribute. What is stored in the data attribute is the body of the data, with each entry consisting of a millisecond-level timestamp and the data content (which can be any JSON-encodable data). The service program for testing, written in Go:

package main
import (
    "fmt"
    "net/http"
    "encoding/json"
)                

func Handle (w http.ResponseWriter, r *http.Request) {
    defer func() {
        fmt.Println("req:", *r)
        ret := map[string]interface{}{
            "schema": []string{"time","data"},
            "data": []interface{}{
                []interface{}{1579536000000, "abc"},
                []interface{}{1579622400000, 123},
                []interface{}{1579708800000, map[string]interface{}{"price":123}},
                []interface{}{1579795200000, []interface{}{"abc", 123, map[string]interface{}{"price":123}}},
            },
        }
        b, _ := json.Marshal(ret)
        w.Write(b)
    }()
}                

func main () {
    fmt.Println("listen http://localhost:9090")
    http.HandleFunc("/data", Handle)
    http.ListenAndServe(":9090", nil)
}

The program’s response data upon receipt of the request:

{
    "schema":["time","data"],
    "data":[
        [1579536000000, "abc"],
        [1579622400000, 123],
        [1579708800000, {"price": 123}],
        [1579795200000, ["abc", 123, {"price": 123}]]
    ]
}

Test strategy code:

function main() {
    Log(exchange.GetData("http://xxx.xx.x.xx:9090/data"))
    Log(exchange.GetData("https://www.fmz.com/upload/asset/32bf73a69fc12d36e76.json"))
}
def main():
    Log(exchange.GetData("http://xxx.xx.x.xx:9090/data"))
    Log(exchange.GetData("https://www.fmz.com/upload/asset/32bf73a69fc12d36e76.json"))
void main() {
    Log(exchange.GetData("http://xxx.xx.x.xx:9090/data"));
    Log(exchange.GetData("https://www.fmz.com/upload/asset/32bf73a69fc12d36e76.json"));
}

The call method to get the data of an external link.

function main() {
    Log(exchange.GetData("https://www.datadata.com/api/v1/query/xxx/data"))   // The xxx part of the link is the code of the query data, here xxx is an example.
}
def main():
    Log(exchange.GetData("https://www.datadata.com/api/v1/query/xxx/data"))
void main() {
    Log(exchange.GetData("https://www.datadata.com/api/v1/query/xxx/data"));
}

Request data for a query created on the platform datadata, requesting that the data format of the answer be (must have time, data fields described in schema):

{
    "data": [],
    "schema": ["time", "data"]
}

The “data” field is the required data content, and the data in the “data” field needs to be the same as what is agreed in the “schema”. When the exchange.GetData() function is called, a JSON object is returned, e.g.: {"Time":1579795200000, "Data":"..."}.

Get the data at once for backtesting and cache one minute of data for live trading. In the backtesting system, when requesting data using the access interface, the backtesting system automatically adds from (timestamped in seconds), to (timestamped in seconds) to the request, parameters such as period (underlying K-line period, timestamped in milliseconds) are used to determine the time frame over which the data is to be acquired.

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

exchange.SetData exchange.GetMarkets