बोलिंगर बैंड पर आधारित डिजिटल मुद्रा की क्रॉस-पीरियड आर्बिट्रेज रणनीति

लेखक:लिडिया, बनाया गयाः 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 वायदा अनुबंध का उपयोग करें ताकि यह प्रदर्शित किया जा सके कि त्वरित मध्यस्थता अवसरों को कैसे कैप्चर किया जाए, हर बार देखे जाने वाले लाभों को जब्त किया जा सके, और जोखिमों को सुरक्षित किया जा सके जो एक सरल मध्यस्थता रणनीति के साथ डिजिटल मुद्रा व्यापार में आ सकते हैं।

डिजिटल मुद्रा के लिए क्रॉस-पीरियड आर्बिट्रेज रणनीति तैयार करें

कठिनाई: सामान्य

रणनीतिक माहौल

  • लेनदेन का विषयः एथर क्लासिक (ईटीसी)
  • स्प्रेड डेटाः ईटीसी चालू सप्ताह - ईटीसी तिमाही (सह-संगठन परीक्षण को छोड़ दें)
  • लेनदेन की अवधिः 5 मिनट
  • स्थिति मिलानः 1:1
  • लेन-देन का प्रकारः एक ही प्रकार की क्रॉस अवधि

रणनीतिक तर्क

  • मूल्य अंतर को लंबे समय तक जाने के साथ पदों को खोलने की शर्तेंः यदि चालू खाते में कोई पद नहीं है और मूल्य अंतर बॉल की निचली सीमा से कम है, तो मूल्य अंतर को लंबा करें। अर्थात, सप्ताह के लिए उद्घाटन पदों को खरीदें, तिमाही के लिए उद्घाटन पदों को बेचें।
  • मूल्य अंतर को शॉर्ट करने के साथ पदों को खोलने की शर्तेंः यदि चालू खाते में कोई पद नहीं है, और मूल्य अंतर बोल की ऊपरी सीमा से अधिक है, तो मूल्य अंतर को शॉर्ट करें। अर्थात, सप्ताह के लिए उद्घाटन पदों को बेचें, तिमाही के लिए उद्घाटन पदों को खरीदें।
  • मूल्य अंतर के साथ लंबी स्थिति बंद करने की शर्तेंः यदि चालू खाते में चालू सप्ताह में ईटीसी के चल रहे लंबे ऑर्डर हैं और ईटीसी तिमाही के चल रहे छोटे ऑर्डर हैं, और मूल्य अंतर बॉल की मध्य सीमा से अधिक है, तो मूल्य अंतर को बंद करें। यानी, सप्ताह के लिए ईटीसी की बंद स्थिति बेचें, तिमाही के लिए ईटीसी की बंद स्थिति खरीदें।
  • मूल्य अंतर को छोटा करने के साथ पदों को बंद करने की शर्तेंः यदि चालू खाते में चालू सप्ताह में ईटीसी के शॉर्ट ऑर्डर चल रहे हैं, और ईटीसी तिमाही के लंबे ऑर्डर चल रहे हैं, और मूल्य अंतर बॉल की मध्य सीमा से कम है, तो मूल्य अंतर को बंद करें। यानी, सप्ताह के लिए ईटीसी बंद करने की स्थिति खरीदें, तिमाही के लिए ईटीसी बंद करने की स्थिति बेचें।

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: डेटा प्रोसेसिंग फ़ंक्शन को परिभाषित करें आधारभूत डेटा फ़ंक्शन: डेटा एक कंस्ट्रक्टर, डेटा बनाएँ, और इसके आंतरिक गुणों को परिभाषित करें. इसमें शामिल हैंः खाता डेटा, स्थिति डेटा, के-लाइन डेटा टाइमस्टैम्प, आर्बिट्रेज ए / बी अनुबंध की खरीद / बिक्री मूल्य, और सकारात्मक / नकारात्मक आर्बिट्रेज मूल्य अंतर.

// 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;
}

के-लाइन और संकेतक कार्यः बॉल (boll)) एक नया के-लाइन अनुक्रम सकारात्मक आर्बिट्रेज/नकारात्मक आर्बिट्रेज मूल्य अंतर डेटा के अनुसार संश्लेषित किया जाता है। बॉल संकेतक द्वारा गणना की गई ऊपरी ट्रैक, मध्य ट्रैक और निचले ट्रैक के डेटा लौटाए जाते हैं।

// 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 Add () विधि को कॉल करें, चार्ट में आवश्यक बाजार डेटा और संकेतक डेटा खींचेंः ऊपरी ट्रैक, मध्य ट्रैक, निचला ट्रैक, सकारात्मक/नकारात्मक मध्यस्थता मूल्य अंतर।

// 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: प्रविष्टि फ़ंक्शन main में, पूर्व-लेनदेन पूर्व-प्रसंस्करण कोड निष्पादित करें, जो प्रोग्राम शुरू होने के बाद केवल एक बार चलाया जाएगा, जिसमें शामिल हैंः

  • सेटErrorFilter (()) कंसोल में महत्वहीन जानकारी फ़िल्टर करने के लिए
  • exchange.IO ( https://www.squadhelp.com/name/exchange.io?lp=d) ()) व्यापार करने के लिए डिजिटल मुद्रा निर्धारित करने के लिए
  • प्रोग्राम प्रारंभ करने से पहले खींचा गया पिछला चार्ट साफ़ करने के लिए ObjChart reset ())
  • LogProfitReset (()) प्रोग्राम प्रारंभ करने से पहले स्थिति पट्टी जानकारी को साफ़ करने के लिए
//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
}

उपरोक्त पूर्व-लेनदेन पूर्व-प्रसंस्करण को परिभाषित करने के बाद, अगला चरण मतदान मोड में प्रवेश करना और बार-बार ऑनटिक () फ़ंक्शन निष्पादित करना है। यह स्लीप () मतदान के लिए नींद का समय भी सेट करता है, क्योंकि कुछ डिजिटल मुद्रा एक्सचेंजों के एपीआई में एक निश्चित अवधि के लिए अंतर्निहित पहुंच सीमा है।

//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: उपरोक्त रणनीतिक तर्क के अनुसार खरीद और बिक्री ऑपरेशन निष्पादित करें। सबसे पहले, तय करें कि क्या मूल्य और संकेतक की स्थिति मान्य है, फिर तय करें कि क्या स्थिति की स्थिति मान्य है, और अंत में व्यापार () ऑर्डर फ़ंक्शन निष्पादित करें

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

पूर्ण रणनीति

जैसा कि ऊपर बताया गया है, हमने 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. सारांश

इस लेख में रणनीति सिर्फ एक उदाहरण है। असली बॉट सरल नहीं है, लेकिन आप उदाहरण का पालन कर सकते हैं और अपनी जंगली कल्पना का उपयोग कर सकते हैं। यह याद रखना चाहिए कि, मेरे सीमित अनुभव के आधार पर, वर्तमान डिजिटल मुद्रा बाजार में, लगभग सभी शुद्ध वायदा-भविष्य निर्णायक रणनीतियाँ चलाने के लायक नहीं हैं, चाहे वह जोखिम मुक्त त्रिकोणीय निर्णायक हो या क्रॉस-मार्केट निर्णायक। इसका कारण यह है कि कोई फर्क नहीं पड़ता कि डिजिटल मुद्रा विनिमय वायदा बाजार कौन सा है, इसका मार्जिन कानूनी मुद्रा नहीं है। वर्तमान में, लगभग सभी डिजिटल मुद्राओं में वर्ष की शुरुआत के बाद से लगभग 70% की गिरावट आई है। यानी, रणनीति हमेशा मुद्राओं को कमाने के लिए है, लेकिन मुद्रा की कीमत घट रही है। कुल मिलाकर, डिजिटल मुद्रा बाजार ब्लॉकचेन से अलग हो गया है। उस समय की ट्यूलिप की तरह, कीमत हमेशा लोगों की अपेक्षाओं और विश्वास से आती है, और विश्वास कीमत से आता है...


संबंधित

अधिक