Terdapat dua kaedah pengesahan apabila memanggil antara muka API yang dilanjutkan, menyokongtoken
pengesahan dan pengesahan langsung.
Penggunaanmd5
kaedah penyulitan untuk disahkan, contohPython
, Golang
Panggilan bahasa:
#!/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()
# Note: for the timeout problem of "urllib2.urlopen" function, you can set the timeout time; for example, urllib2.urlopen ('https://www.fmz.com/api/v1', urlencode(d).encode('utf-8'), timeout = 10), that is, set timeout for 10 seconds
return json.loads(urllib2.urlopen('https://www.fmz.com/api/v1', urlencode(d).encode('utf-8')).read().decode('utf-8'))
# Return the docker list
print(api('GetNodeList'))
# Return the exchange list
print(api('GetPlatformList'))
# GetRobotList(offset, length, robotStatus, label), passing "-1" means obtaining all
print(api('GetRobotList', 0, 5, -1, 'member2'))
# CommandRobot(robotId, cmd) sends command to live trading
print(api('CommandRobot', 123, 'ok'))
# StopRobot(robotId) returns the live trading status code
print(api('StopRobot', 123))
# RestartRobot(robotId) returns the live trading status code
print(api('RestartRobot', 123))
# GetRobotDetail(robotId) returns detailed live trading information
print(api('GetRobotDetail', 123))
package main
import (
"fmt"
"time"
"encoding/json"
"crypto/md5"
"encoding/hex"
"net/http"
"io/ioutil"
"strconv"
"net/url"
)
// Fill in your own FMZ platform api key
var apiKey string = ""
// Fill in your own FMZ platform secret key
var secretKey string = ""
var baseApi string = "https://www.fmz.com/api/v1"
func api(method string, args ... interface{}) (ret interface{}) {
// Process args
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-line period parameter, "60" means 60 seconds
"period": 60,
"node" : 73938,
"appid": "member2",
"exchanges": []interface{}{
map[string]interface{}{
"eid": "Exchange",
"label" : "test_bjex",
"pair": "BTC_USDT",
"meta" : map[string]interface{}{
// Fill in the access key
"AccessKey": "",
// Fill in the secret key
"SecretKey": "",
"Front" : "http://127.0.0.1:6666/exchange",
},
},
},
}
method := "RestartRobot"
fmt.Println("Call interface:", method)
ret := api(method, 124577, settings)
fmt.Println("main ret:", ret)
}
Ia menyokong pengesahantoken
(mengalir)secret_key
anda boleh menjana URL yang boleh diakses secara langsung.
contohnya, URL yang secara langsung memberikan arahan interaktif untuk
perdagangan langsung, yang boleh digunakan untukTradingView
atauWebHook
panggilan balik dalam kes lain.CommandRobot(RobotId, Cmd)
fungsi, parameternonce
tidak memerlukan pengesahan, dan kekerapan akses dan
masa lawatan antara muka tidak terhad.
Sebagai contoh,AccessKey
dari sambungan yang diciptaAPI KEY
ialah:xxx
danSecretKey
ialah:yyy
. Lihat pautan berikut untuk menghantar mesej arahan interaktif ke
perdagangan langsung dengan ID perdagangan langsung186515
, mesej
content adalah rentetan:"ok12345"
.
https://www.fmz.com/api/v1?access_key=xxx&secret_key=yyy&method=CommandRobot&args=[186515,"ok12345"]
Di bawah keadaan bahawa pengesahan langsung disokong,
HanyaCommandRobot
antara muka disokong untuk mendapatkanBody
data dalam permintaan. Sebagai contoh, tetapan dalamWebHook URL
daripadaTradingView
:
https://www.fmz.com/api/v1?access_key=xxx&secret_key=yyy&method=CommandRobot&args=[186515,+""]
Berhati-hati untuk menetapkan mengikut format berikut:args=[130350,+""]
, di mana130350
adalah perdagangan secara langsungID
dari Platform Dagangan Kuantum FMZ.
Tetapkan dalam kotak mesejTrading View
(yang diminta
Format JSON:
{"close": {{close}}, "name": "aaa"}
Perdagangan langsung denganID
daripada186515
boleh menerima rentetan arahan interaktif:{"close": 39773.75, "name": "aaa"}
.
Format teks:
BTCUSDTPERP Crossing 39700.00 close: {{close}}
Perdagangan langsung denganID
daripada186515
boleh menerima rentetan arahan interaktif:BTCUSDTPERP Crossing 39700.00 close: 39739.4
.
ContohPython
& Golang
Panggilan bahasa:
#!/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'))
# If APIKEY does not have the interface permission, the call to
print(api('RestartRobot', 186515)) will fail, and the returned data
is: {'code': 4, 'data': None}
# print(api('RestartRobot', 186515))
# Printed Id: the live trading details of 186515
print(api('GetRobotDetail', 186515))
package main
import (
"fmt"
"encoding/json"
"net/http"
"io/ioutil"
"net/url"
)
// Fill in your own FMZ platform api key
var apiKey string = "your access_key"
// Fill in your own FMZ platform 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("Call interface:", method)
ret := api(method, 186515)
fmt.Println("main ret:", ret)
}
Gunakan API lanjutan di FMZ Quant untuk merealisasikan amaran