FMZの拡張APIの活用の利点 量的な取引における効率的なグループコントロール管理

作者: リン・ハーンリディア作成日:2023年11月20日 14:05:49 更新日:2024年1月1日 12:16:20

img

定量取引の普及と発展とともに,投資家はしばしば大量のライブアカウントを管理する必要があるため,取引決定,監視および実行に大きな課題をもたらします.管理効率を向上させ,運用困難を軽減するために,FMZのトレーダーはグループ制御管理のためにFMZの拡張APIを使用できます.この記事では,定量取引におけるFMZの拡張APIの使用の利点と効率的なグループ制御管理を達成する方法について議論します.

FMZは,多くのユーザーに,管理および維持を必要とする独自の顧客ライブアカウントがあります.多くの顧客ライブアカウントがある場合,それらを管理するためのより便利な方法 (数十個または数百個ほど) が必要です. 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

1 クリックで実行

グループコントロール管理は,一クリックで取引を実行することを非常に便利にします.各アカウントを個別に開く必要なく,複数のライブ取引アカウントで同時に購入,販売,取引を終了することができます.これは実行効率を向上させるだけでなく,運用エラーの可能性を軽減します.

ライブ取引アカウントのリストを取得した後,これらのアカウントにコマンドを送信し,事前に決定された一連の操作を実行することができます.例えば: ライブアカウントのクリアリングポジション, ライブアカウントの保護を一時停止し, ライブアカウントのモードを切り替える.これらはすべて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

グループ制御戦略は,テスト1Aとテスト1Bに指示を送った.

img img

img img

戦略の同期

FMZの拡張APIにより,戦略パラメータのバッチ変更を簡単に実装し,バッチ開始またはライブ取引を停止できます.

概要

定量取引では,グループ制御管理のためのFMZの拡張APIを使用して,トレーダーは複数のライブアカウントをより効率的に監視,実行,調整することができます.この集中管理方法は,運用効率を向上させるだけでなく,リスク管理と戦略の同期をよりよく実施するのに役立ちます.

FMZの拡張APIは,多くの実用口座を管理しているトレーダーに,定量取引をより便利で制御可能な強力で柔軟なツールを提供します.


もっと