متوازن زیر التواء آرڈر کی حکمت عملی (تعلیم کی حکمت عملی)

مصنف:لیدیہ, تخلیق: 2022-12-19 17:19:44, تازہ کاری: 2023-09-20 10:01:27

img

متوازن زیر التواء آرڈر کی حکمت عملی (تعلیم کی حکمت عملی)

اس مضمون میں بیان کردہ حکمت عملی کا جوہر متحرک توازن کی حکمت عملی ہے ، یعنی توازن کی کرنسی کی قیمت ہمیشہ تشخیصی کرنسی کی قیمت کے برابر ہوتی ہے۔ تاہم ، حکمت عملی کا منطق بہت آسان ہے جب اسے پہلے سے زیر التواء آرڈر کے طور پر ڈیزائن کیا گیا ہو۔ اس حکمت عملی کو لکھنے کا بنیادی مقصد حکمت عملی کے ڈیزائن کے تمام پہلوؤں کو ظاہر کرنا ہے۔

  • حکمت عملی کی منطق کا احاطہ رن ٹائم پر کچھ ڈیٹا اور ٹیگ متغیرات کے ساتھ حکمت عملی کی منطق کو احاطہ کریں (جسم کے طور پر احاطہ کرتا ہے).

  • حکمت عملی پروسیسنگ کے آغاز کے لئے کوڈ ابتدائی اکاؤنٹ کی معلومات منافع کے حساب کے لئے ابتدائی رن میں ریکارڈ کی جاتی ہیں۔ ابتدائی رن ٹائم پر ، آپ منتخب کرسکتے ہیں کہ پیرامیٹرز کے مطابق ڈیٹا کو بحال کرنا ہے۔

  • حکمت عملی تعامل کی پروسیسنگ کے لئے کوڈ ایک سادہ انٹرایکٹو پروسیسنگ وقفے اور دوبارہ شروع کرنے کے لئے ڈیزائن کیا گیا ہے.

  • حکمت عملی کے منافع کے حساب کے لئے کوڈ منافع کا حساب کرنے کے لئے کرنسی سٹینڈرڈ حساب کتاب کا طریقہ استعمال کیا جاتا ہے۔

  • حکمت عملی میں کلیدی اعداد و شمار کے تسلسل کا طریقہ کار ڈیٹا کی بازیابی کے لئے میکانزم ڈیزائن کرنا۔

  • حکمت عملی پروسیسنگ کی معلومات دکھانے کا کوڈ اسٹیٹس بار ڈیٹا ڈسپلے

حکمت عملی کا کوڈ

var Shannon = {
    // member
    e : exchanges[0],
    arrPlanOrders : [],
    distance : BalanceDistance,
    account : null,
    ticker : null, 
    initAccount : null,
    isAskPending : false,
    isBidPending : false,

    // function 
    CancelAllOrders : function (e) {
        while(true) {
            var orders = _C(e.GetOrders)
            if(orders.length == 0) {
                return 
            }
            Sleep(500)
            for(var i = 0; i < orders.length; i++) {
                e.CancelOrder(orders[i].Id, orders[i])
                Sleep(500)
            }
        }
    },

    Balance : function () {
        if (this.arrPlanOrders.length == 0) {
            this.CancelAllOrders(this.e)
            var acc = _C(this.e.GetAccount)
            this.account = acc
            var askPendingPrice = (this.distance + acc.Balance) / acc.Stocks
            var bidPendingPrice = (acc.Balance - this.distance) / acc.Stocks
            var askPendingAmount = this.distance / 2 / askPendingPrice
            var bidPendingAmount = this.distance / 2 / bidPendingPrice

            this.arrPlanOrders.push({tradeType : "ask", price : askPendingPrice, amount : askPendingAmount}) 
            this.arrPlanOrders.push({tradeType : "bid", price : bidPendingPrice, amount : bidPendingAmount})
        } else if(this.isAskPending == false && this.isBidPending == false) {
            for(var i = 0; i < this.arrPlanOrders.length; i++) {
                var tradeFun = this.arrPlanOrders[i].tradeType == "ask" ? this.e.Sell : this.e.Buy
                var id = tradeFun(this.arrPlanOrders[i].price, this.arrPlanOrders[i].amount)
                if(id) {
                    this.isAskPending = this.arrPlanOrders[i].tradeType == "ask" ? true : this.isAskPending
                    this.isBidPending = this.arrPlanOrders[i].tradeType == "bid" ? true : this.isBidPending
                } else {
                    Log("Pending order failed, clear!")
                    this.CancelAllOrders(this.e)
                    return 
                }
            }
        }

        if(this.isBidPending || this.isAskPending) {
            var orders = _C(this.e.GetOrders)
            Sleep(1000)
            var ticker = _C(this.e.GetTicker)
            this.ticker = ticker
            if(this.isAskPending) {
                var isFoundAsk = false 
                for (var i = 0; i < orders.length; i++) {
                    if(orders[i].Type == ORDER_TYPE_SELL) {
                        isFoundAsk = true
                    }
                }
                if(!isFoundAsk) {
                    Log("Selling order filled, cancel the order, reset")
                    this.CancelAllOrders(this.e)
                    this.arrPlanOrders = []
                    this.isAskPending = false 
                    this.isBidPending = false 
                    LogProfit(this.CalcProfit(ticker))
                    return 
                }
            }
            if(this.isBidPending) {
                var isFoundBid = false 
                for(var i = 0; i < orders.length; i++) {
                    if(orders[i].Type == ORDER_TYPE_BUY) {
                        isFoundBid = true
                    }
                }
                if(!isFoundBid) {
                    Log("Buying order filled, cancel the order, reset")
                    this.CancelAllOrders(this.e)
                    this.arrPlanOrders = []
                    this.isAskPending = false 
                    this.isBidPending = false 
                    LogProfit(this.CalcProfit(ticker))
                    return 
                }
            }        
        }
    }, 
    ShowTab : function() {
        var tblPlanOrders = {
            type : "table", 
            title : "Plan pending orders", 
            cols : ["direction", "price", "amount"], 
            rows : []
        }
        for(var i = 0; i < this.arrPlanOrders.length; i++) {
            tblPlanOrders.rows.push([this.arrPlanOrders[i].tradeType, this.arrPlanOrders[i].price, this.arrPlanOrders[i].amount])
        }

        var tblAcc = {
            type : "table", 
            title : "Account information", 
            cols : ["type", "Stocks", "FrozenStocks", "Balance", "FrozenBalance"], 
            rows : []            
        }
        tblAcc.rows.push(["Initial", this.initAccount.Stocks, this.initAccount.FrozenStocks, this.initAccount.Balance, this.initAccount.FrozenBalance])
        tblAcc.rows.push(["This", this.account.Stocks, this.account.FrozenStocks, this.account.Balance, this.account.FrozenBalance])
        
        return "Time:" + _D() + "\n `" + JSON.stringify([tblPlanOrders, tblAcc]) + "`" + "\n" + "ticker:" + JSON.stringify(this.ticker)
    },
    CalcProfit : function(ticker) {
        var acc = _C(this.e.GetAccount)
        this.account = acc
        return (this.account.Balance - this.initAccount.Balance) + (this.account.Stocks - this.initAccount.Stocks) * ticker.Last
    },
    Init : function() {
        this.initAccount = _C(this.e.GetAccount)
        if(IsReset) {
            var acc = _G("account")
            if(acc) {
                this.initAccount = acc 
            } else {
                Log("Failed to restore initial account information! Running in initial state!")
                _G("account", this.initAccount)
            }
        } else {
            _G("account", this.initAccount)
            LogReset(1)
            LogProfitReset()
        }
    },
    Exit : function() {
        Log("Cancel all pending orders before stopping...")
        this.CancelAllOrders(this.e)
    }
}

function main() {
    // Initialization
    Shannon.Init()

    // Main loop
    while(true) {
        Shannon.Balance()        
        LogStatus(Shannon.ShowTab())
        // Interaction
        var cmd = GetCommand()
        if(cmd) {
            if(cmd == "stop") {
                while(true) {
                    LogStatus("Pause", Shannon.ShowTab())
                    cmd = GetCommand()
                    if(cmd) {
                        if(cmd == "continue") {
                            break
                        }
                    }
                    Sleep(1000)
                }
            }
        }
        Sleep(5000)
    }
}

function onexit() {
    Shannon.Exit()
}

بیک ٹسٹنگ

img img img img

اصلاح اور توسیع

  • ایک ورچوئل زیر التواء آرڈر میکانزم شامل کیا جاسکتا ہے۔ کچھ تبادلے میں زیر التواء آرڈرز پر محدود قیمت ہوتی ہے ، لہذا آرڈر اصل میں نہیں لگایا جاسکتا ہے۔ آپ کو اس وقت تک انتظار کرنے کی ضرورت ہے جب تک کہ قیمت اصل زیر التواء آرڈر کے قریب نہ ہو۔
  • فیوچر ٹریڈنگ شامل کریں.
  • ایک کثیر پرجاتی اور کثیر تبادلہ ورژن کو بڑھانا.

حکمت عملی صرف تعلیمی مقاصد کے لئے ہیں اور حقیقی بوٹ ٹریڈنگ میں احتیاط کے ساتھ استعمال کیا جانا چاہئے. حکمت عملی کا پتہ:https://www.fmz.com/strategy/225746


متعلقہ

مزید