양적 거래에서 효율적인 그룹 제어 관리를 위해 FMZ의 확장 API를 사용하는 것의 장점

저자:리디아, 창작: 2023-11-20 14:05:49, 업데이트: 2024-01-01 12:16:20

img

양적 거래의 대중화와 발전으로 인해 투자자는 종종 많은 수의 라이브 계정을 관리해야하며, 이는 거래 결정, 모니터링 및 실행에 큰 도전을 가져옵니다. 관리 효율성을 향상시키고 운영 어려움을 줄이기 위해 FMZ의 거래자는 그룹 제어 관리를 위해 FMZ의 확장 API를 사용할 수 있습니다. 이 기사에서는 양적 거래에서 FMZ의 확장 API를 사용하는 장점과 효율적인 그룹 제어 관리를 달성하는 방법을 논의 할 것입니다.

많은 사용자가 관리 및 유지 관리가 필요한 자신의 고객 라이브 계정을 가지고 있습니다. 많은 고객 라이브 계정이있을 때, 그들을 관리하기 위해 더 편리한 방법이 필요합니다. FMZ는 강력한 확장 API를 제공합니다. 그룹 제어 관리를 위해 이것을 사용하는 것이 이상적인 선택이되었습니다.

중앙 관측

FMZ의 확장 API를 통해 모든 라이브 계정의 거래 활동과 자산 상태를 중앙에서 모니터링 할 수 있습니다. 각 계정의 위치, 역사 거래 기록 또는 계정의 이익 및 손실 상태를 실시간으로 모니터링하는 것이든, 모든 것이 달성 될 수 있습니다.

// Global variable
var isLogMsg = true   // Control whether the log is printed
var isDebug = false   // Debug mode
var arrIndexDesc = ["all", "running", "stop"]
var descRobotStatusCode = ["In idle", "Running", "Stopping", "Exited", "Stopped", "Strategy error"]
var dicRobotStatusCode = {
    "all" : -1,
    "running" : 1,
    "stop" : 4,
}

// Extended log function
function LogControl(...args) {
    if (isLogMsg) {
        Log(...args)
    }
}

// FMZ extended API call function
function callFmzExtAPI(accessKey, secretKey, funcName, ...args) {
    var params = {
        "version" : "1.0",
        "access_key" : accessKey,
        "method" : funcName,
        "args" : JSON.stringify(args),
        "nonce" : Math.floor(new Date().getTime())
    }

    var data = `${params["version"]}|${params["method"]}|${params["args"]}|${params["nonce"]}|${secretKey}`
    params["sign"] = Encode("md5", "string", "hex", data)
    
    var arrPairs = []
    for (var k in params) {
        var pair = `${k}=${params[k]}`
        arrPairs.push(pair)
    }
    var query = arrPairs.join("&")
    
    var ret = null
    try {
        LogControl("url:", baseAPI + "/api/v1?" + query)
        ret = JSON.parse(HttpQuery(baseAPI + "/api/v1?" + query))
        if (isDebug) {
            LogControl("Debug:", ret)
        }
    } catch(e) {
        LogControl("e.name:", e.name, "e.stack:", e.stack, "e.message:", e.message)
    }
    Sleep(100)  // Control frequency
    return ret 
}

// Obtain all live trading information of the specified strategy Id.
function getAllRobotByIdAndStatus(accessKey, secretKey, strategyId, robotStatusCode, maxRetry) {
    var retryCounter = 0
    var length = 100
    var offset = 0
    var arr = []

    if (typeof(maxRetry) == "undefined") {
        maxRetry = 10
    }

    while (true) {
        if (retryCounter > maxRetry) {
            LogControl("Exceeded the maximum number of retries", 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
        }
        offset += length
    }

    return arr 
}

function main() {
    var robotStatusCode = dicRobotStatusCode[arrIndexDesc[robotStatus]]
    var robotList = getAllRobotByIdAndStatus(accessKey, secretKey, strategyId, robotStatusCode)
    if (!robotList) {
        Log("Failed to obtain live trading data")
    }
    
    var robotTbl = {"type": "table", "title": "live trading list", "cols": [], "rows": []}
    robotTbl.cols = ["live trading Id", "live trading name", "live trading status", "strategy name", "live trading profit"]

    _.each(robotList, function(robotInfo) {
        robotTbl.rows.push([robotInfo.id, robotInfo.name, descRobotStatusCode[robotInfo.status], robotInfo.strategy_name, robotInfo.profit])
    })

    LogStatus(_D(), "`" + JSON.stringify(robotTbl) + "`")
}

전략 매개 변수 설계

img

라이브 트레이딩으로 실행:

img

한 번의 클릭으로 실행

그룹 제어 관리는 한 번의 클릭으로 거래를 실행하는 것이 매우 편리합니다. 각 계정을 개별적으로 열지 않고 여러 라이브 거래 계좌에서 동시에 구매, 판매 및 포지션을 닫을 수 있습니다. 이것은 실행 효율성을 향상시킬뿐만 아니라 운영 오류의 가능성을 줄입니다.

라이브 트레이딩 계정의 목록을 얻은 후, 우리는 이러한 계정에 명령을 보내고 미리 결정된 일련의 작업을 수행 할 수 있습니다. 예를 들어: 라이브 계정의 클리어 포지션, 라이브 계정의 보호 중지, 라이브 계정의 모드 전환. 이 모든 것은 FMZ의 확장 API를 통해 달성 할 수 있습니다.CommandRobot.

코드를 계속 작성하면서, 우리는 단지 확장 API 인터페이스에 몇 가지 상호 작용과 호출을 추가해야합니다CommandRobot우리의 주요 기능:

function main() {
    var robotStatusCode = dicRobotStatusCode[arrIndexDesc[robotStatus]]
    var robotList = getAllRobotByIdAndStatus(accessKey, secretKey, strategyId, robotStatusCode)
    if (!robotList) {
        Log("Failed to obtain live trading data")
    }
    
    var robotTbl = {"type": "table", "title": "live trading list", "cols": [], "rows": []}
    robotTbl.cols = ["live trading Id", "live trading name", "live trading status", "strategy name", "live trading profit"]

    _.each(robotList, function(robotInfo) {
        robotTbl.rows.push([robotInfo.id, robotInfo.name, descRobotStatusCode[robotInfo.status], robotInfo.strategy_name, robotInfo.profit])
    })

    LogStatus(_D(), "`" + JSON.stringify(robotTbl) + "`")

    while(true) {
        LogStatus(_D(), ", Waiting to receive interactive commands", "\n", "`" + JSON.stringify(robotTbl) + "`")

        var cmd = GetCommand()
        if (cmd) {
            var arrCmd = cmd.split(":")
            if (arrCmd.length == 1 && cmd == "coverAll") {
                _.each(robotList, function(robotInfo) {
                    var strCmd = "Clearance"               // You can define the required message format
                    if (robotInfo.status != 1) {     // Only the "live" trading platform can receive commands.
                        return 
                    }
                    var ret = callFmzExtAPI(accessKey, secretKey, "CommandRobot", parseInt(robotInfo.id), strCmd)
                    LogControl("Send command to the live trading board with id: ", robotInfo.id, ":", strCmd, ", execution result:", ret)
                })
            }
        }
        Sleep(1000)
    }
}

img

그룹 제어 전략은 Test 1 ATest 1 B에 지시 사항을 보냈습니다.

img img

img img

전략 동기화

FMZ의 확장 API를 사용하면 전략 매개 변수들의 팩 변경을 쉽게 구현하고, 팩 시작 또는 라이브 트레이딩을 중지할 수 있습니다.

요약

양적 거래에서 FMZ의 확장 API를 사용하여 그룹 제어 관리를 통해 거래자는 여러 라이브 계정을 더 효율적으로 모니터링, 실행 및 조정할 수 있습니다. 이 중앙 집중식 관리 방법은 운영 효율성을 향상시킬뿐만 아니라 리스크 제어 및 전략 동기화를 더 잘 구현하는 데 도움이됩니다.

많은 수의 라이브 계정을 관리하는 거래자에게 FMZ의 확장 API는 양적 거래를 더 편리하고 제어 할 수있는 강력하고 유연한 도구를 제공합니다.


더 많은