advertisement
Teach You to Use the FMZ Extended API to Batch Modify Parameters of the Bot
How can I change the parameters of batch live trading in FMZ? When the number of live operations exceeds dozens and reaches hundreds, it would be very inconvenient to set up live operations one by one manually. At this time, we can use the FMZ extended API to complete these operations. So, in this article, we will explore the bot group control and update some parameter details.
In the previous article, we solved the problem of how to use the FMZ extended API to monitor all live operations, group control live operations, and send commands to live operations. And we still use the interface calling code we encapsulated in the previous article as a basis, and continue to write code to realize batch modification of live trading parameters.
Parameter settings:
Strategy code:
// global variables
var isLogMsg = true // Controls whether logs are printed or not
var isDebug = false // Debug mode
var arrIndexDesc = ["all", "running", "stop"]
var descRobotStatusCode = ["Idle", "Running", "Stopping", "Exited", "Stopped", "There is an error in the strategy"]
var dicRobotStatusCode = {
"all": -1,
"running": 1,
"stop": 4,
}
// Extended logging functions
function LogControl(...args) {
if (isLogMsg) {
Registration(...arguments)
}
}
// FMZ extended API call functions
function callFmzExtAPI(accessKey, secretKey, funcName, ...args) {
var parameters = {
"version": "1.0",
"access_key": access key,
"method": functionname,
"arguments": JSON.stringify(arguments),
"nonce": Math.floor(new Date().getTime())
}
var data = `${params["version"]}|${params["method"]}|${params["args"]}|${params["nonce"]}|${secretKey}`
params["sign"] = Encode("md5", "string", "hexadecimal", data)
var arrPairs = []
for (var k in parameters) {
var even = `${k}=${params[k]}`
arrPairs.push(pair)
}
query var = arrPairs.join("&")
var ret = null
test {
LogControl("url:", baseAPI + "/api/v1?" + query)
ret = JSON.parse(HttpQuery(baseAPI + "/api/v1?" + query))
if (esDebug) {
LogControl("Debug:", ret)
}
} capture(e) {
LogControl("e.name:", e.name, "e.stack:", e.stack, "e.message:", e.message)
}
Sleep(100) // Control frequency
return
}
// Get information about all running bots for the specified strategy ID.
function getAllRobotByIdAndStatus(accessKey, secretKey, StrategyId, robotStatusCode, maxRetry) {
var retryCount = 0
variable length = 100
var offset = 0
vararr = []
if (typeof(maxRetry) == "undefined") {
max retry = 10
}
while (true) {
if (retryCounter > maxRetry) {
LogControl("Maximum number of retries exceeded", maxRetry)
return null
}
var ret = callFmzExtAPI(accessKey, secretKey, "GetRobotList", offset, length, robotStatusCode)
if (!ret || ret["code"] != 0) {
Sleep(1000)
retryCounter++
continue
}
var robots = ret["data"]["result"]["robots"]
for (var i in robots) {
if (robots[i].strategy_id != strategyId) {
continue
}
arr.push(robots[i])
}
if (robots.length < length) {
break
}
displacement += length
}
return
}
First learn about the RestartRobot function of the FMZ extended API
When we need to batch modify the parameters of the actual trade and then execute it, to begin with, there are 2 cases for this scenario.
- 1. The bot has been created. For a live operation that has already been created, it is natural to restart it using the RestartRobot function, which is an extended API interface for FMZ.
- 2. The bot has not been created. So that the live trade has not been created, there is no need to "modify" the parameters of the live trade, that is the batch creation of the live trade to execute, and we use the extended API interface FMZ - NewRobot function.
But no matter what kind of method, the following idea and operation are similar, so we will use the RestartRobot extended API function as an example to explain.
The RestartRobot function is used in two ways:
- 1. Setup with only the live trade ID, not the parameter
advertisement
Related Articles
advertisement