输入/搜索内容
入门
平台基础
编写策略
开发工具
回测系统
概述与发起回测
回测模式与撮合
回测配置与保存
支持范围
结果解读
参数调优
自定义数据源
数据格式
自定义数据源范例
本地回测引擎
回测页面快捷键
进阶专题
数据与研究
扩展API接口

自定义数据源返回JSON数据,格式为下面两种之一,系统自动识别:模拟级Tick用K线数据,实盘级Tick用盘口深度和逐笔成交数据。数值都按精度放大为整数,见下文「数值精度」。

模拟级Tick
json
{ "detail": { "eid": "Binance", "symbol": "BTC_USDT", "alias": "BTCUSDT", "baseCurrency": "BTC", "quoteCurrency": "USDT", "marginCurrency": "USDT", "basePrecision": 5, "quotePrecision": 3, "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

数据中包含盘口深度,深度格式为[价格, 量]的数组,可以有多档:asks按价格升序,bids按价格降序。

json
{ "detail": { "eid": "Binance", "symbol": "BTC_USDT", "alias": "BTCUSDT", "baseCurrency": "BTC", "quoteCurrency": "USDT", "marginCurrency": "USDT", "basePrecision": 5, "quotePrecision": 3, "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请求品种的详细信息,例如交易币、计价币、精度、最小下单量,见下文「detail字段」
schemadata数组中各列的属性,区分大小写
data按schema的列结构记录的数据

schema可用的列:time、open、high、low、close、vol、asks、bids、trades、position(持仓量)、data(自定义数据)。其中asks、bids、trades的格式:

列格式示例(实盘级Tick范例中的数据)
asks / bids[[价格, 数量], ...][[9531300, 10]]
trades[[时间, 方向, 价格, 数量], ...],方向0为买、1为卖[[1564315200000, 0, 9531300, 10]]
数值精度

请求中固定带round=true,返回的数值都写成按精度放大后的整数,以免传输过程中丢失浮点数精度:

  • 价格类数值(open、high、low、close,asks/bids和trades中的价格)= 实际值 × 10^quotePrecision。
  • 数量类数值(vol,asks/bids和trades中的数量)= 实际值 × 10^basePrecision。

例如上面的范例中quotePrecision为3,9531300表示价格9531.300;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,回测系统会继续请求资金费率、价格指数数据
永续合约的资金费率与价格指数

期货交易所的永续合约回测时,自定义数据源还需要提供资金费率数据和价格指数数据:

  • 行情数据的detail中包含"contractType": "swap"时,回测系统才会继续请求资金费率数据,并且只在策略持有该永续合约的仓位、或者调用GetFundings()时才请求。声明了swap却拿不到资金费率数据时,回测报错symbol ... not found。
  • 收到资金费率数据后,回测系统才会继续请求价格指数数据。
  • 资金费率数据只读取open列作为费率值,并按资金费率数据detail中的priceTick截断,所以其priceTick要足够小(例如0.00000001)。
  • 资金费率数据相邻两条间隔8小时,与K线数据一样按精度放大为整数,可以为负值。下例中quotePrecision为8,-16795表示资金费率-0.00016795。

资金费率数据(请求的symbol形如BTC_USDT.funding):

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] ] }

回测系统发出的资金费率数据请求示例:

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

价格指数数据(请求的symbol形如BTC_USDT.index):

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