FMZ에 기반한 순서 동기 관리 시스템 설계 (2)

저자:니나바다스, 창작: 2022-04-06 17:12:00, 업데이트: 2022-04-06 17:20:08

FMZ에 기반한 순서 동기 관리 시스템 설계 (2)

주문 동기 관리 시스템 (동시 서버)

지난 기사에서 토론을 계속해 보겠습니다.FMZ에 기반한 순서 동기 관리 시스템 설계 (1), 동시 순서 감독 전략을 수립합니다. 다음의 설계 질문들을 고려해 보세요.

  • 1. 잠시 동안 주문을 동기적으로 감독하고 싶지 않다면 중지 할 수 있습니까? 중단되면 확장 된 API에서 재시작을 비활성화하고 암호 검증을 사용하십시오. 이 함수를 구현하려면 2개의 글로벌 변수를 추가합니다.
    var isStopFollow = false   // used to mark whether to currently supervise orders or not 
    var reStartPwd = null      // used to record the restart password 
    

img

다음 전략 편집 페이지에 인터랙티브 컨트롤을 추가하여 전략을 중지 / 재시작합니다 (봇을 중지하는 것이 아니라 논리를 멈추고 아무것도하지 않고 명령을 따르지 않고 감독합니다). 중지 할 때, 중지 암호를 설정할 수 있습니다.Order Synchronous Management System Library (Single Server)확장된 API KEY의 경우, 그것은 당신의 전략을 호출할 수 없습니다. 주문을 감독하기 위해 재시작 할 때, 주문 감독 기능을 호출하기 위해 미리 설정된 암호를 입력합니다. 관련 기능의 구현 코드:

...
          // Judge the interactive command
          if (arr.length == 2) {
          	// Buttons with controls
          	if (arr[0] == "stop/restart") {
          		// Stop/restart to supervise orders 
          		if (!isStopFollow) {
          		    isStopFollow = true
          		    reStartPwd = arr[1]
          		    Log("stopped to supervise orders,", "the set restart password is:", reStartPwd, "#FF0000")
          		} else if (isStopFollow && arr[1] == reStartPwd) {
          			isStopFollow = false 
          			reStartPwd = null 
          			Log("restarted to supervise orders,", "clear the restart password.", "#FF0000")
          		} else if (isStopFollow && arr[1] != reStartPwd) {
          			Log("Wrong restart password!")
          		}
          	}
          	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) {
          // Switch the trading pair, and set contract 
          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), 등등

전략 코드:

이전 버전의 임시 코드Order Synchronous Management System (Synchronous Server)다음과 같습니다.

img

이제, 우리가 설계하는Order Synchronous Management System (Synchronous Server)다시 한 번:

// Global variables
var isStopFollow = false
var reStartPwd = null 

function trade(action) {
    // Switch the trading pair, and set contract
    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 = {}
	// Parse cmd, such as: 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() {
	// Clear all logs 
    LogReset(1)  

    if (isSimulateOKEX) {
    	exchange.IO("simulate", true)
    	Log("Switch to OKEX simulated bot!")
    }

    // set precision 
    exchange.SetPrecision(pricePrecision, amountPrecision)

    // Check specifiedAmount and zoomAmountRatio, for they cannot be set at the same time 
    if (specifiedAmount != -1 && zoomAmountRatio != -1) {
    	throw "cannot set specifiedAmount and zoomAmountRatio at the same time"
    }

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

            // Judge the interactive command 
            if (arr.length == 2) {
            	// Buttons with controls 
            	if (arr[0] == "stop/restart") {
            		// Stop/restart to supervise orders 
            		if (!isStopFollow) {
            		    isStopFollow = true
            		    reStartPwd = arr[1]
            		    Log("stopped to supervise orders,", "the set restart password is:", reStartPwd, "#FF0000")
            		} else if (isStopFollow && arr[1] == reStartPwd) {
            			isStopFollow = false 
            			reStartPwd = null 
            			Log("restarted to supervise orders,", "Clear the restart password", "#FF0000")
            		} else if (isStopFollow && arr[1] != reStartPwd) {
            			Log("Wrong restart password!")
            		}
            	}
            	continue 
            }
            
            // Allow to supervise orders 
            if (!isStopFollow) {
                // Parse the interactive command of the order supervising signal
                var objAction = parseCmd(cmd)
                if (objAction) {
            	    // Parse correctly 
            	    var ret = trade(objAction)
                } else {
                	Log("Wrong signal cmd:", cmd)
                }
            }
        }
        
        // Display the order supervising status 
        LogStatus(_D(), isStopFollow ? "Stop synchronization" : "Maintain synchronization", "\n")

        Sleep(1000)
    }
}

테스트

이 시간, Binance 실제 틱 테스트는 주문을 가진 계정에 사용되고, OKEX 계정은 주문 감독 봇에 사용됩니다. 주문 감독을 위해, 우리는 여전히 이전 기사에서 사용 된 테스트 기능을 사용합니다 (main기능Order Synchronous Management System Library (Single Server)템플릿)

img

그것은 단지 우리가 짧은 거래 방향을 변경하고 거래 부피는 0.003로 변경되었습니다 (Binance USDT 마진 계약은 소수점으로 배치 될 수 있습니다). 그러나 명령어와 함께 OKEX 계정은 정수여야 합니다 (OKEX에 의해 배치 된 명령어는 정수 숫자가 있어야합니다), 그래서 매개 변수는 전략 매개 변수를 지정합니다specifiedAmount1로

img

테스트 기능의 봇Order Synchronous Management System Library (Single Server)거래가 시작되었습니다.

img

명령어 감독 bot 전략은 신호를 받아, 감독 작업을 실행:

img

플랫폼은 해당 주문을 열었습니다.

img

다음으로, 닫는 위치를 테스트하고, 0.003의 짧은 위치를 닫기 위해 주 함수에서 순서 방향을 변경합니다.

img

그 다음 명령을 수행하는 역할을 하는 로봇을 다시 시작 (Order Synchronous Management System Library (Single Server)).

img

같은 작업은 또한 명령어 감독 bot에서 발생:

img

전략 주소:주문 동기 관리 시스템 라이브러리 (단독 서버) 주문 동기 관리 시스템 (동시 서버)

그 전략은 의사소통과 연구에만 사용되는데 실제 사용하려면 스스로 수정, 조정, 최적화해야 합니다.


더 많은