FMZをベースに量化されたオーダーシンクロマネジメントシステムの設計 (2)

作者: リン・ハーン小さな夢, 作成日:2022-02-16 12:11:36, 更新日:2023-09-15 20:46:46

img

FMZをベースに量化されたオーダーシンクロマネジメントシステムの設計 (2)

同期管理システム (Synchronous Server)

この記事へのトラックバック一覧です.FMZをベースに量化されたオーダーシンクロマネジメントシステムの設計 (1)シンクロリストの策略を策定し始めた.

デザインの課題は,

  • 1、一時的にアカウントを同期したくない場合は,一時停止できますか.一時停止すると,拡張APIから起動し,パスワード認証を使用することを禁止します. この機能を実現するには,2つのグローバル変数を追加します.

    var isStopFollow = false   // 用于标记当前是否跟单
    var reStartPwd = null      // 用于记录重启密码
    

    img

    ポリシーの編集ページに,ポリシーの停止/再起動 (このディスクを停止するのではなく,論理的な停止,リストを停止し,何もしない) のためのインタラクティブなコントロールを追加します. 停止時に停止パスワードを設定できます.订单同步管理系统类库(Single Server)ディスクトップもあなたのポリシーを目覚めさせることができない. リストを再起動する際に,既定のパスワードを入力してリスト機能を目覚めさせる. 関連機能の実装コード:

    ...
              // 判断交互指令
              if (arr.length == 2) {
              	// 带控件的按钮
              	if (arr[0] == "stop/restart") {
              		// 暂停/重启跟单
              		if (!isStopFollow) {
              		    isStopFollow = true
              		    reStartPwd = arr[1]
              		    Log("已经停止跟单,", "设置的重启密码为:", reStartPwd, "#FF0000")
              		} else if (isStopFollow && arr[1] == reStartPwd) {
              			isStopFollow = false 
              			reStartPwd = null 
              			Log("已经重启跟单,", "清空重启密码。", "#FF0000")
              		} else if (isStopFollow && arr[1] != reStartPwd) {
              			Log("重启密码错误!")
              		}
              	}
              	continue 
              }
    
  • 2 リストの次元のサイズを指定したり,倍数拡大したりできます. 策略にパラメータを追加します:

    img

    specifiedAmount: リストの数を指定します. デフォルトでは−1,つまり指定していません. zoomAmountRatio: 送信された信号の下位単位のスケーリング,例えば送信された信号は:ETH_USDT,swap,buy,1単位の値をzoomAmountRatioで掛けます. デフォルトでは−1,つまり拡大しない.

        var amount = specifiedAmount == -1 ? action.amount : specifiedAmount
        amount = zoomAmountRatio == -1 ? amount : amount * zoomAmountRatio
    

    信号が受信されたときに必要な量です.拡大可能性は特定の値を指定する

  • 3, コードをできるだけ簡素化し,下記の処理は他のテンプレートクラスライブラリを使用します.

    オンラインショップの利用者:https://www.fmz.com/strategy/10989フューチャー下注の利用カテゴリ:https://www.fmz.com/strategy/203258

      function trade(action) {
          // 切换交易对,设置合约
          exchange.SetCurrency(action.symbol)
          if (action.ct != "spot") {
              exchange.SetContractType(action.ct)        
          }        
    
          var retTrade = null 
          var amount = specifiedAmount == -1 ? action.amount : specifiedAmount
          amount = zoomAmountRatio == -1 ? amount : amount * zoomAmountRatio    
    
          if (action.direction == "buy") {
              retTrade = action.ct == "spot" ? $.Buy(amount) : $.OpenLong(exchange, action.ct, amount)
          } else if (action.direction == "sell") {
              retTrade = action.ct == "spot" ? $.Sell(amount) : $.OpenShort(exchange, action.ct, amount)
          } else if (action.direction == "closebuy") {
              retTrade = action.ct == "spot" ? $.Sell(amount) : $.CoverLong(exchange, action.ct, amount)
          } else if (action.direction == "closesell") {
              retTrade = action.ct == "spot" ? $.Buy(amount) : $.CoverShort(exchange, action.ct, amount)
          }
          return retTrade
      }
    

    この記事へのトラックバック一覧です.$.Sell(amount)$.Buy(amount)$.OpenLong(exchange, action.ct, amount)ほら ほら

戦略コード:

前の記事订单同步管理系统(Synchronous Server)暫定コードは以下の通りです.

img

デザインを改めよう订单同步管理系统(Synchronous Server)

// 全局变量
var isStopFollow = false
var reStartPwd = null 

function trade(action) {
    // 切换交易对,设置合约
    exchange.SetCurrency(action.symbol)
    if (action.ct != "spot") {
        exchange.SetContractType(action.ct)        
    }    

    var retTrade = null 
    var amount = specifiedAmount == -1 ? action.amount : specifiedAmount
    amount = zoomAmountRatio == -1 ? amount : amount * zoomAmountRatio

    if (action.direction == "buy") {
        retTrade = action.ct == "spot" ? $.Buy(amount) : $.OpenLong(exchange, action.ct, amount)
    } else if (action.direction == "sell") {
    	retTrade = action.ct == "spot" ? $.Sell(amount) : $.OpenShort(exchange, action.ct, amount)
    } else if (action.direction == "closebuy") {
    	retTrade = action.ct == "spot" ? $.Sell(amount) : $.CoverLong(exchange, action.ct, amount)
    } else if (action.direction == "closesell") {
    	retTrade = action.ct == "spot" ? $.Buy(amount) : $.CoverShort(exchange, action.ct, amount)
    }
    return retTrade
}

function parseCmd(cmd) {
	var objAction = {}
	// 解析cmd ,例如:ETH_USDT,swap,buy,1
    var arr = cmd.split(",")
    if (arr.length != 4) {
    	return null 
    }
    objAction.symbol = arr[0]
    objAction.ct = arr[1]
    objAction.direction = arr[2]
    objAction.amount = arr[3]
    return objAction
}

function main() {
	// 清除所有日志
    LogReset(1)  

    if (isSimulateOKEX) {
    	exchange.IO("simulate", true)
    	Log("切换到OKEX模拟盘!")
    }

    // 设置精度
    exchange.SetPrecision(pricePrecision, amountPrecision)

    // 检查缩放、指定不能同时设置
    if (specifiedAmount != -1 && zoomAmountRatio != -1) {
    	throw "不能同时指定同步量和缩放量"
    }

    while (true) {
        var cmd = GetCommand()
        if (cmd) {
            Log("cmd: ", cmd)
            var arr = cmd.split(":")

            // 判断交互指令
            if (arr.length == 2) {
            	// 带控件的按钮
            	if (arr[0] == "stop/restart") {
            		// 暂停/重启跟单
            		if (!isStopFollow) {
            		    isStopFollow = true
            		    reStartPwd = arr[1]
            		    Log("已经停止跟单,", "设置的重启密码为:", reStartPwd, "#FF0000")
            		} else if (isStopFollow && arr[1] == reStartPwd) {
            			isStopFollow = false 
            			reStartPwd = null 
            			Log("已经重启跟单,", "清空重启密码。", "#FF0000")
            		} else if (isStopFollow && arr[1] != reStartPwd) {
            			Log("重启密码错误!")
            		}
            	}
            	continue 
            }
            
            // 允许跟单
            if (!isStopFollow) {
                // 解析跟单信号交互指令
                var objAction = parseCmd(cmd)
                if (objAction) {
            	    // 解析正确
            	    var ret = trade(objAction)
                } else {
                	Log("错误的信号指令 cmd:", cmd)
                }
            }
        }
        
        // 显示跟单情况
        LogStatus(_D(), isStopFollow ? "停止同步" : "保持同步", "\n")

        Sleep(1000)
    }
}

テスト

このバンドアカウントはBinance実装台でテストされ,支払いの実装台はOKEXアカウントでテストされました. バンドは,前回の記事で使用したテスト関数をまだ使用しています.订单同步管理系统类库(Single Server)テンプレートmainこの関数は,

img

しかし,取引方向を空に変更し,取引量は0.003に変更します. しかし,OKEXアカウントのレジは整数でなければなりません. だからパラメータは,私は戦略パラメータを指定します.specifiedAmount1、2、3、3、4、4、4、4、4、4、4、4、4、4、4、4、4、4、4、4、4、4、4、4、4、4

img

订单同步管理系统类库(Single Server)テスト機能のリアルディスクが取引を誘発します.

img

フォローする実態ディスクの戦略は信号を受け,フォローする動作を実行します.

img

取引所が対応するオーダーを発行した.

img

次に,平行状態をテストし,テスト main の下の一番下の方向を平行状態に変えて空頭位置 0.003 を削除します.

img

ビデオのビデオは,このビデオのビデオのビデオのビデオです.订单同步管理系统类库(Single Server))。

img

コンピュータの操作は,コンピュータの操作と,コンピュータの操作と,

img

戦略アドレスは:注文同期管理システムクラスデータベース (Single Server) 同期管理システム (Synchronous Server)

戦略設計は交流学習のみであり,実際の生産は自己修正,調整,最適化が必要である.


関連性

もっと