Type/to search
Built-in Functions
Global
Version
Sleep
IsVirtual
Mail
Mail_Go
SetErrorFilter
GetPid
GetLastError
GetCommand
GetMeta
Dial
HttpQuery
HttpQuery_Go
Encode
UnixNano
Unix
GetOS
MD5
DBExec
UUID
EventLoop
__Serve
_G
_D
_N
_C
_Cross
JSON.parse
JSON.stringify
SetChannelData
GetChannelData
Log
Market
Trade
Account
Futures
NetSettings
Threads
threading
Thread
getThread
mainThread
currentThread
Lock
Condition
Event
Dict
pending
Thread
ThreadLock
ThreadEvent
ThreadCondition
ThreadDict
Web3
TA
Talib
talib.CDL2CROWS
talib.CDL3BLACKCROWS
talib.CDL3INSIDE
talib.CDL3LINESTRIKE
talib.CDL3OUTSIDE
talib.CDL3STARSINSOUTH
talib.CDL3WHITESOLDIERS
talib.CDLABANDONEDBABY
talib.CDLADVANCEBLOCK
talib.CDLBELTHOLD
talib.CDLBREAKAWAY
talib.CDLCLOSINGMARUBOZU
talib.CDLCONCEALBABYSWALL
talib.CDLCOUNTERATTACK
talib.CDLDARKCLOUDCOVER
talib.CDLDOJI
talib.CDLDOJISTAR
talib.CDLDRAGONFLYDOJI
talib.CDLENGULFING
talib.CDLEVENINGDOJISTAR
talib.CDLEVENINGSTAR
talib.CDLGAPSIDESIDEWHITE
talib.CDLGRAVESTONEDOJI
talib.CDLHAMMER
talib.CDLHANGINGMAN
talib.CDLHARAMI
talib.CDLHARAMICROSS
talib.CDLHIGHWAVE
talib.CDLHIKKAKE
talib.CDLHIKKAKEMOD
talib.CDLHOMINGPIGEON
talib.CDLIDENTICAL3CROWS
talib.CDLINNECK
talib.CDLINVERTEDHAMMER
talib.CDLKICKING
talib.CDLKICKINGBYLENGTH
talib.CDLLADDERBOTTOM
talib.CDLLONGLEGGEDDOJI
talib.CDLLONGLINE
talib.CDLMARUBOZU
talib.CDLMATCHINGLOW
talib.CDLMATHOLD
talib.CDLMORNINGDOJISTAR
talib.CDLMORNINGSTAR
talib.CDLONNECK
talib.CDLPIERCING
talib.CDLRICKSHAWMAN
talib.CDLRISEFALL3METHODS
talib.CDLSEPARATINGLINES
talib.CDLSHOOTINGSTAR
talib.CDLSHORTLINE
talib.CDLSPINNINGTOP
talib.CDLSTALLEDPATTERN
talib.CDLSTICKSANDWICH
talib.CDLTAKURI
talib.CDLTASUKIGAP
talib.CDLTHRUSTING
talib.CDLTRISTAR
talib.CDLUNIQUE3RIVER
talib.CDLUPSIDEGAP2CROWS
talib.CDLXSIDEGAP3METHODS
talib.AD
talib.ADOSC
talib.OBV
talib.ACOS
talib.ASIN
talib.ATAN
talib.CEIL
talib.COS
talib.COSH
talib.EXP
talib.FLOOR
talib.LN
talib.LOG10
talib.SIN
talib.SINH
talib.SQRT
talib.TAN
talib.TANH
talib.MAX
talib.MAXINDEX
talib.MIN
talib.MININDEX
talib.MINMAX
talib.MINMAXINDEX
talib.SUM
talib.HT_DCPERIOD
talib.HT_DCPHASE
talib.HT_PHASOR
talib.HT_SINE
talib.HT_TRENDMODE
talib.ATR
talib.NATR
talib.TRANGE
talib.BBANDS
talib.DEMA
talib.EMA
talib.HT_TRENDLINE
talib.KAMA
talib.MA
talib.MAMA
talib.MIDPOINT
talib.MIDPRICE
talib.SAR
talib.SAREXT
talib.SMA
talib.T3
talib.TEMA
talib.TRIMA
talib.WMA
talib.LINEARREG
talib.LINEARREG_ANGLE
talib.LINEARREG_INTERCEPT
talib.LINEARREG_SLOPE
talib.STDDEV
talib.TSF
talib.VAR
talib.ADX
talib.ADXR
talib.APO
talib.AROON
talib.AROONOSC
talib.BOP
talib.CCI
talib.CMO
talib.DX
talib.MACD
talib.MACDEXT
talib.MACDFIX
talib.MFI
talib.MINUS_DI
talib.MINUS_DM
talib.MOM
talib.PLUS_DI
talib.PLUS_DM
talib.PPO
talib.ROC
talib.ROCP
talib.ROCR
talib.ROCR100
talib.RSI
talib.STOCH
talib.STOCHF
talib.STOCHRSI
talib.TRIX
talib.ULTOSC
talib.WILLR
talib.AVGPRICE
talib.MEDPRICE
talib.TYPPRICE
talib.WCLPRICE
OS
Structures
Built-in Variables

Get the Record structure array (i.e. K-line data) of the spot or contract corresponding to the currently set trading pair or contract code.

exchange.GetRecords()
exchange.GetRecords(symbol)
exchange.GetRecords(symbol, period)
exchange.GetRecords(symbol, period, limit)
exchange.GetRecords(period)
exchange.GetRecords(period, limit)

Examples

  • Get K-line data for a custom period.

    javascript
    function main() { // Print K-line data with a K-line period of 120 seconds (2 minutes) Log(exchange.GetRecords(60 * 2)) // Print K-line data with a K-line period of 5 minutes Log(exchange.GetRecords(PERIOD_M5)) }
    python
    def main(): Log(exchange.GetRecords(60 * 2)) Log(exchange.GetRecords(PERIOD_M5))
    rust
    fn main() { // Print K-line data with a K-line period of 120 seconds (2 minutes) Log!(exchange.GetRecords(None, 60 * 2, None)); // Print K-line data with a K-line period of 5 minutes Log!(exchange.GetRecords(None, PERIOD_M5, None)); }
    c++
    void main() { Log(exchange.GetRecords(60 * 2)[0]); Log(exchange.GetRecords(PERIOD_M5)[0]); }
  • Output K-line bar data:

    javascript
    function main() { var records = exchange.GetRecords(PERIOD_H1) /* Due to network reasons, it may not be possible to access the exchange interface (even if the device running the docker program can open the exchange website, the API interface may still be inaccessible) In this case, records is null, and accessing records[0].Time will cause an error. Therefore, when testing this code, please make sure you can access the exchange interface normally */ Log("First K-line data: Time:", records[0].Time, "Open:", records[0].Open, "High:", records[0].High) Log("Second K-line data: Time:", records[1].Time ,"Close:", records[1].Close) Log("Current K-line (latest)", records[records.length-1], "Previous K-line", records[records.length-2]) }
    python
    def main(): records = exchange.GetRecords(PERIOD_H1) Log("First K-line data: Time:", records[0]["Time"], "Open:", records[0]["Open"], "High:", records[0]["High"]) Log("Second K-line data: Time:", records[1]["Time"], "Close:", records[1]["Close"]) Log("Current K-line (latest)", records[-1], "Previous K-line", records[-2])
    rust
    fn main() { let records = exchange.GetRecords(None, PERIOD_H1, None).unwrap(); Log!("First K-line data: Time:", records[0].Time, "Open:", records[0].Open, "High:", records[0].High); Log!("Second K-line data: Time:", records[1].Time, "Close:", records[1].Close); Log!("Current K-line (latest)", records[records.len() - 1], "Previous K-line", records[records.len() - 2]); }
    c++
    void main() { auto records = exchange.GetRecords(PERIOD_H1); Log("First K-line data: Time:", records[0].Time, "Open:", records[0].Open, "High:", records[0].High); Log("Second K-line data: Time:", records[1].Time, "Close:", records[1].Close); Log("Current K-line (latest)", records[records.size() - 1], "Previous K-line", records[records.size() - 2]); }
  • When the configured exchange object is a futures exchange object, you can use the symbol, period, and limit parameters to request K-line data for a specified instrument (futures instrument).

    javascript
    function main() { var records = exchange.GetRecords("BTC_USDT.swap", 60, 100) Log(records) }
    python
    def main(): records = exchange.GetRecords("BTC_USDT.swap", 60, 100) Log(records)
    rust
    fn main() { let records = exchange.GetRecords("BTC_USDT.swap", 60, 100).unwrap(); Log!(records); }
    c++
    void main() { auto records = exchange.GetRecords("BTC_USDT.swap", 60, 100); Log(records); }

Returns

TypeDescription

Record array / null value

The exchange.GetRecords() function returns a Record structure array when the data request succeeds, and returns a null value when the data request fails.

Arguments

NameTypeRequiredDescription

symbol

string

No

The symbol parameter is used to specify the exact trading pair or contract code corresponding to the requested Record array data. If this parameter is not passed, the K-line data of the currently set trading pair or contract code is requested by default.

When calling the exchange.GetRecords(symbol) function, if exchange is a spot exchange object and you need to request K-line data with USDT as the quote currency and BTC as the base currency, then the symbol parameter is: "BTC_USDT", which follows the trading pair format defined by the FMZ platform.

When calling the exchange.GetRecords(symbol) function, if exchange is a futures exchange object and you need to request K-line data for BTC's USDT-margined perpetual contract, then the symbol parameter is: "BTC_USDT.swap", which follows the format defined by the FMZ platform combining the trading pair and the contract code, separated by the character ".".

When calling the exchange.GetRecords(symbol) function, if exchange is a futures exchange object and you need to request K-line data for BTC's USDT-margined options contract, then the symbol parameter is: "BTC_USDT.BTC-240108-40000-C" (taking the Binance option BTC-240108-40000-C as an example), which follows the format defined by the FMZ platform combining the trading pair with the specific option contract code defined by the exchange, separated by the character ".".

period

number

No

The period parameter is used to specify the period of the requested K-line data, for example: PERIOD_M1, PERIOD_M5, PERIOD_M15, etc. In addition to accepting the predefined standard periods, the period parameter can also accept an integer value in seconds. If this parameter is not passed, the requested K-line data period defaults to the default K-line period configured for the current strategy's live trading/backtest.

limit

number

No

The limit parameter is used to specify the length of the requested K-line data. If this parameter is not passed, the default requested length is the maximum number of K-line bars that the exchange's K-line interface can request at once. This parameter may trigger paginated queries of the exchange's K-line data, and the call duration of this function will increase accordingly when paginated queries are performed.

See Also

Remarks

The default K-line period can be set on the backtesting and live trading pages. When calling the exchange.GetRecords() function, if a parameter is specified, it retrieves the K-line data for the period specified by that parameter; if no parameter is specified, it returns the K-line data for the period set in the backtesting or live trading parameters.

The return value is a Record structure array. The returned K-line data accumulates continuously over time, and the upper limit of the accumulated number of K-line bars is affected by the setting of the exchange.SetMaxBarLen() function. When not set, the default upper limit is 5000 K-line bars. Once the K-line data reaches the accumulation limit, each time a new K-line bar is added, the earliest K-line bar is deleted (similar to the first-in-first-out behavior of a queue). Some exchanges do not provide a K-line interface, in which case the docker collects market trade record data (a Trade structure array) in real time to synthesize K-lines.

If the exchange's K-line interface supports paginated queries, when calling the exchange.SetMaxBarLen() function to set a large K-line length, the system will initiate multiple API requests.

When the exchange.GetRecords() function is called for the first time, the number of K-line bars obtained differs between the backtesting and live trading environments:

  • The backtesting system pre-fetches a certain number of K-line bars prior to the start time of the backtesting time range (5000 by default; the relevant settings and data volume of the backtesting system will affect the final returned number) as the initial K-line data.

  • In live trading, the actual number of K-line bars obtained depends on the maximum amount of data that the exchange's K-line interface can provide.

Setting the period parameter to 5 means requesting K-line data with a period of 5 seconds. If the period parameter is not divisible by 60 (i.e., the represented period cannot be expressed in units of minutes), the underlying system will use the relevant interface of exchange.GetTrades() to obtain trade record data in order to synthesize the required K-line data; if the period parameter is divisible by 60, then 1-minute K-line data is used at minimum (using as large a period as possible) to synthesize the required K-line data.

In the simulation-level backtesting of the backtesting system, because the underlying K-line period must be set (during simulation-level backtesting, the system uses the corresponding K-line data to generate Tick data based on the configured underlying K-line period), the following must be noted: the K-line data period obtained in the strategy cannot be smaller than the underlying K-line period. This is because in simulation-level backtesting, the K-line data of each period is synthesized from the K-line data corresponding to the underlying K-line period.

In the C++ language, if you need to construct K-line data yourself, you can refer to the following code example:

c++
#include <sstream> void main() { Records r; r.Valid = true; for (auto i = 0; i < 10; i++) { Record ele; ele.Time = i * 100000; ele.High = i * 10000; ele.Low = i * 1000; ele.Close = i * 100; ele.Open = i * 10; ele.Volume = i * 1; r.push_back(ele); } // Output displays: Records[10] Log(r); auto ma = TA.MA(r,10); // Output displays: [nan,nan,nan,nan,nan,nan,nan,nan,nan,450] Log(ma); }

Exchanges that do not support the exchange.GetRecords() function:

Function NameUnsupported Spot ExchangesUnsupported Futures Exchanges
GetRecordsZaif / Coincheck / BitFlyerFutures_Aevo