Halo semua, saya
Artikel ini terutamanya memperkenalkan:
1) Memohon AccessKey dan SecretKey (selepas ini dirujuk sebagai AK dan SK). Kami memohon dalam menu [Akaun] -> [ApiKey] -> [Buat ApiKey Baru] di laman web rasmi FMZ, dan kemudian mendapatkan dan merakam kumpulan AK dan SK. (AK dan SK di FMZ kelihatan, kita boleh melihat data penuh AK dan SK dalam menu [API Interface] pada bila-bila masa.)
2) Membangunkan mengikut dokumen API yang diperluaskan Pertama, mari kita lihat langkah-langkah utama API permintaan.
https://www.fmz.com/api/v1
{
'version' : '1.0', //Custom version number
'access_key': '8a148320e0bxxxxxxxxxxxxxx19js99f', //AK
'method' : 'GetNodeList', //The specific method to call
'args' : [], //List of parameters for the specific method algorithm
'nonce' : 1516292399361, //Timestamp, in milliseconds
'sign' : '085b63456c93hfb243a757366600f9c2' //Signature (need to be encrypted according to the above 5 parameters to obtain, as discussed below)
}
Take the GetNodeList method as an example:
https://www.fmz.com/api/v1?
access_key=8a148320e0bxxxxxxxxxxxxxx19js99f&
nonce=1516292399361&
args=%5B%5D&
sign=085b63456c93hfb243a757366600f9c2&
version=1.0&
method=GetNodeList
After the parameters are spliced in the following order, the MD5 encryption algorithm is used to encrypt the string and convert it to a hexadecimal data string value, which is used as the value of the parameter sign.
version + "|" + method + "|" + args + "|" + nonce + "|" + secretKey
var URL = "https://www.fmz.com/api/v1?";
var AK = "b3a53d3XXXXXXXXXXXXXXXXXXX866fe5";//Replace here with your own AccessKey
var SK = "1d9ddd7XXXXXXXXXXXXXXXXXXX85be17";//Replace here with your own SecretKey
function main() {
//Get 5 basic parameter objects
var param = getParam("1.0.0",AK,getArgs());
Log("param:",param);
//Get the result after md5 encryption of splicing parameters
var md5Result = md5(param);
//Assign the encryption result to the basic parameter object
param.sign = md5Result;
//Get the URL of the request api
var finalUrl = getFinalUrl(param);
Log("finalUrl:",finalUrl);
//Execute the request and print the results
var info = HttpQuery(finalUrl);
Log("info:",info);
}
//Get 5 basic parameter objects
function getParam(version,ak,args){
return {
'version': version,
'access_key': ak,
'method': 'GetNodeList',
'args': JSON.stringify(args),
'nonce': new Date().getTime()
}
}
//Execute md5 encryption
function md5(param){
var paramUrl = param.version+"|"+param.method+"|"+param.args+"|"+param.nonce+"|"+SK
Log("paramUrl:",paramUrl);
return Hash("md5", "hex", paramUrl)
}
//Get the final request URL
function getFinalUrl(param){
return URL+"access_key="+AK+"&nonce="+param.nonce+"&args="+param.args+"&sign="+param.sign+"&version="+param.version+"&method="+param.method;
}
//The naming method of... args is not supported in js, so the arguments keyword is used instead to obtain the parameter array
function getArgs(){
return [].slice.call(arguments);
}
Berdasarkan kod di atas, kita akan menggunakan kaedah CommandRobot untuk mencapai komunikasi mesej antara robot.
Pertama, mari kita lihat dua parameter yang diperlukan oleh kaedah CommandRobot (RobotId, Cmd):
Nama Parameter | Jenis | Makna |
---|---|---|
RobotId | int | Robot ID, yang boleh diperolehi dengan GetRobotList (...) atau pada halaman butiran robot |
Cmd | String | Mesej dihantar ke robot |
Sekarang kita tahu maksud parameter, mari kita melaksanakan kaedah panggilan.
Dapatkan ID robot di halaman butiran robot
Melaksanakan kaedah mendapatkan mesej Cmd
//Get message header information
function getMessageBody(toUserName,msgType,content){
return ({
"toUserName":toUserName,//Who to send to
"fromUserName":AOKE_INFO,//Source
"createTime": new Date().getTime(),//Current timestamp
"msgType":msgType,//Message Type
"content":content,//Message content
"msgId":Math.random().toString(36).slice(-8)//Message ID
})
}
//Get message body trend information (data of message header content field)
function getCtaDate(symbol,timeCycle,direction,nowCycleTime){
return {
"symbol":symbol,//Trading currency
"timeCycle":timeCycle,//Trend cycle
"direction":direction,//Current entry direction, 0: berish, 1: bullish
"createTime":new Date().getTime(),//Current timestamp
"nowCycleTime":nowCycleTime//Start time of current cycle
}
}
//Get messages before sending them
var sendMessage = getMessageBody("Test object",'CTARemind',getCtaDate('BTC_USDT','120','0','2020-05-1620:00:00'));
//Get the robot ID and message body through the getArgs() method, and pass in the basic parameters.
var param = getParam("1.0.0",AK,getArgs(17777,sendMessage));
function main(){
while(true) {
var cmd = GetCommand()
if (cmd) {
Log(cmd)
}
Sleep(1000)
}
}
Mesej dihantar dengan berjaya:
Mesej diterima dengan berjaya:
Begitu juga, mari kita lihat dahulu deskripsi parameter dua kaedah seterusnya GetRobotList ((offset, panjang, robotStatus, label):
Nama Parameter | Jenis | Makna |
---|---|---|
penyesuaian | int | Nombor halaman pertanyaan |
panjang | int | Panjang data halaman pertanyaan |
robotStatus | int | Pas in - 1 untuk mendapatkan semua |
label | String | Tag tersuai boleh menapis semua robot dengan tag ini |
GetRobotDetail ((RobotId):
Nama Parameter | Jenis | Makna |
---|---|---|
RobotId | int | Robot ID |
//Get robot list information
var robotListJson = getAPIInfo('GetRobotList',getArgs(OFF_SET,PAGE_LENGTH,-1));
var robotList = robotListJson.data.result.robots;
//Get robot detail information
var robotDetailJson = getAPIInfo('GetRobotDetail',getArgs(robotId));
var robotDetail = robotDetailJson.data.result.robot;
function getLogPrient(infoArr){
return table = {
type: 'table',
title: 'Oak Quant robot display',
cols: [''Robot ID', 'Robot name', 'Strategy name', 'Next deduction time', 'Consumed time ms', 'Consumed amount CNY', 'Latest active time', 'Publish or not'],
rows: infoArr
};
}
var URL = "https://www.fmz.com/api/v1?";
var AK = "b3a53d3XXXXXXXXXXXXXXXXXXX866fe5";//Replace here with your own AccessKey
var SK = "1d9ddd7XXXXXXXXXXXXXXXXXXX85be17";//Replace here with your own SecretKey
var OFF_SET = 0;//Page number subscript of query
var PAGE_LENGTH = 5;//Data length of the query page
function main() {
LogReset();
while(true){
//Get robot list information
var robotListJson = getAPIInfo('GetRobotList',getArgs(OFF_SET,PAGE_LENGTH,-1));
//Get the robot list information
var robotList = robotListJson.data.result.robots;
//Create an array to display robot information
var infoArr = new Array();
var infoArr_index = 0;
for (index = 0; index < robotList.length; index++) {
var robot = robotList[index];
//Get the robot ID of the current loop
var robotId = robot.id;
//Get robot detail information
var robotDetailJson = getAPIInfo('GetRobotDetail',getArgs(robotId));
var robotDetail = robotDetailJson.data.result.robot;
//Convert details to array objects
var arr = getLogPrientItem(robotDetail);
infoArr[infoArr_index] = arr;
infoArr_index++;
}
Log("infoArr:",infoArr);
LogStatus('`' + JSON.stringify(getLogPrient(infoArr)) + '`');
Sleep(30000);
}
}
function getLogPrient(infoArr){
return table = {
type: 'table',
title: 'Oak Quant robot display',
cols: [''Robot ID', 'Robot name', 'Strategy name', 'Next deduction time', 'Consumed time ms', 'Consumed amount CNY', 'Latest active time', 'Publish or not'],
rows: infoArr
};
}
//Get API information by parameters
function getAPIInfo(method,dateInfo){
//Get 5 basic parameter objects
var param = getParam("1.0.0",AK,method,dateInfo);
//Log("param:",param);
//Get the result after md5 encryption of splicing parameters
var md5Result = md5(param);
//Assign the encryption result to the basic parameter object
param.sign = md5Result;
//Get the URL of the request api
var finalUrl = getFinalUrl(param);
//Log("finalUrl:",finalUrl);
//Execute the request and print the results
var info = HttpQuery(finalUrl);
//Log("info:",info);
return JSON.parse(info);
}
//Get the object of the basic 5 parameters
function getParam(version,ak,method,args){
return {
'version': version,
'access_key': ak,
'method': method,
'args': JSON.stringify(args),
'nonce': new Date().getTime()
}
}
//Execute md5 encryption
function md5(param){
var paramUrl = param.version+"|"+param.method+"|"+param.args+"|"+param.nonce+"|"+SK
//Log("paramUrl:",paramUrl);
return Hash("md5", "hex", paramUrl)
}
//Get the final request URL
function getFinalUrl(param){
return URL+"access_key="+AK+"&nonce="+param.nonce+"&args="+param.args+"&sign="+param.sign+"&version="+param.version+"&method="+param.method;
}
//The naming method of... args is not supported in js, so the arguments keyword is used instead to obtain the parameter array
function getArgs(){
return [].slice.call(arguments);
}
//Get the display details object: ['Robot ID', 'Robot Name', 'Strategy Name', 'Next Deduction Time', 'Time Consumed ms', 'Amount Consumed CNY', 'Latest Active Time', 'Whether to Publish'],
function getLogPrientItem(robotDetail){
var itemArr = new Array();
var iteArr_index = 0;
itemArr[iteArr_index++] = robotDetail.id;
itemArr[iteArr_index++] = robotDetail.name;
itemArr[iteArr_index++] = robotDetail.strategy_name;
itemArr[iteArr_index++] = robotDetail.charge_time;
itemArr[iteArr_index++] = robotDetail.charged;
itemArr[iteArr_index++] = robotDetail.consumed/1e8;
itemArr[iteArr_index++] = robotDetail.refresh;
itemArr[iteArr_index++] = robotDetail.public == 0?"Published":"Unpublished";
return itemArr;
}
Dalam sambungan sebenar, lebih banyak fungsi yang menarik dapat direalisasikan. Sebagai contoh, menggunakan kaedah CommandRobot, setiap robot menghantar pengesanan denyutan jantung kepada robot A. Jika robot A mendapati bahawa mesin tidak mempunyai denyutan jantung, tetapi robot masih berjalan, ia boleh memberi penggera melalui perkhidmatan FMZ. Dengan cara ini, penggera seperti _C() gelung mati yang membawa kepada senario kematian palsu program dapat dielakkan. Saya harap melalui pengenalan saya kali ini, platform FMZ boleh mempunyai lebih banyak fungsi yang menarik untuk dibangunkan dan dibuka. Akhirnya, saya ingin mengucapkan terima kasih kepada platform FMZ dan semua orang hebat seperti Xiaoxiaomeng, Encik Zhang dan Encik Z atas sokongan dan bantuan mereka.