FMZ پر مبنی آرڈر سنکرون مینجمنٹ سسٹم ڈیزائن (2)

مصنف:نینا باداس, تخلیق: 2022-04-06 17:12:00, تازہ کاری: 2022-04-06 17:20:08

FMZ پر مبنی آرڈر سنکرون مینجمنٹ سسٹم ڈیزائن (2)

آرڈر سنکرونس مینجمنٹ سسٹم (سنکرونس سرور)

آئیے پچھلے مضمون میں بحث جاری رکھیں:ایف ایم زیڈ پر مبنی آرڈر سنکرون مینجمنٹ سسٹم ڈیزائن (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 کلید کی، یہ آپ کی حکمت عملی کو بلانے کے قابل نہیں ہو گا. احکامات کی نگرانی کے لئے دوبارہ شروع کرتے وقت، حکم کی نگرانی کے فنکشن کو بلانے کے لئے پیش سیٹ پاس ورڈ درج کریں. متعلقہ فنکشن کا نفاذ کا کوڈ:

...
          // 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 کو تبدیل کر دیا گیا تھا (بائنس USDT مارجن معاہدوں اعشاریہ میں رکھا جا سکتا ہے). تاہم، احکامات کے ساتھ OKEX اکاؤنٹ ایک عدد ہونا ضروری ہے (OKEX کی طرف سے رکھا حکم ایک عدد ہونا ضروری ہے) ، تو پیرامیٹر میں حکمت عملی پیرامیٹر کی وضاحتspecifiedAmount1 کے طور پر.

img

میں ٹیسٹنگ تقریب کے بوٹOrder Synchronous Management System Library (Single Server)تجارت کو متحرک کیا.

img

آرڈر نگرانی بوٹ حکمت عملی سگنل موصول ہوئی، اور نگرانی کارروائی کو انجام:

img

پلیٹ فارم نے اسی آرڈر کو کھول دیا.

img

اگلا، اختتامی پوزیشنوں کی جانچ کریں، اور مختصر پوزیشن بند کرنے کے لئے مرکزی فنکشن میں آرڈر کی سمت تبدیل کریں، 0.003.

img

پھر روبوٹ دوبارہ شروع کریں جو احکامات لے جانے کے لئے ذمہ دار ہے (Order Synchronous Management System Library (Single Server)).

img

اسی آپریشن کو بھی حکم کی نگرانی بوٹ میں شروع کیا جاتا ہے:

img

حکمت عملی کا پتہ:آرڈر سنکرونس مینجمنٹ سسٹم لائبریری (واحد سرور) آرڈر سنکرونس مینجمنٹ سسٹم (سنکرونس سرور)

ان حکمت عملیوں کا استعمال صرف مواصلات اور مطالعہ کے لیے ہوتا ہے۔ اصل استعمال کے لیے آپ کو خود ان کو تبدیل، ایڈجسٹ اور بہتر بنانے کی ضرورت ہے۔


مزید