扩展API接口
发明者量化平台开放了扩展API接口,支持通过程序化方式调用发明者量化交易平台的各项功能。
创建ApiKey
发明者量化交易平台支持扩展API接口的权限管理,可以设置API KEY的权限。在平台账号设置页面的「API接口」选项中,点击「创建新的ApiKey」按钮即可创建扩展API KEY。
创建API KEY时,可在「API权限」输入框中输入*符号以开启所有扩展API接口权限。如需指定具体接口权限,请输入对应的扩展API函数名,使用英文逗号分隔,例如:GetRobotDetail,DeleteRobot,这将授予该API KEY调用获取实盘详细信息接口和删除实盘接口的权限。
在API KEY管理页面,您还可以对已创建的API KEY进行修改、禁用、删除等操作。
扩展API接口返回码
扩展API接口返回的数据结构示例如下:
json
{
"code":0,
"data":{
// ...
}
}
code字段表示扩展API接口调用时返回的状态码。
| 描述 | 代码 |
|---|---|
| 执行成功 | 0 |
| 错误的API KEY | 1 |
| 错误的签名 | 2 |
| Nonce错误 | 3 |
| 方法不正确 | 4 |
| 参数不正确 | 5 |
| 内部未知错误 | 6 |
实盘状态码
GetRobotList接口、GetRobotDetail接口、GetRobotLogs接口返回的数据中status字段为:实盘状态码。
- 正常启动
状态 代码 空闲中 0 运行中 1 停止中 2 已退出 3 被停止 4 策略有错误 5 - 异常
状态 代码 策略已过期,请联系作者重新购买 -1 未找到托管者 -2 策略编译错误 -3 实盘已处于运行状态 -4 余额不足 -5 策略并发数超限 -6
验证方式
调用扩展API接口时支持两种验证方式:token验证和直接验证。
token验证
使用md5加密方式进行验证,以下是Python、Golang语言的调用示例:
python
#!/usr/bin/python
# -*- coding: utf-8 -*-
import time
import json
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
try:
import md5
import urllib2
from urllib import urlencode
except:
import hashlib as md5
import urllib.request as urllib2
from urllib.parse import urlencode
accessKey = '' # your API KEY
secretKey = ''
def api(method, *args):
d = {
'version': '1.0',
'access_key': accessKey,
'method': method,
'args': json.dumps(list(args)),
'nonce': int(time.time() * 1000),
}
d['sign'] = md5.md5(('%s|%s|%s|%d|%s' % (d['version'], d['method'], d['args'], d['nonce'], secretKey)).encode('utf-8')).hexdigest()
# 注意:urllib2.urlopen 函数可能存在超时问题,可以设置超时时间,例如:urllib2.urlopen('https://www.fmz.com/api/v1', urlencode(d).encode('utf-8'), timeout=10) 设置超时时间为10秒
return json.loads(urllib2.urlopen('https://www.fmz.com/api/v1', urlencode(d).encode('utf-8')).read().decode('utf-8'))
# 返回托管者列表
print(api('GetNodeList'))
# 返回交易所列表
print(api('GetPlatformList'))
# GetRobotList(offset, length, robotStatus, label),传入-1表示获取全部
print(api('GetRobotList', 0, 5, -1, 'member2'))
# CommandRobot(robotId, cmd)向实盘发送命令
print(api('CommandRobot', 123, 'ok'))
# StopRobot(robotId)返回实盘状态码
print(api('StopRobot', 123))
# RestartRobot(robotId)返回实盘状态码
print(api('RestartRobot', 123))
# GetRobotDetail(robotId)返回实盘详细信息
print(api('GetRobotDetail', 123))
mylang
package main
import (
"fmt"
"time"
"encoding/json"
"crypto/md5"
"encoding/hex"
"net/http"
"io/ioutil"
"strconv"
"net/url"
)
// 填写您的FMZ平台API密钥
var apiKey string = ""
// 填写您的FMZ平台密钥
var secretKey string = ""
var baseApi string = "https://www.fmz.com/api/v1"
func api(method string, args ... interface{}) (ret interface{}) {
// 处理参数
jsonStr, err := json.Marshal(args)
if err != nil {
panic(err)
}
params := map[string]string{
"version" : "1.0",
"access_key" : apiKey,
"method" : method,
"args" : string(jsonStr),
"nonce" : strconv.FormatInt(time.Now().UnixNano() / 1e6, 10),
}
data := fmt.Sprintf("%s|%s|%s|%v|%s", params["version"], params["method"], params["args"], params["nonce"], secretKey)
h := md5.New()
h.Write([]byte(data))
sign := h.Sum(nil)
params["sign"] = hex.EncodeToString(sign)
// http request
client := &http.Client{}
// request
urlValue := url.Values{}
for k, v := range params {
urlValue.Add(k, v)
}
urlStr := urlValue.Encode()
request, err := http.NewRequest("GET", baseApi + "?" + urlStr, nil)
if err != nil {
panic(err)
}
resp, err := client.Do(request)
if err != nil {
panic(err)
}
defer resp.Body.Close()
b, err := ioutil.ReadAll(resp.Body)
if err != nil {
panic(err)
}
ret = string(b)
return
}
func main() {
settings := map[string]interface{}{
"name": "hedge test",
"strategy": 104150,
// K线周期参数,60表示60秒
"period": 60,
"node" : 73938,
"appid": "member2",
"exchanges": []interface{}{
map[string]interface{}{
"eid": "Exchange",
"label" : "test_bjex",
"pair": "BTC_USDT",
"meta" : map[string]interface{}{
// 填写访问密钥
"AccessKey": "",
// 填写密钥
"SecretKey": "",
"Front" : "http://127.0.0.1:6666/exchange",
},
},
},
}
method := "RestartRobot"
fmt.Println("调用接口:", method)
ret := api(method, 124577, settings)
fmt.Println("main ret:", ret)
}
直接验证
支持不使用token验证(直接传递secret_key验证),可以生成一个用于直接访问的URL。例如直接向实盘发送交互指令的URL,可用于Trading View或其他场景的WebHook回调。对于扩展API接口CommandRobot()函数,不进行nonce校验,不限制该接口的访问频率和访问次数。
例如:创建的扩展API KEY中的AccessKey为:xxx,SecretKey为:yyy。访问以下链接即可向ID为186515的实盘发送交互指令消息,消息内容为字符串:"ok12345"。
plaintext
https://www.fmz.com/api/v1?access_key=xxx&secret_key=yyy&method=CommandRobot&args=%5B186515%2C%22ok12345%22%5D
在支持直接验证方式下,可获取请求中的Body数据,仅支持CommandRobot接口。例如在Trading View的WebHook URL中设置:
plaintext
https://www.fmz.com/api/v1?access_key=xxx&secret_key=yyy&method=CommandRobot&args=%5B186515%2C+%22%22%5D
注意需要按照此格式设置:%5B186515%2C+%22%22%5D(编码前为:[186515, ""]),其中186515是发明者量化交易平台的实盘ID。
模拟Trading View发送WebHook URL警报:
javascript
function main() {
var options = {
method: "POST",
body: `{"test": 123}`,
headers: {"Content-Type": "application/json"}
}
// WebHook URL 警报会自动发送POST请求,包含需要的 headers 设置
return HttpQuery("https://www.fmz.com/api/v1?access_key=xxx&secret_key=xxx&method=CommandRobot&args=%5B186515%2C+%22%22%5D", options)
}
Trading View消息框中设置(要发送的请求中的Body数据):
-
JSON格式:
plaintext{"close": {{close}}, "name": "aaa"}ID为
186515的实盘即可收到交互命令字符串:{"close": 39773.75, "name": "aaa"}。 -
文本格式:
plaintextBTCUSDTPERP 穿过(Crossing) 39700.00 close: {{close}}ID为
186515的实盘即可收到交互命令字符串:BTCUSDTPERP 穿过(Crossing) 39700.00 close: 39739.4。
Python、Golang语言调用示例:
python
#!/usr/bin/python
# -*- coding: utf-8 -*-
import json
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
try:
import urllib2
except:
import urllib.request as urllib2
accessKey = 'your accessKey'
secretKey = 'your secretKey'
def api(method, *args):
return json.loads(urllib2.urlopen(('https://www.fmz.com/api/v1?access_key=%s&secret_key=%s&method=%s&args=%s' % (accessKey, secretKey, method, json.dumps(list(args)))).replace(' ', '')).read().decode('utf-8'))
# 如果API KEY没有该接口权限,调用print(api('RestartRobot', 186515)) 会失败,返回数据:{'code': 4, 'data': None}
# print(api('RestartRobot', 186515))
# 打印Id为:186515的实盘详细信息
print(api('GetRobotDetail', 186515))
mylang
package main
import (
"fmt"
"encoding/json"
"net/http"
"io/ioutil"
"net/url"
)
// 填写自己的FMZ平台api key
var apiKey string = "your access_key"
// 填写自己的FMZ平台secret key
var secretKey string = "your secret_key"
var baseApi string = "https://www.fmz.com/api/v1"
func api(method string, args ... interface{}) (ret interface{}) {
jsonStr, err := json.Marshal(args)
if err != nil {
panic(err)
}
params := map[string]string{
"access_key" : apiKey,
"secret_key" : secretKey,
"method" : method,
"args" : string(jsonStr),
}
// http request
client := &http.Client{}
// request
urlValue := url.Values{}
for k, v := range params {
urlValue.Add(k, v)
}
urlStr := urlValue.Encode()
request, err := http.NewRequest("GET", baseApi + "?" + urlStr, nil)
if err != nil {
panic(err)
}
resp, err := client.Do(request)
if err != nil {
panic(err)
}
defer resp.Body.Close()
b, err := ioutil.ReadAll(resp.Body)
if err != nil {
panic(err)
}
ret = string(b)
return
}
func main() {
method := "GetRobotDetail"
fmt.Println("调用接口:", method)
ret := api(method, 186515)
fmt.Println("main ret:", ret)
}
使用发明者量化交易平台扩展API实现TradingView报警信号交易
使用发明者量化交易平台扩展API实现TradingView报警信号交易,B站视频链接
扩展API接口详解
-
发明者量化交易平台扩展API接口
在https://www.fmz.com/api/v1后直接附加请求的查询参数(以?分隔),以下是使用Python表达的请求参数:json{ "version" : "1.0", "access_key": "xxx", "method" : "GetNodeList", "args" : [], "nonce" : 1516292399361, "sign" : "085b63456c93hfb243a757366600f9c2" }字段 说明 version 版本号。 access_key AccessKey,在账户管理页面申请。 method 具体调用的方法。 args 调用method方法的参数列表。 nonce 时间戳,单位为毫秒,允许与标准时间戳前后误差1小时,nonce必须大于上一次访问时的nonce值。 sign 签名。 各参数以字符
&分隔,参数名和参数值用符号=连接,完整的请求URL(以method=GetNodeList为例):plaintexthttps://www.fmz.com/api/v1?access_key=xxx&nonce=1516292399361&args=%5B%5D&sign=085b63456c93hfb243a757366600f9c2&version=1.0&method=GetNodeList注意:请求参数中不包含
secret_key参数。 -
签名方式
请求参数中sign参数的加密方式如下,按照以下格式:plaintextversion + "|" + method + "|" + args + "|" + nonce + "|" + secretKey拼接字符串后,使用
MD5加密算法对字符串进行加密,并转换为十六进制字符串,该值作为参数sign的值。签名部分可参考Python代码扩展API接口「验证方式」:python# 参数 d = { 'version': '1.0', 'access_key': accessKey, 'method': method, 'args': json.dumps(list(args)), 'nonce': int(time.time() * 1000), } # 计算sign签名 d['sign'] = md5.md5(('%s|%s|%s|%d|%s' % (d['version'], d['method'], d['args'], d['nonce'], secretKey)).encode('utf-8')).hexdigest() -
接口业务错误:
- 参数不足:json{ "code":0, "data":{ "result":null, "error":"Params length incorrect" } }
- 参数不足:
GetNodeList
GetNodeList方法用于获取请求中API KEY对应的发明者量化交易平台账号下的托管者列表。
返回值
json
{
"code": 0,
"data": {
"result": {
"all": 1,
"nodes": [{
"build": "3.7",
"city": "...",
"created": "2024-11-08 09:21:08",
"date": "2024-11-08 16:37:16",
"forward": "...",
"guid": "...",
"host": "node.fmz.com:9902",
"id": 123,
"ip": "...",
"is_owner": true,
"loaded": 0,
"name": "MacBook-Pro-2.local",
"online": true,
"os": "darwin/amd64",
"peer": "...",
"public": 0,
"region": "...",
"tunnel": false,
"version": "...",
"wd": 0
}]
},
"error": null
}
}
返回值字段说明(字面意思明显的字段不再赘述):
- all: 当前账户关联的托管者总数。
- nodes: 托管者节点的详细信息列表。
- build: 版本号。
- city: 所在城市。
- is_owner: true表示私有托管者,false表示公共托管者。
- loaded: 负载量,即当前运行的策略实例数量。
- public: 0表示私有托管者,1表示公共托管者。
- region: 地理位置。
- version: 托管者的详细版本信息。
- wd: 离线报警开关,0表示未开启。
一键部署的托管者包含额外信息,相关字段以ecs_、unit_为前缀,记录了一键部署托管者服务器的相关信息(运营商名称、配置、状态等)、计费周期、价格等信息,此处不再详述。
参数
无参数
GetRobotGroupList
GetRobotGroupList方法用于获取请求中API KEY对应的发明者量化交易平台账号下的实盘分组列表。
返回值
json
{
"code": 0,
"data": {
"result": {
"items": [{
"id": 3417,
"name": "测试"
}, {
"id": 3608,
"name": "实盘演示"
}]
},
"error": null
}
}
- items: 实盘分组信息。
- id: 实盘分组ID。
- name: 实盘分组名称。
items字段仅记录创建的新分组,「默认」分组不包含在items中。
参数
无参数
GetPlatformList
GetPlatformList方法用于获取请求中API KEY对应的发明者量化交易平台账号下已配置的交易所列表。
返回值
json
{
"code": 0,
"data": {
"result": {
"all": 2,
"platforms": [{
"category": "加密货币||Crypto",
"date": "2023-12-07 13:44:52",
"eid": "Binance",
"id": 123,
"label": "币安",
"logo": "...",
"name": "币安现货|Binance",
"stocks": ["BTC_USDT", "LTC_USDT", "ETH_USDT", "ETC_USDT", "BTC_TUSD", "ETH_TUSD", "BNB_TUSD"],
"website": "..."
}, {
"category": "通用协议|Custom Protocol",
"date": "2020-11-09 11:23:48",
"eid": "Exchange",
"id": 123,
"label": "XX交易所REST协议",
"logo": "...",
"name": "通用协议|Custom Protocol",
"stocks": ["BTC_USDT", "ETH_USDT"],
"website": ""
}]
},
"error": null
}
}
- all: 已配置的交易所对象总数。
- platforms: 交易所相关信息。
- eid: 发明者量化交易平台上的交易所标识符,在某些配置和参数中需要使用
eid。
- eid: 发明者量化交易平台上的交易所标识符,在某些配置和参数中需要使用
参数
无参数
GetRobotList
GetRobotList方法用于获取请求中API KEY对应的发明者量化交易平台账号下的实盘列表。
返回值
json
{
"code": 0,
"data": {
"result": {
"all": 1,
"concurrent": 0,
"robots": [{
"charge_time": 1731654846,
"date": "2024-11-12 14:05:29",
"end_time": "2024-11-15 14:56:32",
"fixed_id": 4509153,
"id": 591026,
"is_sandbox": 0,
"name": "测试",
"node_guid": "45891bcf3d57f99b08a43dff76ee1ea1",
"node_id": 4519153,
"node_public": 0,
"profit": 0,
"public": 0,
"refresh": 1731651257000,
"start_time": "2024-11-15 14:56:30",
"status": 3,
"strategy_id": 411670,
"strategy_isowner": true,
"strategy_language": 0,
"strategy_name": "测试",
"strategy_public": 0,
"uid": "105ed6e511cc977921610fdbb7e2a1d6",
"wd": 0
}]
},
"error": null
}
}
- robots: 实盘信息
- group_id: 实盘分组ID;如果实盘位于默认分组中,则不包含
group_id字段。
- group_id: 实盘分组ID;如果实盘位于默认分组中,则不包含
参数
| 名称 | 类型 | 必填 | 描述 |
offset | number | 否 | 分页查询的偏移量设置。 |
length | number | 否 | 分页查询的数据长度设置。 |
robotStatus | number | 否 | 指定要查询的实盘状态,参考扩展API接口「实盘状态码」,传入 |
label | string | 否 | 指定要查询的实盘自定义标签,可筛选出包含该标签的所有实盘。 |
keyWord | string | 否 | 查询关键字。 |
备注
以Python语言的扩展API接口「验证方式」为例:
print(api('GetRobotList')):获取全部实盘信息。
print(api('GetRobotList', 'member2')):打印所有自定义标签为member2的实盘信息。
print(api('GetRobotList', 0, 5, -1, 'member2')):分页查询,从偏移量0开始,最多返回5个标签为member2的实盘。
CommandRobot
CommandRobot方法用于向请求中API KEY对应的发明者量化交易平台账号下的实盘发送交互命令。接收交互命令的实盘Id由robotId参数指定,交互命令由策略中调用的GetCommand()函数捕获并返回。
返回值
json
{
"code":0,
"data":{
"result":true,
"error":null
}
}
- result: 交互指令是否发送成功。向未运行的实盘发送指令时,返回数据中的result为false。
参数
| 名称 | 类型 | 必填 | 描述 |
robotId | number | 是 |
|
cmd | string | 是 |
|
备注
实盘策略示例(假设该策略实盘正在运行,实盘Id为123):
javascript
function main() {
while (true) {
var cmd = GetCommand()
if (cmd) {
Log(cmd)
}
Sleep(2000)
}
}
如果使用本章节的Python测试脚本访问发明者量化交易平台的扩展API:api("CommandRobot", 123, "test command"),Id为123的实盘将收到交互指令:test command,并通过Log函数输出打印。
StopRobot
StopRobot方法用于停止请求中API KEY对应的发明者量化交易平台账号下的实盘。停止运行的实盘Id由robotId参数指定。
返回值
json
{
"code":0,
"data":{
"result":2,
"error":null
}
}
- result: 实盘状态码,2表示停止中。
参数
| 名称 | 类型 | 必填 | 描述 |
robotId | number | 是 |
|
RestartRobot
RestartRobot方法用于重启请求中API KEY对应的发明者量化交易平台账号下的实盘。重启的实盘ID由robotId参数指定。
返回值
json
{
"code":0,
"data":{
"result":1,
"error":null
}
}
- result: 实盘状态码,1表示运行中。
参数
| 名称 | 类型 | 必填 | 描述 |
robotId | number | 是 |
|
settings | JSON对象 | 否 | 实盘配置参数,
|
备注
如果实盘是通过扩展API接口创建的,重启时必须使用扩展API接口RestartRobot进行重启,并且必须传入settings参数。对于在平台页面上创建的实盘,可以通过扩展API接口重启或点击实盘页面上的按钮重启。可以传入settings参数或不传入。如果只传入robotId参数,则按照实盘的当前设置启动运行。
GetRobotDetail
GetRobotDetail方法用于获取请求中API KEY对应的发明者量化交易平台账号下的实盘详细信息。所要获取的实盘详细信息由robotId参数指定。
返回值
json
{
"code": 0,
"data": {
"result": {
"robot": {
"charge_time": 1732246539,
"charged": 5850000,
"consumed": 5375000000,
"date": "2018-12-28 14:34:51",
"favorite": {
"added": false,
"type": "R"
},
"fixed_id": 123,
"hits": 1,
"id": 123,
"is_deleted": 0,
"is_manager": true,
"is_sandbox": 0,
"name": "测试",
"node_id": 123,
"pexchanges": {
"123": "Futures_OKCoin"
},
"phash": {
"123": "ca1aca74b9cf7d8624f2af2dac01e36d"
},
"plabels": {
"123": "OKEX期货 V5"
},
"priority": 0,
"profit": 0,
"public": 0,
"refresh": 1732244453000,
"robot_args": "[]",
"start_time": "2024-11-22 11:00:48",
"status": 1,
"strategy_args": "[]",
"strategy_exchange_pairs": "[60,[123],[\"ETH_USDT\"]]",
"strategy_id": 123,
"strategy_last_modified": "2024-11-21 16:49:25",
"strategy_name": "测试",
"strategy_public": "0",
"uid": "105ed6e51bcc17792a610fdbb7e2a1d6",
"username": "abc",
"wd": 0
}
},
"error": null
}
}
- charge_time: 下次扣费时间,即当前扣费后的有效截止时间。
- charged: 已消耗的时间。
- consumed: 已消耗的金额(0.125 USD = 12500000 / 1e8)。
- date: 创建日期。
- fixed_id: 实盘运行时分配的托管者ID,如果是自动分配,该值为-1。
- is_manager: 是否有权限管理该实盘。
- is_sandbox: 是否为模拟盘。
- name: 实盘名称。
- node_id: 托管者ID。
- pexchanges: 实盘配置的交易所对象,123为pid,"Futures_OKCoin"为交易所名称。
- plabels: 实盘配置的交易所对象的标签信息。
- profit: 实盘收益数据。
- public: 实盘是否公开。
- refresh: 最近活跃时间。
- strategy_exchange_pairs: 配置的交易所对象及其交易对信息。
- wd: 是否开启离线报警。
参数
| 名称 | 类型 | 必填 | 描述 |
robotId | number | 是 |
|
备注
strategy_exchange_pairs属性说明,以下列数据为例:
plaintext
"[60,[44314,42960,15445,14703],[\"BTC_USDT\",\"BTC_USDT\",\"ETH_USDT\",\"ETH_USDT\"]]"
其中第一个数据60表示实盘设置的默认K线周期为1分钟,即60秒。
[44314,42960,15445,14703]为实盘配置的交易所对象的pid(按添加顺序排列)。
[\"BTC_USDT\",\"BTC_USDT\",\"ETH_USDT\",\"ETH_USDT\"]为实盘配置的交易所对象设置的交易对(按添加顺序与pid一一对应)。
GetAccount
GetAccount方法用于获取请求中API KEY对应的发明者量化交易平台账号的账户信息。
返回值
json
{
"code":0,
"data":{
"result":{
"balance":22944702436,
"concurrent":0,
"consumed":211092719653,
"currency":"USD",
"email":"[email protected]",
"openai":false,
"settings":null,
"sns":{"wechat":true},
"uid":"105ea6e51bcc177926a10fdbb7e2a1d6",
"username":"abc"
},
"error":null
}
}
- balance: 账户余额
此处的数值采用整数表示以确保精度,实际数值需除以1e8(即10的8次方)进行换算。本例中实际余额为:229.44702436
GetExchangeList
GetExchangeList方法用于获取FMZ量化交易平台支持的交易所列表及其配置信息。
返回值
isSummary参数为false时,返回的数据:
json
{
"code": 0,
"data": {
"result": {
"exchanges": [{
"category": "加密货币||Crypto",
"eid": "Futures_Binance",
"id": 74,
"logo": "/upload/asset/d8d84b23e573e9326b99.svg",
"meta": "[{\"desc\": \"Access Key\", \"qr\":\"apiKey\",\"required\": true, \"type\": \"string\", \"name\": \"AccessKey\", \"label\": \"Access Key\"}, {\"encrypt\": true, \"qr\":\"secretKey\",\"name\": \"SecretKey\", \"required\": true, \"label\": \"Secret Key\", \"type\": \"password\", \"desc\": \"Secret Key\"}]",
"name": "币安期货|Futures_Binance",
"priority": 200,
"stocks": "BTC_USDT,ETH_USDT,ETH_USD",
"website": "https://accounts.binance.com/zh-TC/register?ref=45110270"
}]
},
"error": null
}
}
isSummary参数为true时,返回的数据:
json
{
"code": 0,
"data": {
"result": {
"exchanges": [{
"category": "加密货币||Crypto",
"eid": "Futures_Binance",
"id": 74,
"logo": "/upload/asset/d8d84b23e573e9326b99.svg",
"name": "币安期货|Futures_Binance",
"priority": 200,
"website": "https://accounts.binance.com/zh-TC/register?ref=45110270"
}]
},
"error": null
}
}
- meta: 交易所配置元数据。
参数
| 名称 | 类型 | 必填 | 描述 |
isSummary | bool | 是 |
|
DeleteNode
DeleteNode方法用于删除请求中API KEY对应的发明者量化交易平台账号下的托管者节点,删除的托管者节点ID为nid参数指定的托管者ID。
返回值
json
{
"code":0,
"data":{
"result":true,
"error":null
}
}
- result: 是否成功删除关联的托管者程序。
参数
| 名称 | 类型 | 必填 | 描述 |
nid | number | 是 |
|
DeleteRobot
DeleteRobot方法用于删除请求中API KEY对应的发明者量化交易平台账号下的实盘。删除的实盘ID为robotId参数指定的实盘ID。
返回值
json
{
"code":0,
"data":{
"result":0,
"error":null
}
}
- result: 实盘删除操作的反馈结果。
- 0: 正常删除。
- -2: 删除成功,但无法与实盘关联的托管者联系,请手动删除文件 123.db3!
参数
| 名称 | 类型 | 必填 | 描述 |
robotId | number | 是 |
|
deleteLogs | bool | 是 |
|
GetStrategyList
GetStrategyList方法用于获取平台策略信息。
返回值
json
{
"code": 0,
"data": {
"result": {
"all": 123,
"strategies": [{
"category": 9,
"date": "2024-11-10 20:40:04",
"description": "",
"forked": 0,
"hits": 0,
"id": 123,
"is_buy": false,
"is_owner": false,
"language": 2,
"last_modified": "2024-11-11 17:23:52",
"name": "HedgeGridStrategy",
"profile": {
"avatar": "...",
"nickname": "abc",
"uid": "4ed225440db1eda23fe05ed10184113e"
},
"public": 0,
"tags": "",
"uid": "4ed225440db1eda23fe05ed10184113e",
"username": "abc"
}]
},
"error": null
}
}
- all: 符合筛选条件的策略总数。
- strategies: 查询返回的策略详细信息。
参数
| 名称 | 类型 | 必填 | 描述 |
offset | number | 是 |
|
length | number | 是 |
|
strategyType | number | 是 |
|
category | number | 是 |
|
needArgs | number | 是 |
|
language | number | 是 |
|
kw | string | 是 |
|
NewRobot
NewRobot方法用于创建请求中API KEY对应的发明者量化交易平台账号下的实盘。
返回值
json
{
"code":0,
"data":{
"result":591988,
"error":null
}
}
- result: 创建成功,返回实盘ID。
参数
| 名称 | 类型 | 必填 | 描述 |
settings | JSON对象 | 是 | 实盘配置参数,
|
备注
settings参数中eid配置的"meta":{"AccessKey": "123", "SecretKey": "123"}等敏感信息,发明者量化交易平台不会存储。这些数据将直接转发给托管者程序,因此每次创建或重启实盘时必须配置此信息。
如果创建使用通用协议交易所对象的实盘,在配置settings参数时,exchanges属性可使用如下设置:
json
{
"eid": "Exchange",
"label": "test",
"pair": "ETH_BTC",
"meta": {
"AccessKey": "123",
"SecretKey": "123",
"Front": "http://127.0.0.1:6666/test"
}
}
label属性用于为当前通用协议接入的交易所对象设置标签,在策略中可使用exchange.GetLabel()函数获取。
PluginRun
PluginRun方法用于调用发明者量化交易平台的调试工具功能;仅支持JavaScript语言。
返回值
json
{
"code": 0,
"data": {
"result": "{\"logs\":[{\"PlatformId\":\"\",\"OrderId\":\"0\",\"LogType\":5,\"Price\":0,\"Amount\":0,\"Extra\":\"Hello FMZ\",\"Currency\":\"\",\"Instrument\":\"\",\"Direction\":\"\",\"Time\":1732267473108}],\"result\":\"\"}",
"error": null
}
}
- result: 调试工具成功执行传入的JavaScript代码后返回的测试结果数据。
参数
| 名称 | 类型 | 必填 | 描述 |
settings | JSON对象 | 是 | 调试工具中的设置参数,
|
备注
{"eid": "OKEX", "pair": "ETH_BTC", "meta" :{"AccessKey": "123", "SecretKey": "123"}}
{"eid": "Huobi", "pair": "BCH_BTC", "meta" :{"AccessKey": "123", "SecretKey": "123"}}
对于settings中的exchanges属性,调用PluginRun方法时只需设置一个(在调试工具页面使用时也仅支持一个交易所对象)。在settings中设置2个交易所对象不会引发报错,但在代码中访问第二个交易所对象时将会报错。
GetRobotLogs
GetRobotLogs方法用于获取请求中API KEY对应的FMZ量化交易平台账号下的实盘日志信息。要获取日志信息的实盘ID由robotId参数指定。
返回值
json
{
"code": 0,
"data": {
"result": {
"chart": "",
"chartTime": 0,
"logs": [{
"Total": 20,
"Max": 20,
"Min": 1,
"Arr": []
}, {
"Total": 0,
"Max": 0,
"Min": 0,
"Arr": []
}, {
"Total": 0,
"Max": 0,
"Min": 0,
"Arr": []
}],
"node_id": 123,
"online": true,
"refresh": 1732201544000,
"status": 4,
"summary": "...",
"updateTime": 1732201532636,
"wd": 0
},
"error": null
}
}
- logs: 日志信息;查询出的若干条日志数据存储在Arr字段中。
logs中第一个数据结构为实盘数据库中策略日志表的日志记录。
logs中第二个数据结构为实盘数据库中收益日志表的日志记录。
logs中第三个数据结构为实盘数据库中图表日志表的日志记录。 - summary: 实盘状态栏数据。
参数
| 名称 | 类型 | 必填 | 描述 |
robotId | number | 是 |
|
logMinId | number | 是 |
|
logMaxId | number | 是 |
|
logOffset | number | 是 |
|
logLimit | number | 是 |
|
profitMinId | number | 是 |
|
profitMaxId | number | 是 |
|
profitOffset | number | 是 |
|
profitLimit | number | 是 |
|
chartMinId | number | 是 |
|
chartMaxId | number | 是 |
|
chartOffset | number | 是 |
|
chartLimit | number | 是 |
|
chartUpdateBaseId | number | 是 |
|
chartUpdateDate | number | 是 |
|
summaryLimit | number | 是 |
设置为0表示不查询状态栏信息;设置为非0值表示要查询的状态栏信息字节数(此接口不限制数据量,可以指定一个较大的summaryLimit参数来获取所有状态栏信息)。状态栏数据存储在返回数据的 |
备注
-
数据库中的策略日志表
返回数据中logs的属性值(数组结构)的第一个元素中(日志数据)Arr属性值描述如下:plaintext"Arr": [ [3977, 3, "Futures_OKCoin", "", 0, 0, "Sell(688.9, 2): 20016", 1526954372591, "", ""], [3976, 5, "", "", 0, 0, "OKCoin:this_week 仓位过多, 多: 2", 1526954372410, "", ""] ],id logType eid orderId price amount extra date contractType direction 3977 3 "Futures_OKCoin" "" 0 0 "Sell(688.9, 2): 20016" 1526954372591 "" "" 3976 5 "" "" 0 0 "OKCoin:this_week 仓位过多, 多: 2" 1526954372410 "" "" extra为打印日志的附加信息。logType值对应的日志类型描述如下:logType: 0 1 2 3 4 5 6 logType意义: BUY SALE RETRACT ERROR PROFIT MESSAGE RESTART 中文意义 买入订单日志 卖出订单日志 撤单 错误 收益 消息 重启 -
数据库中的收益图表日志表
该图表日志表数据与策略日志表中的收益日志保持一致。plaintext"Arr": [ [202, 2515.44, 1575896700315], [201, 1415.44, 1575896341568] ]以其中一条日志数据为例:
plaintext[202, 2515.44, 1575896700315]202为日志ID,2515.44为收益数值,1575896700315为时间戳。 -
数据库中的图表日志表
plaintext"Arr": [ [23637, 0, "{\"close\":648,\"high\":650.5,\"low\":647,\"open\":650,\"x\":1575960300000}"], [23636, 5, "{\"x\":1575960300000,\"y\":3.0735}"] ]以其中一条日志数据为例:
plaintext[23637, 0, "{\"close\":648,\"high\":650.5,\"low\":647,\"open\":650,\"x\":1575960300000}"],23637为日志ID,0为图表数据系列索引,最后的数据"{\"close\":648,\"high\":650.5,\"low\":647,\"open\":650,\"x\":1575960300000}"为日志数据,该条数据为图表上的K线数据。

