数据格式
返回的格式必须为以下两种格式其中之一(系统自动识别):
- 模拟级Tick,以下是JSON数据范例:json{ "detail": { "eid": "Binance", "symbol": "BTC_USDT", "alias": "BTCUSDT", "baseCurrency": "BTC", "quoteCurrency": "USDT", "marginCurrency": "USDT", "basePrecision": 5, "quotePrecision": 2, "minQty": 0.00001, "maxQty": 9000, "minNotional": 5, "maxNotional": 9000000, "priceTick": 0.01, "volumeTick": 0.00001, "marginLevel": 10 }, "schema":["time", "open", "high", "low", "close", "vol"], "data":[ [1564315200000, 9531300, 9531300, 9497060, 9497060, 787], [1564316100000, 9495160, 9495160, 9474260, 9489460, 338] ] }
- 实盘级Tick,以下是JSON数据范例:
Tick级回测的数据(包含盘口深度信息,深度格式为[价格, 量]的数组。可有多级深度,asks为价格升序,bids为价格倒序)。json{ "detail": { "eid": "Binance", "symbol": "BTC_USDT", "alias": "BTCUSDT", "baseCurrency": "BTC", "quoteCurrency": "USDT", "marginCurrency": "USDT", "basePrecision": 5, "quotePrecision": 2, "minQty": 0.00001, "maxQty": 9000, "minNotional": 5, "maxNotional": 9000000, "priceTick": 0.01, "volumeTick": 0.00001, "marginLevel": 10 }, "schema":["time", "asks", "bids", "trades", "close", "vol"], "data":[ [1564315200000, [[9531300, 10]], [[9531300, 10]], [[1564315200000, 0, 9531300, 10]], 9497060, 787], [1564316100000, [[9531300, 10]], [[9531300, 10]], [[1564316100000, 0, 9531300, 10]], 9497060, 787] ] }
| 字段 | 说明 |
|---|---|
| detail | 请求数据的品种详细信息,包含计价币名称、交易币名称,精度,最小下单量等 |
| schema | 指定data数组中列的属性,区分大小写。仅限于 time, open, high, low, close, vol, asks, bids, trades |
| data | 按照schema设置的列结构,记录的数据。 |
数值精度
请求中固定带round=true,返回的数值都写成按精度放大后的整数,以免传输过程中丢失浮点数精度:
- 价格类数值(
open、high、low、close,asks/bids和trades中的价格)= 实际值 × 10^quotePrecision。 - 数量类数值(
vol,asks/bids和trades中的数量)= 实际值 × 10^basePrecision。
例如上面的范例中quotePrecision为2,9531300表示价格95313.00;basePrecision为5,787表示数量0.00787。时间列(time及trades中的时间)是毫秒时间戳,不放大。
detail字段
| 字段 | 说明 |
|---|---|
| eid | 交易所Id,注意某个交易所现货与期货是不同的eid |
| symbol | 交易品种代码 |
| alias | 当前交易品种代码对应的交易所中的symbol |
| baseCurrency | 交易币种 |
| quoteCurrency | 计价币种 |
| marginCurrency | 保证金币种 |
| basePrecision | 交易币种精度 |
| quotePrecision | 计价币种精度 |
| minQty | 最小下单量 |
| maxQty | 最大下单量 |
| minNotional | 最小下单金额 |
| maxNotional | 最大下单金额 |
| priceTick | 价格一跳 |
| volumeTick | 下单量最小变动数值(下单量一跳) |
| marginLevel | 期货杠杆值 |
| contractType | 对于永续合约设置为:swap,回测系统会继续发送资金费率、价格指数请求 |
特殊的列属性asks、bids、trades:
| 字段 | 说明 | 备注 |
|---|---|---|
| asks / bids | [[价格, 数量], ...] | 例如实盘级Tick数据范例中的数据:[[9531300, 10]] |
| trades | [[时间, 方向(0:买,1:卖), 价格, 数量], ...] | 例如实盘级Tick数据范例中的数据:[[1564315200000, 0, 9531300, 10]] |
期货交易所的永续合约回测时,自定义数据源还需要额外的资金费率数据、价格指数数据。只有当请求的行情数据返回时,返回的结构中detail字段包含"contractType": "swap"键值对,回测系统才会继续发送对于资金费率的请求。
当回测系统收到资金费率数据时,才会继续发送对于价格指数数据的请求。
资金费率数据结构如下:
json
{
"detail": {
"eid": "Futures_Binance",
"symbol": "BTC_USDT.funding",
"alias": "BTC_USDT.funding",
"baseCurrency": "BTC",
"quoteCurrency": "USDT",
"marginCurrency": "",
"basePrecision": 8,
"quotePrecision": 8,
"minQty": 1,
"maxQty": 10000,
"minNotional": 1,
"maxNotional": 100000000,
"priceTick": 1e-8,
"volumeTick": 1e-8,
"marginLevel": 10
},
"schema": [
"time",
"open",
"high",
"low",
"close",
"vol"
],
"data": [
[
1584921600000,
-16795,
-16795,
-16795,
-16795,
0
],
[
1584950400000,
-16294,
-16294,
-16294,
-16294,
0
]
]
}
- 相邻的周期间隔8小时
- 资金费率数据为什么是 -16795?
与K线数据一样按精度放大为整数:该数据的quotePrecision为8,-16795表示资金费率-0.00016795。资金费率可以为负值。
回测系统发出的资金费率数据请求,举例为:
url
http://customserver:9090/data?custom=0&depth=20&detail=true&eid=Futures_Binance&from=1351641600&period=86400000&round=true&symbol=BTC_USDT.funding&to=1611244800&trades=0
价格指数数据结构如下:
json
{
"detail": {
"eid": "Futures_Binance",
"symbol": "BTC_USDT.index",
"alias": "BTCUSDT",
"baseCurrency": "BTC",
"quoteCurrency": "USDT",
"contractType": "index",
"marginCurrency": "USDT",
"basePrecision": 3,
"quotePrecision": 1,
"minQty": 0.001,
"maxQty": 1000,
"minNotional": 0,
"maxNotional": 1.7976931348623157e+308,
"priceTick": 0.1,
"volumeTick": 0.001,
"marginLevel": 10,
"volumeMultiple": 1
},
"schema": [
"time",
"open",
"high",
"low",
"close",
"vol"
],
"data": [
[1584921600000, 58172, 59167, 56902, 58962, 0],
[1584922500000, 58975, 59428, 58581, 59154, 0]
]
}
回测系统发出的价格指数数据请求,举例为:
url
http://customserver:9090/data?custom=0&depth=20&detail=true&eid=Futures_Binance&from=1351641600&period=86400000&round=true&symbol=BTC_USDT.index&to=1611244800&trades=0