एफएमजेड आधारित ऑर्डर सिंक्रोनस मैनेजमेंट सिस्टम डिजाइन (2)

लेखक:निनाबादास, बनाया गयाः 2022-04-06 17:12:00, अद्यतन किया गयाः 2022-04-06 17:20:08

एफएमजेड आधारित ऑर्डर सिंक्रोनस मैनेजमेंट सिस्टम डिजाइन (2)

ऑर्डर सिंक्रोनस मैनेजमेंट सिस्टम (सिंक्रोनस सर्वर)

आइए पिछले लेख में चर्चा जारी रखें:एफएमजेड आधारित ऑर्डर सिंक्रोनस मैनेजमेंट सिस्टम डिजाइन (1), एक सिंक्रोन ऑर्डर पर्यवेक्षण रणनीति तैयार करने के लिए। कृपया निम्नलिखित डिजाइन प्रश्नों पर विचार करें:

  • 1.यदि आप कुछ समय के लिए ऑर्डर की सिंक्रोनस निगरानी नहीं करना चाहते हैं, तो क्या इसे रोक दिया जा सकता है? एक बार यह बंद हो जाने के बाद, विस्तारित एपीआई से पुनरारंभ को अक्षम करें, और पासवर्ड सत्यापन का उपयोग करें। इस फ़ंक्शन को लागू करने के लिए, 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)अपने विस्तारित एपीआई कुंजी के, यह अपनी रणनीति को कॉल करने में सक्षम नहीं होगा. आदेश पर्यवेक्षण करने के लिए पुनरारंभ करते समय, आदेश पर्यवेक्षण समारोह को कॉल करने के लिए पूर्व निर्धारित पासवर्ड दर्ज करें. संबंधित फ़ंक्शन का कार्यान्वयन कोडः

...
          // 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 है, अर्थात् नहीं zoomed।

        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)
    }
}

परीक्षण

इस बार, आदेशों के साथ खाते के लिए बिनेंस वास्तविक टिक परीक्षण का उपयोग किया जाता है, और ऑर्डर पर्यवेक्षण बॉट के लिए ओकेएक्स खाते का उपयोग किया जाता है। ऑर्डर पर्यवेक्षण के लिए, हम अभी भी पिछले लेख में उपयोग किए गए परीक्षण फ़ंक्शन (mainकार्य मेंOrder Synchronous Management System Library (Single Server)टेम्पलेट) ।

img

यह सिर्फ इतना है कि हम शॉर्ट करने के लिए व्यापार की दिशा बदल गया है, और व्यापार की मात्रा 0.003 करने के लिए बदल गया था (Binance USDT-मार्जिन किए गए अनुबंध दशमलव में रखा जा सकता है). हालांकि, आदेशों के साथ ओकेएक्स खाता एक पूर्णांक होना चाहिए (ओकेएक्स द्वारा रखा आदेश एक पूर्णांक संख्या होना चाहिए), तो पैरामीटर मैं रणनीति पैरामीटर निर्दिष्टspecifiedAmount1 के रूप में।

img

में परीक्षण समारोह के बॉटOrder Synchronous Management System Library (Single Server)व्यापार को ट्रिगर किया।

img

आदेश पर्यवेक्षण बॉट रणनीति संकेत प्राप्त किया, और पर्यवेक्षण कार्रवाई निष्पादितः

img

मंच ने संबंधित आदेश खोला।

img

इसके बाद, बंद स्थिति का परीक्षण करें, और मुख्य फ़ंक्शन में ऑर्डर दिशा को 0.003 की शॉर्ट स्थिति बंद करने के लिए बदलें।

img

फिर बॉट को पुनरारंभ करें जो आदेशों को ले जाने के लिए जिम्मेदार है (Order Synchronous Management System Library (Single Server)).

img

आदेश पर्यवेक्षण बॉट में भी वही ऑपरेशन ट्रिगर किया जाता हैः

img

रणनीतिक पताःऑर्डर सिंक्रोनस मैनेजमेंट सिस्टम लाइब्रेरी (एकल सर्वर) ऑर्डर सिंक्रोनस मैनेजमेंट सिस्टम (सिंक्रोनस सर्वर)

उन रणनीतियों का उपयोग केवल संचार और अध्ययन के लिए किया जाता है; वास्तविक उपयोग के लिए, आपको उन्हें स्वयं संशोधित, समायोजित और अनुकूलित करने की आवश्यकता है।


अधिक