ডিজিটাল মুদ্রার ক্রস-পিরিয়ড আর্বিট্রেজ কৌশল বোলিঞ্জার ব্যান্ডের উপর ভিত্তি করে

লেখক:লিডিয়া, তৈরিঃ 2022-12-02 16:58:27, আপডেটঃ 2023-09-20 09:33:29

img

ডিজিটাল মুদ্রার ক্রস-পিরিয়ড আর্বিট্রেজ কৌশল বোলিঞ্জার ব্যান্ডের উপর ভিত্তি করে

I. সংক্ষিপ্তসার

জর্জ সোরস ১৯৮৭ সালে লেখা The Alchemy of Finance এ একটি গুরুত্বপূর্ণ প্রস্তাব পেশ করেছিলেনঃ আমি বিশ্বাস করি যে বাজারের দামগুলি সর্বদা ভবিষ্যতের একটি পক্ষপাতমূলক দৃষ্টিভঙ্গি উপস্থাপন করে বলে ভুল। বাজারের দক্ষতা অনুমানটি কেবল একটি তাত্ত্বিক অনুমান। আসলে, বাজারের অংশগ্রহণকারীরা সর্বদা যুক্তিসঙ্গত নয় এবং প্রতিটি সময়ে, অংশগ্রহণকারীরা সম্পূর্ণরূপে সমস্ত তথ্য পেতে এবং বস্তুনিষ্ঠভাবে ব্যাখ্যা করতে পারে না। তদতিরিক্ত, এটি যদি একই তথ্য হয় তবে প্রত্যেকের প্রতিক্রিয়া আলাদা। অর্থাৎ, দাম নিজেই ইতিমধ্যে বাজারের অংশগ্রহণকারীদের ভুল প্রত্যাশা ধারণ করে, তাই মূলত, বাজারের দাম সর্বদা ভুল। এটি arbitrageurs এর মুনাফার উত্স হতে পারে।

২. কৌশলগত নীতি

উপরের নীতি অনুসারে, আমরা জানতে পারি যে একটি অকার্যকর ফিউচার বাজারে, বিভিন্ন সময়কালে বিতরণ চুক্তিতে বাজারের প্রভাবের কারণ সবসময় সিঙ্ক্রোন নয় এবং মূল্য নির্ধারণ সম্পূর্ণ কার্যকর নয়। তারপরে, বিভিন্ন সময়ে একই লেনদেনের বস্তুর বিতরণ চুক্তির দামের ভিত্তিতে, যদি দুটি দামের মধ্যে একটি বড় মূল্য পার্থক্য থাকে তবে আমরা ক্রস-পিরিয়ড সালিশের জন্য একই সময়ে বিভিন্ন সময়ে ফিউচার চুক্তি কিনতে এবং বিক্রি করতে পারি। পণ্যের ফিউচারগুলির মতো, ডিজিটাল মুদ্রারও ক্রস-পিরিয়ড সালিশ চুক্তি পোর্টফোলিও রয়েছে। উদাহরণস্বরূপ, ওকেএক্স এক্সচেঞ্জে রয়েছেঃ ইটিসি চলতি সপ্তাহ, ইটিসি পরের সপ্তাহ, ইটিসি ত্রৈমাসিক। উদাহরণস্বরূপ, অনুমান করুন যে ইটিসির চলতি সপ্তাহ এবং ইটিসির চতুর্থাংশের মধ্যে দামের পার্থক্য দীর্ঘ সময় ধরে 5 এর কাছাকাছি থাকে। যদি দামের পার্থক্য একদিন 7 এ পৌঁছায় তবে আমরা আশা করি যে ভবিষ্যতে দামের পার্থক্যটি 5 এ ফিরে আসবে। তারপরে আমরা সেই সপ্তাহে ইটিসি বিক্রি করতে পারি এবং একই সাথে দামের পার্থক্যটি হ্রাস করতে ইটিসি চতুর্থাংশ কিনতে পারি, বিপরীত। যদিও এই দামের পার্থক্য বিদ্যমান, সময়সাপেক্ষ ম্যানুয়াল অপারেশন, দুর্বল নির্ভুলতা এবং দামের পরিবর্তনের প্রভাবের কারণে ম্যানুয়াল সালিশে অনেক অনিশ্চয়তা রয়েছে। পরিমাণগত সালিশের আকর্ষণ পরিমাণগত মডেল এবং সালিশ ট্রেডিং কৌশলগুলি তৈরির মাধ্যমে সালিশের সুযোগগুলি ক্যাপচার করতে এবং পাশাপাশি প্রোগ্রামযুক্ত অ্যালগরিদমগুলির মাধ্যমে এক্সচেঞ্জগুলিতে স্বয়ংক্রিয়ভাবে ট্রেডিং অর্ডার স্থাপন করতে, যাতে সুযোগগুলি দ্রুত এবং সঠিকভাবে ক্যাপচার করতে এবং দক্ষতার সাথে এবং স্থিতিশীলভাবে মুনাফা অর্জন করতে পারে।

III. কৌশলগত যুক্তি

এই নিবন্ধটি আপনাকে শিখিয়ে দেবে যে কীভাবে FMZ কোয়ান্ট ট্রেডিং প্ল্যাটফর্ম এবং OKEX এক্সচেঞ্জে ETC ফিউচার চুক্তি ব্যবহার করা যায় তাৎক্ষণিক সালিশের সুযোগগুলি কীভাবে ক্যাপচার করা যায়, যে লাভগুলি প্রতিবার দেখা যায় তা দখল করা যায় এবং একটি সহজ সালিশ কৌশল দিয়ে ডিজিটাল মুদ্রা ট্রেডিংয়ে যে ঝুঁকিগুলি দেখা দিতে পারে তা হিজিং করা যায়।

ডিজিটাল মুদ্রার জন্য একটি ক্রস-পিরিয়ড আরবিট্রেজ কৌশল তৈরি করুন

অসুবিধা: স্বাভাবিক

কৌশলগত পরিবেশ

  • লেনদেনের উদ্দেশ্যঃ ইথার ক্লাসিক (ইটিসি)
  • স্প্রেড ডেটাঃ ইটিসি চলতি সপ্তাহ - ইটিসি ত্রৈমাসিক (সমন্বয় পরীক্ষা বাদ দিন)
  • লেনদেনের সময়ঃ ৫ মিনিট
  • পজিশন মেলেঃ ১ঃ১
  • লেনদেনের ধরনঃ একই ধরনের ক্রস পিরিয়ড

কৌশলগত যুক্তি

  • দামের পার্থক্যের সাথে দীর্ঘ পজিশন খোলার শর্তাবলীঃ যদি বর্তমান অ্যাকাউন্টে কোনও অবস্থান না থাকে এবং দামের পার্থক্যটি বোলের নীচের সীমার চেয়ে কম হয় তবে দামের পার্থক্যটি দীর্ঘ করুন। অর্থাৎ, সপ্তাহের জন্য খোলার অবস্থান ইটিসি কিনুন, ত্রৈমাসিকের জন্য খোলার অবস্থান ইটিসি বিক্রি করুন।
  • দামের পার্থক্যের সাথে শর্ট পজিশন খোলার শর্তাবলীঃ যদি বর্তমান অ্যাকাউন্টে কোনও অবস্থান না থাকে এবং দামের পার্থক্য বোলের উপরের সীমার চেয়ে বেশি হয় তবে দামের পার্থক্যটি শর্ট করুন। অর্থাৎ, সপ্তাহের জন্য খোলা অবস্থানগুলি ইটিসি বিক্রি করুন, ত্রৈমাসিকের জন্য খোলা অবস্থানগুলি ইটিসি কিনুন।
  • দামের পার্থক্যের সাথে দীর্ঘ পজিশন বন্ধ করার শর্তাবলীঃ যদি বর্তমান অ্যাকাউন্টে চলমান সপ্তাহে ইটিসির চলমান দীর্ঘ অর্ডার থাকে এবং ইটিসির চতুর্থাংশের চলমান শর্ট অর্ডার থাকে এবং দামের পার্থক্য বলের মাঝামাঝি সীমার চেয়ে বড় হয় তবে দামের পার্থক্যটি বন্ধ করুন। অর্থাৎ, সপ্তাহের জন্য বন্ধ পজিশন ইটিসি বিক্রি করুন, চতুর্থাংশের জন্য বন্ধ পজিশন ইটিসি কিনুন।
  • দামের পার্থক্যের সাথে শর্ট পজিশন বন্ধ করার শর্তাবলীঃ যদি বর্তমান অ্যাকাউন্টে চলমান সপ্তাহে ইটিসির চলমান শর্ট অর্ডার থাকে এবং ইটিসির চতুর্থাংশের চলমান দীর্ঘ অর্ডার থাকে এবং দামের পার্থক্যটি বোলের মাঝের সীমার চেয়ে কম হয় তবে দামের পার্থক্যটি বন্ধ করুন। অর্থাৎ, সপ্তাহের জন্য ইটিসির বন্ধ পজিশন কিনুন, চতুর্থাংশের জন্য ইটিসির বন্ধ পজিশন বিক্রয় করুন।

IV. একটি কৌশলগত কাঠামো লিখুন

উপরের একটি সহজ যুক্তিগত বর্ণনা ক্রস পিরিয়ড আর্বিট্রেজ কৌশল ডিজিটাল মুদ্রা. সুতরাং কিভাবে প্রোগ্রাম আমাদের ধারনা বাস্তবায়ন করতে? আমরা FMZ কোয়ান্ট ট্রেডিং প্ল্যাটফর্ম উপর কাঠামো নির্মাণ করার চেষ্টা করুন.

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. লেখার কৌশল

কৌশলগত ধারণা এবং লেনদেনের প্রক্রিয়া অনুযায়ী কৌশলগত কাঠামো সহজেই স্থাপন করা যেতে পারে। সমগ্র কৌশলটি তিনটি ধাপে সরলীকৃত করা যেতে পারেঃ লেনদেনের আগে প্রাক-প্রক্রিয়াকরণ। তথ্য সংগ্রহ এবং গণনা করুন। অর্ডার দাও আর পরে নিয়ে যাও। এর পর, প্রকৃত লেনদেন প্রক্রিয়া এবং লেনদেনের বিবরণ অনুযায়ী কৌশল কাঠামোতে প্রয়োজনীয় বিস্তারিত কোডটি পূরণ করতে হবে।

লেনদেনের আগে প্রাক-প্রক্রিয়াকরণ ধাপ ১ঃ প্রয়োজনীয় গ্লোবাল ভেরিয়েবলগুলিকে গ্লোবাল স্কোপে ঘোষণা করুন।

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

পদক্ষেপ ২ঃ কৌশলটির বাহ্যিক পরামিতিগুলি কনফিগার করুন।

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

কে-লাইন এবং ইন্ডিকেটর ফাংশনঃ বোল ((() একটি নতুন কে-লাইন ক্রম ধনাত্মক সালিশ / নেতিবাচক সালিশ মূল্য পার্থক্য তথ্য অনুযায়ী সংশ্লেষিত হয়। উপরের ট্র্যাক, মাঝারি ট্র্যাক এবং নিম্ন ট্র্যাকের তথ্য বোল সূচক দ্বারা গণনা করা হয়।

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

ধাপ ৪ঃ এন্ট্রি ফাংশন main (() এ, প্রাক-ট্রানজেকশন প্রাক-প্রক্রিয়াকরণ কোডটি চালান, যা প্রোগ্রামটি শুরু হওয়ার পরে কেবল একবার চালানো হবে, যার মধ্যে রয়েছেঃ

  • কনসোলে অপ্রয়োজনীয় তথ্য ফিল্টার করতে SetErrorFilter (())
  • 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
}

উপরের প্রাক-ট্রানজেকশন প্রাক-প্রক্রিয়াকরণ সংজ্ঞায়িত হওয়ার পরে, পরবর্তী পদক্ষেপটি পোলিং মোডে প্রবেশ করা এবং onTick (()) ফাংশনটি বারবার সম্পাদন করা। এটি ঘুম () পোলিংয়ের জন্য ঘুমের সময়ও সেট করে, কারণ কিছু ডিজিটাল মুদ্রা এক্সচেঞ্জের এপিআইতে নির্দিষ্ট সময়ের জন্য অন্তর্নির্মিত অ্যাক্সেস সীমা রয়েছে।

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

তথ্য সংগ্রহ এবং গণনা করুন ধাপ ১ঃ ট্রেডিং লজিক ব্যবহারের জন্য বেসিক ডেটা অবজেক্ট, অ্যাকাউন্ট ব্যালেন্স এবং বোল সূচক তথ্য সংগ্রহ করুন।

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

ধাপ ২ঃ অর্ডার দেওয়ার পরে, অনিয়মিত অর্ডার এবং একটি একক চুক্তির ধারণের মতো অস্বাভাবিক পরিস্থিতি মোকাবেলা করা প্রয়োজন। এবং চার্ট আঁকুন।

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

সপ্তম সংক্ষিপ্ত বিবরণ

এই নিবন্ধে কৌশলটি কেবল একটি উদাহরণ। আসল বটটি সহজ নয়, তবে আপনি উদাহরণটি অনুসরণ করতে পারেন এবং আপনার নিজের বন্য কল্পনা ব্যবহার করতে পারেন। এটি মনে করিয়ে দেওয়া উচিত যে, আমার সীমিত অভিজ্ঞতার ভিত্তিতে, বর্তমান ডিজিটাল মুদ্রা বাজারে, প্রায় সমস্ত খাঁটি ফিউচার-ফিউচার আরবিট্রেজ কৌশলগুলি চালানোর যোগ্য নয়, এটি ঝুঁকিমুক্ত ত্রিভুজাকার আরবিট্রেজ বা ক্রস-মার্কেট আরবিট্রেজ কিনা। কারণটি হ'ল ডিজিটাল মুদ্রা বিনিময় ফিউচার বাজার যাই হোক না কেন, এর মার্জিন আইনী মুদ্রা নয়। বর্তমান সময়ে, প্রায় সমস্ত ডিজিটাল মুদ্রা বছরের শুরু থেকে প্রায় 70% হ্রাস পেয়েছে। অর্থাৎ, কৌশলটি সর্বদা মুদ্রা উপার্জন করা, তবে মুদ্রার দাম হ্রাস পাচ্ছে। সামগ্রিকভাবে, ডিজিটাল মুদ্রা বাজারটি ব্লকচেইন থেকে বিচ্ছিন্ন হয়ে গেছে বলে মনে হচ্ছে। সেই সময় টলিপসের মতো, দাম সর্বদা মানুষের প্রত্যাশা এবং আত্মবিশ্বাস থেকে আসে এবং আত্মবিশ্বাস দাম থেকে আসে...


সম্পর্কিত

আরো