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

مصنف:لیدیہ, تخلیق: 2022-11-08 11:34:20, تازہ کاری: 2023-09-15 20:48:46

img

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

آرڈر سنکرونائزیشن مینجمنٹ سسٹم (سنکرونس سرور)

آئیے پچھلے مضمون سے بحث جاری رکھیں: ایف ایم زیڈ کوانٹیفیکیشن پر مبنی آرڈر سنکرونائزیشن مینجمنٹ سسٹم کا ڈیزائن (1) (https://www.fmz.com/digest-topic/9729) اور ہم آہنگ آرڈر کی پیروی کے لئے ایک حکمت عملی ڈیزائن کرنے کے لئے شروع.

اس طرح کے کئی ڈیزائن کے مسائل پر غور کریں:

    1. اگر آپ عارضی طور پر ہم آہنگ آرڈر کی پیروی نہیں کرنا چاہتے ہیں تو ، کیا اسے روکنا ممکن ہے؟ ایک بار معطل ہونے کے بعد ، توسیع شدہ API سے شروع کرنا منع ہے ، اسے پاس ورڈ کے ذریعہ تصدیق کرنا ہوگی۔ 2 عالمی متغیرات کو شامل کرکے اس فنکشن کو لاگو کریں:
var isStopFollow = false   // Used to mark whether the current order is being followed
var reStartPwd = null      // Used to record the restart password

img

اس کے بعد ہم حکمت عملی کی ترمیم کے صفحے پر انٹرایکٹو کنٹرولز کو شامل کرتے ہیں حکمت عملی کو روکنے / دوبارہ شروع کرنے کے لئے (حقیقی بوٹ کو روکنے کے لئے نہیں ، صرف منطقی توقف ، کوئی اور آرڈر کی پیروی نہیں) ۔ ہم توقف کرتے وقت توقف کا پاس ورڈ ترتیب دے سکتے ہیں ، تاکہ آپ کے حقیقی بوٹ کے ساتھ بھی توسیع شدہ API KEY کےOrder Synchronization Management System Class Library (Single Server)اختتام، یہ آپ کی حکمت عملی کو بیدار نہیں کر سکتا. حکم کے بعد دوبارہ شروع کرتے وقت، حکم کے بعد تقریب کو بیدار کرنے کے لئے پہلے سے مقرر پاس ورڈ درج کریں. متعلقہ افعال کے نفاذ کے لئے کوڈ:

...
          // Judge the interaction command
          if (arr.length == 2) {
          	// Buttons with controls
          	if (arr[0] == "stop/restart") {
          		// Pause/restart order-following
          		if (!isStopFollow) {
          		    isStopFollow = true
          		    reStartPwd = arr[1]
          		    Log("it has stopped the order-following,", "Set the restart password as:", reStartPwd, "#FF0000")
          		} else if (isStopFollow && arr[1] == reStartPwd) {
          			isStopFollow = false 
          			reStartPwd = null 
          			Log("it has restarted the order-following, ", "Clear the restart password.", "#FF0000")
          		} else if (isStopFollow && arr[1] != reStartPwd) {
          			Log("Restart password error!")
          		}
          	}
          	continue 
          }
    1. آپ کی پیروی کی جائے کرنے کے احکامات کی مقدار کی وضاحت کر سکتے ہیں یا کئی گنا میں پیمانے پر کیا جا سکتا ہے حکمت عملی میں پیرامیٹرز شامل کریں:

img

specifiedAmount: آرڈر کے بعد کی تعداد کی وضاحت کریں، ڈیفالٹ -1 ہے، یعنی مخصوص نہیں. zoomAmountRatio: بھیجے گئے احکامات کی مقدار کے مطابق اسکیلنگ ، مثال کے طور پر ، اگر بھیجا گیا اشارہ ہے: ETH_USDT،swap،buy،1، zoomAmountRatio کے ذریعہ احکامات کی مقدار کی قیمت ضرب کریں۔ ڈیفالٹ -1 ہے ، یعنی کوئی اسکیلنگ نہیں۔

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

یہاں اسے اسکیل کرنے یا موصولہ سگنل میں پیروی کرنے والے احکامات کی مقدار کے لئے ایک مخصوص قدر کی وضاحت کرنے کے لئے لاگو کیا جاتا ہے۔

    1. کوڈ ممکن حد تک آسان ہونا چاہئے، آرڈر کرنے کے لئے دیگر ٹیمپلیٹ لائبریریوں کا استعمال کریں.

جگہ کے احکامات کی طرف سے استعمال کلاس لائبریری:https://www.fmz.com/strategy/10989مستقبل کے احکامات کی طرف سے استعمال کلاس لائبریری:https://www.fmz.com/strategy/203258

  function trade(action) {
      // Switch trading pairs and set up contracts
      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

اب ہم آرڈر ہم وقت سازی مینجمنٹ سسٹم (ہم وقت سرور) کو دوبارہ ڈیزائن کرنے شروع:

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

function trade(action) {
    // Switch trading pairs and set up contracts
    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 demo!")
    }

    // Set accuracy
    exchange.SetPrecision(pricePrecision, amountPrecision)

    // Check zoom and specify it cannot be set at the same time
    if (specifiedAmount != -1 && zoomAmountRatio != -1) {
    	throw "it cannot specify simultaneous volume and scaling volume at the same time"
    }

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

            // Judge interaction commands
            if (arr.length == 2) {
            	// Buttons with controls
            	if (arr[0] == "stop/restart") {
            		// Pause/restart order-following
            		if (!isStopFollow) {
            		    isStopFollow = true
            		    reStartPwd = arr[1]
            		    Log("it has stopped the order-following.", "Set the restart password as.", reStartPwd, "#FF0000")
            		} else if (isStopFollow && arr[1] == reStartPwd) {
            			isStopFollow = false 
            			reStartPwd = null 
            			Log("it has restarted the order-following", "Clear the restart password.", "#FF0000")
            		} else if (isStopFollow && arr[1] != reStartPwd) {
            			Log("Restart password error!")
            		}
            	}
            	continue 
            }
            
            // Permission to follow orders
            if (!isStopFollow) {
                // Resolve the interaction instructions of order-following signal
                var objAction = parseCmd(cmd)
                if (objAction) {
            	    // The analysis is correct
            	    var ret = trade(objAction)
                } else {
                	Log("Wrong signal command cmd:", cmd)
                }
            }
        }
        
        // Display order-following status
        LogStatus(_D(), isStopFollow ? "Stop Synchronization" : "Keep Synchronization", "\n")

        Sleep(1000)
    }
}

ٹیسٹ

ہم اس وقت کے لئے بائننس حقیقی بوٹ کا استعمال کرتے ہوئے آرڈر لیڈنگ اکاؤنٹ کی جانچ کرتے ہیں، اور ہم آرڈر کی پیروی کرنے کے لئے حقیقی بوٹ کے لئے اوکیکس اکاؤنٹ کا استعمال کرتے ہیں۔ آرڈر لیڈنگ کے لئے، ہم اب بھی استعمال کرتے ہیںmainٹیسٹ فنکشن میں فنکشن(Order Synchronization Management System Class Library (Single Server)ماڈل) میں استعمال کیا گیا ہے۔

img

یہاں ہم ٹرانزیکشن کی سمت کو sell ، اور ٹرانزیکشن کا حجم 0.003 میں تبدیل کرتے ہیں۔ (بائنین USDT معیاری معاہدوں کے لئے آرڈر اعشاریہ نمبروں میں رکھے جاسکتے ہیں۔) لیکن OKEX اکاؤنٹ کے لئے آرڈر کے بعد ایک عدد نمبر ہونا ضروری ہے (OKEX ایکسچینج آرڈرز ایک عدد ہونا ضروری ہے) ، لہذا ہم اسٹریٹجی پیرامیٹر specifiedAmount کو 1 کے طور پر بیان کرتے ہیں۔

img

اگلا، چلو 0.003 کی طرف سے مختصر پوزیشن کو بند کرنے کے لئے ٹیسٹ اہم تقریب میں حکم کی سمت کو تبدیل کرنے کی طرف سے پوزیشن کو بند کرنے کی جانچ.

img

پھر ہم اسے دوبارہ چلائیں، جو آرڈر کی قیادت کے لئے ذمہ دار ہے (آرڈر ہم وقت سازی مینجمنٹ سسٹم کلاس لائبریری (واحد سرور)).

اسی آپریشن کو حکم کے بعد حقیقی بوٹ کی طرف سے شروع کیا گیا تھا

حکمت عملی کا خطاب: آرڈر سنکرونائزیشن مینجمنٹ سسٹم کلاس لائبریری (واحد سرور) (https://www.fmz.com/strategy/345171) آرڈر سنکرونائزیشن مینجمنٹ سسٹم (سنکرونس سرور) (https://www.fmz.com/strategy/345172)

یہ حکمت عملی صرف مواصلات اور سیکھنے کے لیے بنائی گئی ہے، براہ کرم حقیقی ضروریات کے مطابق ایڈجسٹ اور بہتر بنائیں۔


متعلقہ

مزید