بولنگر بینڈ پر مبنی ڈیجیٹل کرنسی کی کراس پیریڈ آربٹراج حکمت عملی

مصنف:لیدیہ, تخلیق: 2022-12-02 16:58:27, تازہ کاری: 2023-09-20 09:33:29

img

بولنگر بینڈ پر مبنی ڈیجیٹل کرنسی کی کراس پیریڈ آربٹراج حکمت عملی

I. خلاصہ

جارج سوروس نے 1987 میں لکھی گئی The Alchemy of Finance میں ایک اہم تجویز پیش کی: مجھے یقین ہے کہ مارکیٹ کی قیمتیں ہمیشہ اس لحاظ سے غلط ہوتی ہیں کہ وہ مستقبل کا ایک متعصب نظریہ پیش کرتی ہیں۔ مارکیٹ کی کارکردگی کا مفروضہ صرف ایک نظریاتی مفروضہ ہے۔ در حقیقت ، مارکیٹ کے شرکاء ہمیشہ عقلی نہیں ہوتے ہیں ، اور ہر وقت ، شرکاء پوری طرح سے حاصل نہیں کرسکتے ہیں اور ہر معلومات کی معروضی تشریح نہیں کرسکتے ہیں۔ مزید برآں ، یہاں تک کہ اگر یہ ایک ہی معلومات ہے تو ، ہر ایک کی رائے مختلف ہے۔ یعنی ، قیمت میں خود ہی مارکیٹ کے شرکاء کی غلط توقعات موجود ہیں ، لہذا جوہر طرح سے ، مارکیٹ کی قیمت ہمیشہ غلط ہوتی ہے۔ یہ ثالثی کرنے والوں کے منافع کا ذریعہ ہوسکتا ہے۔

II. اسٹریٹجک اصول

مندرجہ بالا اصولوں کے مطابق ، ہم یہ جان سکتے ہیں کہ غیر موثر فیوچر مارکیٹ میں ، مختلف ادوار میں ترسیل کے معاہدوں پر مارکیٹ کے اثرات کی وجہ ہمیشہ ہم آہنگ نہیں ہوتی ہے ، اور قیمتوں کا تعین مکمل طور پر موثر نہیں ہوتا ہے۔ پھر ، مختلف ادوار میں ایک ہی لین دین کے اعتراض کی ترسیل کے معاہدے کی قیمت کی بنیاد پر ، اگر دونوں قیمتوں کے مابین قیمت کا بڑا فرق ہے تو ، ہم کراس پیریڈ آربیٹریج کے لئے ایک ہی وقت میں مختلف ادوار میں فیوچر معاہدوں کو خرید اور فروخت کرسکتے ہیں۔ خام مال کے فیوچر کی طرح ، ڈیجیٹل کرنسی میں بھی کراس پیریڈ آربیٹریج معاہدے کا پورٹ فولیو ہوتا ہے۔ مثال کے طور پر ، اوکیکس ایکسچینج میں ، ہیں: ای ٹی سی رواں ہفتہ ، ای ٹی سی اگلے ہفتے ، ای ٹی سی سہ ماہی۔ مثال کے طور پر ، فرض کریں کہ ای ٹی سی کے موجودہ ہفتہ اور ای ٹی سی کے سہ ماہی کے درمیان قیمت کا فرق طویل عرصے تک 5 کے آس پاس رہتا ہے۔ اگر قیمت کا فرق ایک دن 7 تک پہنچ جاتا ہے تو ، ہم توقع کرتے ہیں کہ قیمت کا فرق مستقبل میں 5 پر واپس آجائے گا۔ پھر ہم اس ہفتے ای ٹی سی فروخت کرسکتے ہیں اور قیمت کے فرق کو مختصر کرنے کے لئے ایک ہی وقت میں ای ٹی سی سہ ماہی خرید سکتے ہیں ، اور اس کے برعکس۔ اگرچہ یہ قیمت کا فرق موجود ہے ، لیکن وقت طلب دستی کارروائیوں ، ناقص درستگی اور قیمتوں میں تبدیلیوں کے اثرات کی وجہ سے دستی سودے بازی میں بہت سی غیر یقینی صورتحال ہے۔ مقداری سودے بازی کا سحر مقداری ماڈلز اور سودے بازی کی حکمت عملی تیار کرنے کے ذریعے سودے بازی کے مواقع کو حاصل کرنے میں ہے ، نیز پروگرام کردہ الگورتھم کے ذریعہ خود بخود تبادلے میں تجارتی آرڈرز کی جگہ ، تاکہ مواقع کو تیزی سے اور درست طریقے سے حاصل کیا جاسکے اور موثر اور مستحکم منافع حاصل کیا جاسکے۔

III. حکمت عملی کا منطق

یہ مضمون آپ کو سکھائے گا کہ کس طرح FMZ کوانٹ ٹریڈنگ پلیٹ فارم اور OKEX ایکسچینج میں ETC فیوچر معاہدے کا استعمال کریں تاکہ فوری طور پر ثالثی کے مواقع کو کیسے حاصل کیا جاسکے ، ہر بار دیکھے جانے والے منافع کو پکڑیں ، اور ڈیجیٹل کرنسی کی تجارت میں آنے والے خطرات کو ایک آسان ثالثی کی حکمت عملی کے ساتھ ہیج کریں۔

ڈیجیٹل کرنسی کے لئے کراس پیریڈ آربراجی کی حکمت عملی تیار کریں

مشکل: عام

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

  • لین دین کا مقصد: ایتھر کلاسیکی (ETC)
  • پھیلاؤ کے اعداد و شمار: ETC جاری ہفتہ - ETC سہ ماہی (مشترکہ انضمام ٹیسٹ کو نظر انداز کریں)
  • ٹرانزیکشن کا دورانیہ: 5 منٹ
  • پوزیشن مماثلت: 1:1
  • ٹرانزیکشن کی قسم: ایک ہی قسم کی کراس مدت

حکمت عملی کا منطق

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

IV. ایک حکمت عملی کا فریم ورک لکھیں

مندرجہ بالا ڈیجیٹل کرنسی کی کراس پیریڈ آربیٹریج حکمت عملی کی ایک سادہ منطقی وضاحت ہے۔ تو پروگرام میں اپنے خیالات کو کیسے نافذ کیا جائے؟ ہم ایف ایم زیڈ کوانٹ ٹریڈنگ پلیٹ فارم پر فریم ورک بنانے کی کوشش کرتے ہیں۔

function Data() {}  // Basic data function
Data.prototype.mp = function () {}  // Position function
Data.prototype.boll = function () {}  // Indicator function
Data.prototype.trade = function () {}  // Order placement function
Data.prototype.cancelOrders = function () {}  // Order withdrawal function
Data.prototype.isEven = function () {}  // Processing single contract function
Data.prototype.drawingChart = function () {}  // Drawing function

// Trading conditions
function onTick() {
    var data = new Data(tradeTypeA, tradeTypeB);  // Create a basic data object
    var accountStocks = data.accountData.Stocks;  // Account balance
    var boll = data.boll(dataLength, timeCycle);  // Calculate the technical indicators of boll
    data.trade();  // Calculate trading conditions to place an order
    data.cancelOrders();  // Cancel orders
    data.drawingChart(boll);  // drawing
    data.isEven();  // Processing of holding individual contract
}

//Entry function
function main() {
    while (true) {  // Enter the polling mode
        onTick();  // Execute onTick function
        Sleep(500);  // Sleep for 0.5 seconds
    }
}

V. تحریری حکمت عملی

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

ٹرانزیکشن سے پہلے پری پروسیسنگ مرحلہ 1: عالمی دائرہ کار میں ضروری عالمی متغیرات کا اعلان کریں۔

//Declare a chart object for the configuration chart
var chart = { }

//Call Chart function and initialize the chart
var ObjChart = Chart ( chart )

//Declare an empty array to store price difference series
var bars = [ ]

//Declare a record history data timestamp variable
var oldTime = 0

مرحلہ 2: حکمت عملی کے بیرونی پیرامیٹرز کو ترتیب دیں.

// parameters
var tradeTypeA = "this_week"; // Arbitrage A Contract
var tradeTypeB = "quarter"; // Arbitrage B Contract
var dataLength = 10; //Indicator period length
var timeCycle = 1; // K-line period
var name = "ETC"; // Currencies
var unit = 1; // Order quantity

مرحلہ 3: ڈیٹا پروسیسنگ فنکشن کی وضاحت کریں بنیادی ڈیٹا فنکشن: ڈیٹا ((( ایک کنسٹرکٹر ، ڈیٹا بنائیں ، اور اس کی داخلی خصوصیات کی وضاحت کریں۔ بشمول: اکاؤنٹ ڈیٹا ، پوزیشن ڈیٹا ، کے لائن ڈیٹا ٹائم اسٹیمپ ، arbitrage A / B معاہدے کی خرید / فروخت کی قیمت ، اور مثبت / منفی arbitrage قیمت کا فرق۔

// Basic data
function Data(tradeTypeA, tradeTypeB) { // Pass in arbitrage A contract and arbitrage B contract
    this.accountData = _C(exchange.GetAccount); // Get account information
    this.positionData = _C(exchange.GetPosition); // Get position information
    var recordsData = _C(exchange.GetRecords); // Get K-line data
    exchange.SetContractType(tradeTypeA); // Subscription arbitrage A contract
    var depthDataA = _C(exchange.GetDepth); // Depth data of arbitrage A contract
    exchange.SetContractType(tradeTypeB); // Subscription arbitrage B contract
    var depthDataB = _C(exchange.GetDepth); // Depth data of arbitrage B contract
    this.time = recordsData[recordsData.length - 1].Time; // Time of obtaining the latest data
    this.askA = depthDataA.Asks[0].Price; // Sell one price of Arbitrage A contract
    this.bidA = depthDataA.Bids[0].Price; // Buy one price of Arbitrage A contract
    this.askB = depthDataB.Asks[0].Price; // Sell one price of Arbitrage B contract
    this.bidB = depthDataB.Bids[0].Price; // Buy one price of Arbitrage B contract
    // Positive arbitrage price differences (Sell one price of contract A - Buy one price of contract B)
    this.basb = depthDataA.Asks[0].Price - depthDataB.Bids[0].Price;
    // Negative arbitrage price differences (Buy one price of contract A - Sell one price of contract B)
    this.sabb = depthDataA.Bids[0].Price - depthDataB.Asks[0].Price;
}

پوزیشن فنکشن حاصل کریں: mp ()) پورے پوزیشن صف کو پار کریں اور مخصوص معاہدے اور سمت کی پوزیشن مقدار واپس. اگر نہیں، غلط واپس

// Get positions
Data.prototype.mp = function (tradeType, type) {
    var positionData = this.positionData; // Get position information
    for (var i = 0; i < positionData.length; i++) {
        if (positionData[i].ContractType == tradeType) {
            if (positionData[i].Type == type) {
                if (positionData[i].Amount > 0) {
                    return positionData[i].Amount;
                }
            }
        }
    }
    return false;
}

K لائن اور اشارے کی تقریب: boll() ایک نیا K- لائن ترتیب مثبت آربراجیج / منفی آربراجیج قیمت فرق کے اعداد و شمار کے مطابق ترکیب کیا جاتا ہے۔ بول اشارے کے ذریعہ حساب لگایا گیا اوپری ٹریک ، مڈل ٹریک اور نچلے ٹریک کے اعداد و شمار واپس کردیئے جاتے ہیں۔

// Synthesis of new K-line data and boll indicator data
Data.prototype.boll = function (num, timeCycle) {
    var self = {}; // Temporary objects
    // Median value of positive arbitrage price difference and negative arbitrage price difference
    self.Close = (this.basb + this.sabb) / 2;
    if (this.timeA == this.timeB) {
        self.Time = this.time;
    } // Compare two depth data timestamps
    if (this.time - oldTime > timeCycle * 60000) {
        bars.push(self);
        oldTime = this.time;
    } // Pass in the price difference data object into the K-line array according to the specified time period
    if (bars.length > num * 2) {
        bars.shift(); // Control the length of the K-line array
    } else {
        return;
    }
    var boll = TA.BOLL(bars, num, 2); // Call the boll indicator in the talib library
    return {
        up: boll[0][boll[0].length - 1], // boll indicator upper track
        middle: boll[1][boll[1].length - 1], // boll indicator middle track
        down: boll[2][boll[2].length - 1] // boll indicator down track
    } // Return a processed boll indicator data
}

آرڈر فنکشن: تجارت آرڈر معاہدے کا نام اور آرڈر کی قسم میں منتقل کریں ، پھر آرڈر کو معاوضے کے ساتھ رکھیں ، اور آرڈر دینے کے بعد نتیجہ واپس کریں۔ چونکہ ایک ہی وقت میں مختلف سمتوں میں دو آرڈر دینا ضروری ہے ، لہذا آرڈر کے معاہدے کے نام کے مطابق فنکشن کے اندر ایک خرید / فروخت کی قیمت تبدیل کردی جاتی ہے۔

// place the order
Data.prototype.trade = function (tradeType, type) {
    exchange.SetContractType(tradeType); // Resubscribe to a contract before placing an order
    var askPrice, bidPrice;
    if (tradeType == tradeTypeA) { // If the order is placed in contract A
        askPrice = this.askA; // set askPrice
        bidPrice = this.bidA; // set bidPrice
    } else if (tradeType == tradeTypeB) { // If the order is placed in contract B
        askPrice = this.askB; // set askPrice
        bidPrice = this.bidB; // set bidPrice
    }
    switch (type) { // Match order placement mode
        case "buy":
            exchange.SetDirection(type); // Set order placement mode
            return exchange.Buy(askPrice, unit);
        case "sell":
            exchange.SetDirection(type); // Set order placement mode
            return exchange.Sell(bidPrice, unit);
        case "closebuy":
            exchange.SetDirection(type); // Set order placement mode
            return exchange.Sell(bidPrice, unit);
        case "closesell":
            exchange.SetDirection(type); // Set order placement mode
            return exchange.Buy(askPrice, unit);
        default:
            return false;
    }
}

آرڈر منسوخ کریں فنکشن: آرڈر منسوخ کریں تمام بقایا احکامات کی ایک صف حاصل کریں اور انہیں ایک ایک کرکے منسوخ کریں۔ اس کے علاوہ ، اگر کوئی خالی آرڈر موجود ہے تو غلط لوٹایا جاتا ہے ، اور اگر کوئی خالی آرڈر موجود نہیں ہے تو سچ لوٹایا جاتا ہے۔

// Cancel order
Data.prototype.cancelOrders = function () {
    Sleep(500); // Delay before cancellation, because some exchanges, you know what I mean
    var orders = _C(exchange.GetOrders); // Get an array of unfilled orders
    if (orders.length > 0) { // If there are unfilled orders
        for (var i = 0; i < orders.length; i++) { //Iterate through the array of unfilled orders
            exchange.CancelOrder(orders[i].Id); //Cancel unfilled orders one by one
            Sleep(500); //Delay 0.5 seconds
        }
        return false; // Return false if an unfilled order is cancelled
    }
    return true; // Return true if there are no unfilled orders
}

ایک معاہدہ رکھنے والے ہینڈل: isEven() ثالثی کے لین دین میں ایک ہی ٹانگ کی صورت میں ، ہم صرف تمام پوزیشنوں کو بند کردیں گے۔ یقینا ، یہ ٹریکنگ کے طریقہ کار میں بھی تبدیل کیا جاسکتا ہے۔

// Handle holding a single contract
Data.prototype.isEven = function () {
    var positionData = this.positionData; // Get position information
    var type = null; // Switch position direction
    // If the remaining 2 of the position array length is not equal to 0 or the position array length is not equal to 2
    if (positionData.length % 2 != 0 || positionData.length != 2) {
        for (var i = 0; i < positionData.length; i++) { // Iterate through the position array
            if (positionData[i].Type == 0) { // If it is a long order
                type = 10; // Set order parameters
            } else if (positionData[i].Type == 1) { // If it is a short order
                type = -10; // Set order parameters
            }
            // Close all positions
            this.trade(positionData[i].ContractType, type, positionData[i].Amount);
        }
    }
}

ڈرائنگ فنکشن: ڈرائنگ گراف ()) کال ObjChart شامل () طریقہ کار، چارٹ میں ضروری مارکیٹ کے اعداد و شمار اور اشارے کے اعداد و شمار کو ڈرا: اوپری ٹریک، درمیانی ٹریک، نچلے ٹریک، مثبت / منفی arbitrage قیمت فرق.

// Drawing
Data.prototype.drawingChart = function (boll) {
    var nowTime = new Date().getTime();
    ObjChart.add([0, [nowTime, boll.up]]);
    ObjChart.add([1, [nowTime, boll.middle]]);
    ObjChart.add([2, [nowTime, boll.down]]);
    ObjChart.add([3, [nowTime, this.basb]]);
    ObjChart.add([4, [nowTime, this.sabb]]);
    ObjChart.update(chart);
}

مرحلہ 4: انٹری فنکشن مین میں ، پری ٹرانزیکشن پری پروسیسنگ کوڈ کو چلائیں ، جو پروگرام شروع ہونے کے بعد صرف ایک بار چلایا جائے گا ، جس میں شامل ہیں:

  • کنسول میں غیر اہم معلومات کو فلٹر کرنے کے لئے SetErrorFilter (())
  • exchange.IO ( https://www.squadhelp.com/name/exchange.io?lp=d()) ()) ڈیجیٹل کرنسی کی تجارت کرنے کے لئے مقرر کرنے کے لئے
  • ObjChart reset () پروگرام شروع کرنے سے پہلے تیار کردہ پچھلے چارٹ کو صاف کرنے کے لئے
  • پروگرام شروع کرنے سے پہلے حالت بار کی معلومات کو صاف کرنے کے لئے لاگ پروفٹ ری سیٹ کریں
//entry function
function main() {
    // Filter the unimportant information in the console
    SetErrorFilter("429|GetRecords:|GetOrders:|GetDepth:|GetAccount|:Buy|Sell|timeout|Futures_OP");
    exchange.IO("currency", name + '_USDT'); //Set the digital currency to be traded
    ObjChart.reset(); // Clear the previous chart drawn before starting the program
    LogProfitReset(); // Clear the status bar information before starting the program
}

مذکورہ بالا ٹرانزیکشن سے پہلے کی پروسیسنگ کی وضاحت کے بعد ، اگلا مرحلہ پولنگ موڈ میں داخل ہونا اور آن ٹِک ()) فنکشن کو بار بار انجام دینا ہے۔ یہ سوتے () پولنگ کے لئے نیند کا وقت بھی طے کرتا ہے ، کیونکہ کچھ ڈیجیٹل کرنسی تبادلے کے API میں ایک مخصوص مدت کے لئے داخلی رسائی کی حد ہے۔

//entry function
function main() {
    // Filter the unimportant information in the console
    SetErrorFilter("429|GetRecords:|GetOrders:|GetDepth:|GetAccount|:Buy|Sell|timeout|Futures_OP");
    exchange.IO("currency", name + '_USDT'); //Set the digital currency to be traded
    ObjChart.reset(); //Clear the previous chart drawn before starting the program
    LogProfitReset(); //Clear the status bar information before starting the program
    while (true) { // Enter the polling mode
        onTick(); // Execute onTick function
        Sleep(500); // Sleep for 0.5 seconds
    }
}

ڈیٹا حاصل کریں اور حساب لگائیں مرحلہ 1: تجارتی منطق میں استعمال کے لئے بنیادی ڈیٹا آبجیکٹ ، اکاؤنٹ بیلنس ، اور بول اشارے کے اعداد و شمار حاصل کریں۔

// Trading conditions
function onTick() {
    var data = new Data(tradeTypeA, tradeTypeB); // Create a basic data object
    var accountStocks = data.accountData.Stocks; // Account balance
    var boll = data.boll(dataLength, timeCycle); // Get boll indicator data
    if (!boll) return; // Return if there is no boll data
}

آرڈر دیں اور اس کی پیروی کریں مرحلہ 1: اوپر کی اسٹریٹجک منطق کے مطابق خرید و فروخت کا عمل انجام دیں۔ پہلے ، فیصلہ کریں کہ آیا قیمت اور اشارے کی شرائط درست ہیں ، پھر فیصلہ کریں کہ آیا پوزیشن کی شرائط درست ہیں ، اور آخر میں trade () آرڈر فنکشن کو انجام دیں

// Trading conditions
function onTick() {
    var data = new Data(tradeTypeA, tradeTypeB); // Create a basic data object
    var accountStocks = data.accountData.Stocks; // Account balance
    var boll = data.boll(dataLength, timeCycle); // Get boll indicator data
    if (!boll) return; // Return if there is no boll data
    // Explanation of the price difference
    // basb = (Sell one price of contract A - Buy one price of contract B)
    // sabb = (Buy one price of contract A - Sell one price of contract B)
    if (data.sabb > boll.middle && data.sabb < boll.up) { // If sabb is higher than the middle track
        if (data.mp(tradeTypeA, 0)) { // Check whether contract A has long orders before placing an order
            data.trade(tradeTypeA, "closebuy"); // Contract A closes long position
        }
        if (data.mp(tradeTypeB, 1)) { // Check whether contract B has short orders before placing an order
            data.trade(tradeTypeB, "closesell"); // Contract B closes short position
        }
    } else if (data.basb < boll.middle && data.basb > boll.down) { // If basb is lower than the middle track
        if (data.mp(tradeTypeA, 1)) { // Check whether contract A has short orders before placing an order
            data.trade(tradeTypeA, "closesell"); // Contract A closes short position
        }
        if (data.mp(tradeTypeB, 0)) { // Check whether contract B has long orders before placing an order
            data.trade(tradeTypeB, "closebuy"); // Contract B closes long position
        }
    }
    if (accountStocks * Math.max(data.askA, data.askB) > 1) { // If there is balance in the account
        if (data.basb < boll.down) { // If basb price difference is lower than the down track
            if (!data.mp(tradeTypeA, 0)) { // Check whether contract A has long orders before placing an order
                data.trade(tradeTypeA, "buy"); // Contract A opens long position
            }
            if (!data.mp(tradeTypeB, 1)) { // Check whether contract B has short orders before placing an order
                data.trade(tradeTypeB, "sell"); // Contract B opens short position
            }
        } else if (data.sabb > boll.up) { // If sabb price difference is higher than the upper track
            if (!data.mp(tradeTypeA, 1)) { // Check whether contract A has short orders before placing an order
                data.trade(tradeTypeA, "sell"); // Contract A opens short position
            }
            if (!data.mp(tradeTypeB, 0)) { // Check whether contract B has long orders before placing an order
                data.trade(tradeTypeB, "buy"); // Contract B opens long position
            }
        }
    }
}

مرحلہ 2: آرڈر دینے کے بعد ، غیر معمولی حالات جیسے غیر طے شدہ آرڈر اور ایک ہی معاہدے کے انعقاد سے نمٹنا ضروری ہے۔ اور چارٹ بنائیں۔

// Trading conditions
function onTick() {
    var data = new Data(tradeTypeA, tradeTypeB); // Create a basic data object
    var accountStocks = data.accountData.Stocks; // Account balance
    var boll = data.boll(dataLength, timeCycle); // Get boll indicator data
    if (!boll) return; // Return if there is no boll data
    // Explanation of the price difference
    //basb = (Sell one price of contract A - Buy one price of contract B)
    // sabb = (Buy one price of contract A - Sell one price of contract B)
    if (data.sabb > boll.middle && data.sabb < boll.up) { // If sabb is higher than the middle track
        if (data.mp(tradeTypeA, 0)) { // Check whether contract A has long orders before placing an order
            data.trade(tradeTypeA, "closebuy"); // Contract A closes long position
        }
        if (data.mp(tradeTypeB, 1)) { // Check whether contract B has short orders before placing an order
            data.trade(tradeTypeB, "closesell"); // Contract B closes short position
        }
    } else if (data.basb < boll.middle && data.basb > boll.down) { // If basb is lower than the middle track
        if (data.mp(tradeTypeA, 1)) { // Check whether contract A has short orders before placing an order
            data.trade(tradeTypeA, "closesell"); // Contract A closes short position
        }
        if (data.mp(tradeTypeB, 0)) { // Check whether contract B has long orders before placing an order
            data.trade(tradeTypeB, "closebuy"); // Contract B closes long position
        }
    }
    if (accountStocks * Math.max(data.askA, data.askB) > 1) { // If there is balance in the account
        if (data.basb < boll.down) { // If basb price difference is lower than the down track
            if (!data.mp(tradeTypeA, 0)) { // Check whether contract A has long orders before placing an order
                data.trade(tradeTypeA, "buy"); // Contract A opens long position
            }
            if (!data.mp(tradeTypeB, 1)) { // Check whether contract B has short orders before placing an order
                data.trade(tradeTypeB, "sell"); // Contract B opens short position
            }
        } else if (data.sabb > boll.up) { // If sabb price difference is higher than the upper track
            if (!data.mp(tradeTypeA, 1)) { // Check whether contract A has short orders before placing an order
                data.trade(tradeTypeA, "sell"); // Contract A opens short position
            }
            if (!data.mp(tradeTypeB, 0)) { // Check whether contract B has long orders before placing an order
                data.trade(tradeTypeB, "buy"); // Contract B opens long position
            }
        }
    }
    data.cancelOrders(); // cancel orders
    data.drawingChart(boll); // drawing
    data.isEven(); // Handle holding individual contracts
}

VI. مکمل حکمت عملی

جیسا کہ اوپر ، ہم نے 200 سے زیادہ لائنوں کے کوڈ کے ذریعے مکمل طور پر ڈیجیٹل کرنسی کی ایک سادہ کراس پیریڈ آربیٹریج حکمت عملی تیار کی ہے۔ مکمل کوڈ مندرجہ ذیل ہے:

// Global variable
// Declare a chart object for the configuration chart
var chart = {
    __isStock: true,
    tooltip: {
        xDateFormat: '%Y-%m-%d %H:%M:%S, %A'
    },
    title: {
        text: 'transaction profit and loss curve (detailed)'
    },
    rangeSelector: {
        buttons: [{
            type: 'hour',
            count: 1,
            text: '1h'
        }, {
            type: 'hour',
            count: 2,
            text: '3h'
        }, {
            type: 'hour',
            count: 8,
            text: '8h'
        }, {
            type: 'all',
            text: 'All'
        }],
        selected: 0,
        inputEnabled: false
    },
    xAxis: {
        type: 'datetime'
    },
    yAxis: {
        title: {
            text: 'price difference'
        },
        opposite: false,
    },
    series: [{
        name: "upper track",
        id: "line1,up",
        data: []
    }, {
        name: "middle track",
        id: "line2,middle",
        data: []
    }, {
        name: "down track",
        id: "line3,down",
        data: []
    }, {
        name: "basb",
        id: "line4,basb",
        data: []
    }, {
        name: "sabb",
        id: "line5,sabb",
        data: []
    }]
};
var ObjChart = Chart(chart); // Drawing object
var bars = []; // Storage price difference series
var oldTime = 0; // Record historical data timestamp

// parameters
var tradeTypeA = "this_week"; // Arbitrage A contract
var tradeTypeB = "quarter"; // Arbitrage B contract
var dataLength = 10; //Indicator period length
var timeCycle = 1; // K-line period
var name = "ETC"; // Currencies
var unit = 1; // Order quantity

// basic data
function Data(tradeTypeA, tradeTypeB) { // Pass in arbitrage A contract and arbitrage B contract
    this.accountData = _C(exchange.GetAccount); // Get account information
    this.positionData = _C(exchange.GetPosition); // Get position information
    var recordsData = _C(exchange.GetRecords); //Get K-line data
    exchange.SetContractType(tradeTypeA); // Subscribe to arbitrage A contract
    var depthDataA = _C(exchange.GetDepth); // Arbitrage A contract depth data
    exchange.SetContractType(tradeTypeB); // Subscribe to arbitrage B contract
    var depthDataB = _C(exchange.GetDepth); // Arbitrage B contract depth data
    this.time = recordsData[recordsData.length - 1].Time; // Time to get the latest data
    this.askA = depthDataA.Asks[0].Price; // Sell one price of arbitrage A contract
    this.bidA = depthDataA.Bids[0].Price; // Buy one price of arbitrage A contract
    this.askB = depthDataB.Asks[0].Price; // Sell one price of arbitrage B contract
    this.bidB = depthDataB.Bids[0].Price; // Buy one price of arbitrage B contract
    // Positive arbitrage price difference (Sell one price of contract A - Buy one price of contract B)
    this.basb = depthDataA.Asks[0].Price - depthDataB.Bids[0].Price;
    // Negative arbitrage price difference (Buy one price of contract A - Sell one price of contract B)
    this.sabb = depthDataA.Bids[0].Price - depthDataB.Asks[0].Price;
}

// Get position
Data.prototype.mp = function (tradeType, type) {
    var positionData = this.positionData; // Get position information
    for (var i = 0; i < positionData.length; i++) {
        if (positionData[i].ContractType == tradeType) {
            if (positionData[i].Type == type) {
                if (positionData[i].Amount > 0) {
                    return positionData[i].Amount;
                }
            }
        }
    }
    return false;
}

// Synthesis of new K-line data and boll indicator data
Data.prototype.boll = function (num, timeCycle) {
    var self = {}; // Temporary objects
    // Median value of between positive arbitrage price difference and negative arbitrage price difference
    self.Close = (this.basb + this.sabb) / 2;
    if (this.timeA == this.timeB) {
        self.Time = this.time;
    } // Compare two depth data timestamps
    if (this.time - oldTime > timeCycle * 60000) {
        bars.push(self);
        oldTime = this.time;
    } // Pass in the price difference data object into the K-line array according to the specified time period
    if (bars.length > num * 2) {
        bars.shift(); // Control the length of the K-line array
    } else {
        return;
    }
    var boll = TA.BOLL(bars, num, 2); // Call the boll indicator in the talib library
    return {
        up: boll[0][boll[0].length - 1], // boll indicator upper track
        middle: boll[1][boll[1].length - 1], // boll indicator middle track
        down: boll[2][boll[2].length - 1] // boll indicator down track
    } // Return a processed boll indicator data
}

// Place an order
Data.prototype.trade = function (tradeType, type) {
    exchange.SetContractType(tradeType); // Resubscribe to a contract before placing an order
    var askPrice, bidPrice;
    if (tradeType == tradeTypeA) { // If the order is placed in contract A
        askPrice = this.askA; // Set askPrice
        bidPrice = this.bidA; // Set bidPrice
    } else if (tradeType == tradeTypeB) { // If the order is placed in contract B
        askPrice = this.askB; // Set askPrice
        bidPrice = this.bidB; // Set bidPrice
    }
    switch (type) { // Match order placement mode
        case "buy":
            exchange.SetDirection(type); // Set order placement mode
            return exchange.Buy(askPrice, unit);
        case "sell":
            exchange.SetDirection(type); // Set order placement mode
            return exchange.Sell(bidPrice, unit);
        case "closebuy":
            exchange.SetDirection(type); // Set order placement mode
            return exchange.Sell(bidPrice, unit);
        case "closesell":
            exchange.SetDirection(type); // Set order placement mode
            return exchange.Buy(askPrice, unit);
        default:
            return false;
    }
}

// Cancel orders
Data.prototype.cancelOrders = function () {
    Sleep(500); // Delay before cancellation, because some exchanges, you know what I mean
    var orders = _C(exchange.GetOrders); //Get an array of unfilled orders
    if (orders.length > 0) { // If there are unfilled orders
        for (var i = 0; i < orders.length; i++) { //Iterate through the array of unfilled orders
            exchange.CancelOrder(orders[i].Id); //Cancel unfilled orders one by one
            Sleep(500); //Sleep for 0.5 seconds
        }
        return false; // Return false if an unfilled order is cancelled
    }
    return true; //Return true if there are no unfilled orders
}

// Handle holding individual contracts
Data.prototype.isEven = function () {
    var positionData = this.positionData; // Get position information
    var type = null; // Switch position direction
    // If the remaining 2 of the position array length is not equal to 0 or the position array length is not equal to 2
    if (positionData.length % 2 != 0 || positionData.length != 2) {
        for (var i = 0; i < positionData.length; i++) { // Iterate through the position array
            if (positionData[i].Type == 0) { // If it is a long order
                type = 10; // Set order parameters
            } else if (positionData[i].Type == 1) { // If it is a short order
                type = -10; // Set order parameters
            }
            // Close all positions
            this.trade(positionData[i].ContractType, type, positionData[i].Amount);
        }
    }
}

// Drawing
Data.prototype.drawingChart = function (boll) {
    var nowTime = new Date().getTime();
    ObjChart.add([0, [nowTime, boll.up]]);
    ObjChart.add([1, [nowTime, boll.middle]]);
    ObjChart.add([2, [nowTime, boll.down]]);
    ObjChart.add([3, [nowTime, this.basb]]);
    ObjChart.add([4, [nowTime, this.sabb]]);
    ObjChart.update(chart);
}

// Trading conditions
function onTick() {
    var data = new Data(tradeTypeA, tradeTypeB); // Create a basic data object
    var accountStocks = data.accountData.Stocks; // Account balance
    var boll = data.boll(dataLength, timeCycle); // Get boll indicator data
    if (!boll) return; // Return if there is no boll data
    // Explanation of price difference
    // basb = (Sell one price of contract A - Buy one price of contract B)
    // sabb = (Buy one price of contract A - Sell one price of contract B)
    if (data.sabb > boll.middle && data.sabb < boll.up) { // If sabb is higher than the middle track
        if (data.mp(tradeTypeA, 0)) { // Check whether contract A has long orders before placing an order
            data.trade(tradeTypeA, "closebuy"); // Contract A closes long position
        }
        if (data.mp(tradeTypeB, 1)) { // Check whether contract B has short orders before placing an order
            data.trade(tradeTypeB, "closesell"); // Contract B closes short position
        }
    } else if (data.basb < boll.middle && data.basb > boll.down) { // If basb is lower than the middle track
        if (data.mp(tradeTypeA, 1)) { // Check whether contract A has short orders before placing an order
            data.trade(tradeTypeA, "closesell"); // Contract A closes short position
        }
        if (data.mp(tradeTypeB, 0)) { // Check whether contract B has long orders before placing an order
            data.trade(tradeTypeB, "closebuy"); // Contract B closes long position
        }
    }
    if (accountStocks * Math.max(data.askA, data.askB) > 1) { // If there is a balance in the account
        if (data.basb < boll.down) { // If basb price difference is lower than the down track
            if (!data.mp(tradeTypeA, 0)) { // Check whether contract A has long orders before placing an order
                data.trade(tradeTypeA, "buy"); // Contract A opens long position
            }
            if (!data.mp(tradeTypeB, 1)) { // Check whether contract B has short orders before placing an order
                data.trade(tradeTypeB, "sell"); // Contract B opens short position
            }
        } else if (data.sabb > boll.up) { // If sabb price difference is higher than the upper track
            if (!data.mp(tradeTypeA, 1)) { // Check whether contract A has short orders before placing an order
                data.trade(tradeTypeA, "sell"); // Contract A opens short position
            }
            if (!data.mp(tradeTypeB, 0)) { // Check whether contract B has long orders before placing an order
                data.trade(tradeTypeB, "buy"); // Contract B opens long position
            }
        }
    }
    data.cancelOrders(); // Cancel orders
    data.drawingChart(boll); // Drawing
    data.isEven(); // Handle holding individual contracts
}

//Entry function
function main() {
    // Filter unimportant information in the console
    SetErrorFilter("429|GetRecords:|GetOrders:|GetDepth:|GetAccount|:Buy|Sell|timeout|Futures_OP");
    exchange.IO("currency", name + '_USDT'); //Set the digital currency to be traded
    ObjChart.reset(); //Clear the previous chart drawn before starting the program
    LogProfitReset(); //Clear the status bar information before starting the program
    while (true) { // Enter polling mode
        onTick(); // Execute the onTick function
        Sleep(500); // Sleep for 0.5 seconds
    }
}

حکمت عملی کا پتہ:https://www.fmz.com/strategy/104964

VII. خلاصہ

اس مضمون میں حکمت عملی صرف ایک مثال ہے۔ اصلی بوٹ آسان نہیں ہے ، لیکن آپ اس مثال پر عمل کرسکتے ہیں اور اپنی جنگلی تخیل کا استعمال کرسکتے ہیں۔ یہ یاد رکھنا چاہئے کہ ، میرے محدود تجربے کی بنیاد پر ، موجودہ ڈیجیٹل کرنسی مارکیٹ میں ، تقریبا all تمام خالص فیوچر فیوچر آربیٹریج حکمت عملیوں کو چلانے کے قابل نہیں ہے ، چاہے وہ خطرہ سے پاک مثلث آربیٹریج ہو یا کراس مارکیٹ آربیٹریج۔ اس کی وجہ یہ ہے کہ اس سے کوئی فرق نہیں پڑتا ہے کہ کون سی ڈیجیٹل کرنسی ایکسچینج فیوچر مارکیٹ ہے ، اس کا مارجن قانونی کرنسی نہیں ہے۔ موجودہ وقت میں ، تقریبا all تمام ڈیجیٹل کرنسیوں میں سال کے آغاز سے اب تک تقریبا 70 70 فیصد کمی واقع ہوئی ہے۔ یعنی ، حکمت عملی ہمیشہ کرنسیوں کو کمانا ہے ، لیکن کرنسی کی قیمت کم ہورہی ہے۔ مجموعی طور پر ، ڈیجیٹل کرنسی مارکیٹ بلاکچین سے الگ ہوگئی ہے۔ اس وقت کی لالیوں کی طرح ، قیمت ہمیشہ لوگوں کی توقعات اور اعتماد سے آتی ہے ، اور اعتماد قیمت سے آتا ہے...


متعلقہ

مزید