Type/to search
Built-in Functions
Global
Log
Market
exchange.GetTicker
exchange.GetTickers
exchange.GetDepth
exchange.GetTrades
exchange.GetRecords
exchange.GetMarkets
exchange.GetRawJSON
exchange.SetData
exchange.GetData
Trade
Account
Futures
Exchange
IO
Network
Storage
Threads
TA
Talib
OS
Structures
Built-in Variables and Constants
Conventions
Exchanges

Sets the data loaded when the strategy is running.

exchange.SetData(key, value)

Examples

The data format required by the value parameter is like the data variable in the following example. As you can see, the timestamp 1579622400000 corresponds to the time 2020-01-22 00:00:00. When the running time of the strategy program exceeds this time and is before the timestamp 1579708800000 of the next data entry (i.e. the time 2020-01-23 00:00:00), calling the exchange.GetData() function will always retrieve the content of this data entry [1579622400000, 123]. As the program continues to run and time passes, and so on, the data can be retrieved entry by entry.

In the following example, when the current moment of the runtime (backtesting or live trading) reaches or exceeds the timestamp 1579795200000, calling the exchange.GetData() function returns: {"Time":1579795200000,"Data":["abc",123,{"price":123}]}. Here "Time":1579795200000 corresponds to 1579795200000 in the data [1579795200000, ["abc", 123, {"price": 123}]]; "Data":["abc",123,{"price":123}] corresponds to ["abc", 123, {"price": 123}] in the data [1579795200000, ["abc", 123, {"price": 123}]].

javascript
/*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) } }
python
'''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)
rust
/*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"}] */ fn main() { // In the Rust SDK, the data argument of SetData is a JSON string let data = r#"[ [1579536000000, "abc"], [1579622400000, 123], [1579708800000, {"price": 123}], [1579795200000, ["abc", 123, {"price": 123}]] ]"#; exchange.SetData("test", data); loop { Log!(exchange.GetData("test")); Sleep(1000); } }

Returns

TypeDescription

number

The string length of the value parameter after being JSON-encoded.

Arguments

NameTypeRequiredDescription

key

string

Yes

The name of the data collection.

value

array

Yes

The data to be loaded by the exchange.SetData() function, whose data structure is an array. This data structure is the same as the format required by the exchange.GetData() function when requesting external data, namely: "schema": ["time", "data"].

See Also

Remarks

The loaded data can be any economic indicator, industry data, related index, etc., used to quantitatively evaluate various types of quantifiable information within the strategy.