ট্রেডিং অর্ডারের নটিফিকেশন মূল্যঃ 1000, // অর্ডার দেওয়ার মূল্য; লক্ষ্য করুন বাজার অর্ডারের এই বৈশিষ্ট্যটি 0 বা -1 হতে পারে পরিমাণঃ 10, // অর্ডার পরিমাণ স্থাপন; লক্ষ্য করুন বাজার অর্ডার এই বৈশিষ্ট্য অর্থ পরিমাণ হতে পারে, মুদ্রা সংখ্যা না DealAmount : 10, // এক্সিকিউটেড ভলিউম; যদি প্ল্যাটফর্ম ইন্টারফেস এই ধরনের তথ্য প্রদান করে না, সম্ভবত পূরণ করতে 0 ব্যবহার করুন AvgPrice : 1000, // গড় কার্যকর মূল্য; লক্ষ্য করুন কিছু প্ল্যাটফর্ম এই তথ্য প্রদান করে না. অবস্থাঃ 1, // অর্ডার অবস্থা; ধ্রুবকগুলিতে অর্ডার অবস্থা উল্লেখ করুন, যেমন ORDER_STATE_CLOSED প্রকারঃ 0, // অর্ডার টাইপ; ধ্রুবকগুলিতে অর্ডার টাইপ উল্লেখ করুন, যেমন ORDER_TYPE_BUY অফসেটঃ 0 // ক্রিপ্টোকারেন্সি ফিউচারগুলির অর্ডার ডেটাতে অর্ডার খোলা এবং বন্ধের দিক;ORDER_OFFSET_OPEN হল খোলা অবস্থান, যখন ORDER_OFFSET_CLOSE হল বন্ধের দিক ContractType : // এই বৈশিষ্ট্যটি স্পট অর্ডারের জন্য , যথা শূন্য স্ট্রিং; ফিউচার অর্ডারের বৈশিষ্ট্যটি হ'ল নির্দিষ্ট চুক্তি কোড }


##### MarketOrder

Market depth order, that is, ```exchange.GetDepth()``` returns the data structure of the elements in the **Bids** and **Asks** arrays in the data.

```javascript
{
    Price   : 1000,              // Price
    Amount  : 1                  // Volume
}
গভীরতা

বাজারের গভীরতা ফাংশন দ্বারা ফিরে আসেexchange.GetDepth().

{
    Asks    : [...],             // The array of sell orders, namely MarketOrder array, sorted by price from low to high
    Bids    : [...],             // The array of buy orders, namely MarketOrder array, sorted by price from high to low
    Time    : 1567736576000      // Millisecond-level timestamp
}
অ্যাকাউন্ট

অ্যাকাউন্টের তথ্য, ফাংশন দ্বারা ফেরতexchange.GetAccount()স্ট্রাকচারে ফিরে আসা তথ্য বর্তমানে সেট করা ট্রেডিং জোড়া এবং চুক্তি কোডগুলির সাথে সম্পর্কিত।

{
    Info            : {...},     // After requesting the platform interface, this attribute is not available in the raw data that the platform interface responds to, during the backtest
    Balance         : 1000,      // The available amount of quote currency; if the trading pair is BTC_USDT in the spot trading, "balance" refers to the current USDT amount. In the USDT-margined futures contract, "balance" refers to the available margin amount in USDT
    FrozenBalance   : 0,         // Here "balance" refers to the frozen amount of the assets for pending orders
    Stocks          : 1,         // The available amount of base currency; if the trading pair is BTC_USDT in the spot trading, "stocks" refers to the current BTC amount. In the crypto-margined futures contract, "stocks" refers to the available margin amount (base currency)
    FrozenStocks    : 0          // Here "stocks" refers to the frozen amount of the assets for pending orders
}
অবস্থান

ফিউচার ট্রেডিংয়ের পজিশনের তথ্যের জন্য,অ্যারেএরPositionগঠন ফাংশন দ্বারা ফিরে আসেexchange.GetPosition() function.

{
    Info            : {...},     // After requesting the platform interface, this attribute is not available in the raw data that the platform interface responds to, during the backtest
    MarginLevel     : 10,        // The leverage size of positions; if this data is not provided by the platform interface, fill in the data by calculation, possibly with errors
    Amount          : 100,       // Position volume; the contract quantity of positions is normally positive integer. Notice every platform might have different contract specifications, such as contract multiplier and value, etc., so the rules for ordering might be different; for example, Binance contract might order by 0.1
    FrozenAmount    : 0,         // The quantity of frozen positions, used as the number of temporary position freeze when close positions and pending orders
    Price           : 10000,     // Average position price; in principle, the attribute is the average price of the entire position (which does not involve in the settlement); if the platform interface does not provide the data, use the existing average position price of the platform to fill in (which involves in the settlement)
    Profit          : 0,         // Position floating profit and loss, namely the failure of realizing position profit and loss. If the platform interface does not provide the data, use other profit and loss data from the interface to fill in; the unit of the profit and loss values is the same as the unit of the current contract margin 

    Type            : 0,         // PD_LONG is a long position, while PD_SHORT is a short position
    ContractType    : "quarter", // Contract code; for more details, refer to the transmitted parameters in the description of the function "SetContractType"
    Margin          : 1          // Margin occupied by positions; if the platform interface does not provide the data, use 0 to fill in
}

ক্রিপ্টোকারেন্সির ফিউচারগুলির জন্য, মনোযোগ দিনPositionফাংশন দ্বারা ফেরত গঠন অ্যারেexchange.GetPosition(). যেমন তার অবস্থান ডাটা স্ট্রাকচার মধ্যে বৈশিষ্ট্য জন্য, যেমনFrozenAmount, ProfitএবংMargin, বিভিন্ন ডেটা সংজ্ঞা বিভিন্ন বিনিময় বস্তু দ্বারা ফিরে আসতে পারে, যখন তারা কলexchange.GetPosition()উদাহরণস্বরূপ, কিছু এক্সচেঞ্জ অবস্থান হিমায়িত তথ্য অন্তর্ভুক্ত করে না, যা নির্দেশ করেFrozenAmountযদি কিছু তথ্য গণনা করার প্রয়োজন হয়, আপনি বৈশিষ্ট্য মধ্যে উৎস তথ্য ব্যবহার করতে পারেনInfoগণনা ও বিশ্লেষণের জন্য।

বিশ্বব্যাপী ফাংশন

সংস্করণ

Version()সিস্টেমের বর্তমান সংস্করণ নম্বর ফেরত দেয়; ফেরত মানঃ স্ট্রিং টাইপ।

ঘুম ((মিলেসেকেন্ড)

Sleep(Millisecond), স্লিপ ফাংশন, একটি নির্দিষ্ট সময়ের জন্য প্রোগ্রাম বিরতি দেয়। পরামিতি মানঃMillisecondএকটি সংখ্যা টাইপ। প্যারামিটার ইউনিট মিলিসেকেন্ড, উদাহরণস্বরূপঃSleep(1000)মানে এক সেকেন্ডের জন্য ঘুমানো। স্লিপ টাইম ১ মিলিসেকেন্ডের কম হলে সাপোর্ট অপারেশন, যেমন সেটিংSleep (0.1). সর্বনিম্ন সমর্থিত প্যারামিটার হল0.000001এক ন্যানোসেকেন্ড ঘুমের সমান1e-6 milliseconds.

নোটঃ যখন আপনি কৌশল লিখুনPythonভাষা, ফাংশনSleep(Millisecond)যেমন পোলিং ব্যবধান এবং অপেক্ষা সময় অপারেশন জন্য ব্যবহার করা উচিত নয়।time.time(second)এরtimeগ্রন্থাগারPythonকারণ যখন ফাংশনটি ব্যবহার করা হয়time.time(second)কৌশল, কৌশল প্রোগ্রাম আসলে একটি নির্দিষ্ট সংখ্যক সেকেন্ডের জন্য অপেক্ষা করবে (প্যারামিটারsecondএটি একটি খুব ধীর কৌশল ব্যাকটেস্টের দিকে পরিচালিত করবে।

এটা ভার্চুয়াল ((()

IsVirtual(), এটি একটি সিমুলেটেড ব্যাকটেস্ট কিনা তা নির্ধারণ করতে। রিটার্ন মানঃ bool টাইপ। সিমুলেটেড ব্যাকটেস্টের অবস্থা রিটার্ন করেtrue, এবং আসল বট ফিরে আসেfalse.

মেইল ((...)

Mail(smtpServer, smtpUsername, smtpPassword, mailTo, title, body)একটি মেইল পাঠানোর ফাংশন। প্যারামিটার মানঃ সব স্ট্রিং টাইপের। রিটার্ন মানঃ bool টাইপ;trueসফলভাবে পাঠানোর পর ফেরত দেওয়া হয়।smtpServerপাঠানো মেইলবক্সের জন্য কাজ করেsmtp; smtpUsernameহল মেইলবক্স অ্যাকাউন্ট;smtpPasswordহল মেইলবক্সের STMP পাসওয়ার্ড;mailToহচ্ছে প্রাপক মেইলবক্স অ্যাকাউন্ট;titleপাঠানো মেইলের নাম;bodyপাঠানো মেইলের বিষয়বস্তু, উদাহরণস্বরূপঃ

function main(){
    Mail("smtp.163.com", "asdf@163.com", "password", "111@163.com", "title", "body")
}
def main():
    Mail("smtp.163.com", "asdf@163.com", "password", "111@163.com", "title", "body")
void main() {
    Mail("smtp.163.com", "asdf@163.com", "password", "111@163.com", "title", "body");
}
  • দ্যMail_Goফাংশন ফাংশন একটি অ্যাসিনক্রোন সংস্করণMail: এর ব্যবহার ফাংশন অনুরূপexchange.Go.

    function main() {
        var r1 = Mail_Go("smtp.163.com", "asdf@163.com", "password", "111@163.com", "title", "body")
        var r2 = Mail_Go("smtp.163.com", "asdf@163.com", "password", "111@163.com", "title", "body")
        
        var ret1 = r1.wait()
        var ret2 = r2.wait()
        
        Log("ret1:", ret1)
        Log("ret2:", ret2)
    }
    
    # Not supported
    
    // Not supported
    

নোটঃ আলিবাবা ক্লাউড সার্ভার কিছু পোর্ট ব্লক করতে পারে, যাতে মেইল পাঠানো যাবে না. যদি আপনি পোর্ট পরিবর্তন করতে হবে, আপনি সরাসরি প্রথম পরামিতিতে পোর্ট নম্বর যোগ করতে পারেন, উদাহরণস্বরূপ,smtp.qq.com:587(QQmail), পোর্ট পরীক্ষার জন্য উপলব্ধ. যদি কোন ত্রুটি ঘটে:unencrypted connection, আপনি পরামিতি বিন্যাস পরিবর্তন করতে হবেsmtpServerফাংশনেMailনিম্নলিখিত বিষয়গুলো:ssl://xxxxx.com:xxxউদাহরণস্বরূপ, QQmail এর SMTP ssl পদ্ধতিঃssl://smtp.qq.com:465অথবাsmtp://xxxxx.com:xxx.

সেটErrorFilter(...)

ErrorFilter(RegEx)প্যারামিটার মানঃ স্ট্রিং টাইপ। এই নিয়মিত অভিব্যক্তি দ্বারা মিলিত ত্রুটিগুলি লগ সিস্টেমে আপলোড করা হবে না, এবং এটি একাধিকবার কল করা যেতে পারে (ঘন ঘন ত্রুটি রিপোর্টিং দ্বারা সৃষ্ট ডাটাবেস ফাইল সম্প্রসারণ রোধ করতে ডকার সামগ্রীতে লগ / বটগুলিতে সংশ্লিষ্ট বট আইডির ডাটাবেস ফাইলটিতে ফিল্টার করা লগগুলি লেখা হবে না) ।

function main() {
    SetErrorFilter("502:|503:|tcp|character|unexpected|network|timeout|WSARecv|Connect|GetAddr|no such|reset|http|received|EOF|reused")
}
def main():
    SetErrorFilter("502:|503:|tcp|character|unexpected|network|timeout|WSARecv|Connect|GetAddr|no such|reset|http|received|EOF|reused")
void main() {
    SetErrorFilter("502:|503:|tcp|character|unexpected|network|timeout|WSARecv|Connect|GetAddr|no such|reset|http|received|EOF|reused");
}

একটি ইন্টারফেসের ত্রুটি তথ্য ফিল্টার করুনঃ

function main() {
    // Randomly check a non-existent order with ID 123; intentionally make the interface report an error
    var order = exchange.GetOrder("123")
    Log(order)
    // Filter http502 errors and GetOrder interface errors; after set the error filter, the second time to call GetOrder no longer reports errors
    SetErrorFilter("502:|GetOrder")
    order = exchange.GetOrder("123")
    Log(order)
}
def main():
    order = exchange.GetOrder("123")
    Log(order)
    SetErrorFilter("502:|GetOrder")
    order = exchange.GetOrder("123")
    Log(order)
void main() {
    TId orderId;
    Order order = exchange.GetOrder(orderId);
    Log(order);
    SetErrorFilter("502:|GetOrder");
    order = exchange.GetOrder(orderId);
    Log(order);
}

GetPid ((()

GetPid()বট প্রসেস আইডি ফেরত দেয়। ফেরত মানঃ স্ট্রিং টাইপ।

function main(){
    var id = GetPid()
    Log(id)
}
def main():
    id = GetPid()
    Log(id)
void main() {
    auto id = GetPid();
    Log(id);
}

GetLastError ((()

GetLastError()সর্বশেষ ত্রুটি তথ্য পায়; সাধারণত, এটি ব্যবহার করার প্রয়োজন হয় না, কারণ প্রোগ্রাম স্বয়ংক্রিয়ভাবে লগ সিস্টেমে ত্রুটি তথ্য আপলোড করবে। রিটার্ন মানঃ স্ট্রিং টাইপ। আপনি ফাংশন কল করার পরেGetLastError(), ত্রুটি ক্যাশে সাফ করা হবে; যখন এটি আবার কল করা হবে, শেষবার রেকর্ড করা ত্রুটি তথ্য ফেরত দেওয়া হবে না।

function main(){
    // Because the order with ID number of 123 does not exist, an error is reported
    exchange.GetOrder("123")
    var error = GetLastError()
    Log(error)
}
def main():
    exchange.GetOrder("123")
    error = GetLastError()
    Log(error)
void main() {
    // The type of order ID: TId; so no string can be passed in, and we can trigger it by placing an order that does not meet the exchange specifications
    exchange.GetOrder(exchange.Buy(1, 1));
    auto error = GetLastError();
    Log(error);
}

GetCommand ((()

GetCommand()ইন্টারেক্টিভ কমান্ডগুলি (utf-8) পায়। এটি কৌশল ইন্টারেক্টিভ ইন্টারফেসের দ্বারা প্রেরিত কমান্ডটি পায় এবং ক্যাশে সাফ করে; যদি কোনও কমান্ড না থাকে তবে এটি একটি খালি স্ট্রিং ফেরত দেয়। ফিরে আসা কমান্ড ফর্ম্যাটটি হলbutton name: parameter; যদি ইন্টারেক্টিভ কন্ট্রোলগুলিতে কোনও প্যারামিটার না থাকে (উদাহরণস্বরূপ, ইনপুট বক্স ছাড়াই বোতাম নিয়ন্ত্রণ), কমান্ডটি বোতামের নাম।

function main(){
    while(true) { 
        var cmd = GetCommand()
        if (cmd) { 
            Log(cmd)
        }
        Sleep(1000) 
    }
}
def main():
    while True:
        cmd = GetCommand()
        if cmd:
            Log(cmd)
        Sleep(1000)
void main() {
    while(true) {
        auto cmd = GetCommand();
        if(cmd != "") {
            Log(cmd);
        }
        Sleep(1000);
    }
}

অন্তর্নিহিত সিস্টেম একটি সারি কাঠামো আছে ইন্টারেক্টিভ কমান্ড রেকর্ড করতে. যখন ফাংশনGetCommand()কল করা হলে, ক্যোয়ারে প্রথম প্রবেশ করা ইন্টারেক্টিভ কমান্ডটি বের করা হবে (যদি কোনও ইন্টারেক্টিভ কমান্ড না থাকে, তাহলে একটি খালি স্ট্রিং) ।

ইন্টারেক্টিভ কন্ট্রোল ব্যবহারের উদাহরণ; কৌশল সম্পাদনা ইন্টারফেসে ইন্টারেক্টিভ কন্ট্রোল সেট করুনঃ

img

পরিকল্পনায় ইন্টারেক্টিভ কোড ডিজাইন করুনঃ

function main() {
    while (true) {
        LogStatus(_D())
        var cmd = GetCommand()
        if (cmd) {
            Log("cmd:", cmd)    
            var arr = cmd.split(":")
            if (arr[0] == "buy") {
                Log("Buy, the control without quantity")
            } else if (arr[0] == "sell") {
                Log("Sell, the control with quantity: ", arr[1])
            } else {
                Log("Other controls trigger:", arr)
            }
        }
        Sleep(1000)
    } 
}
def main():
    while True:
        LogStatus(_D())
        cmd = GetCommand()
        if cmd:
            Log("cmd:", cmd)
            arr = cmd.split(":")
            if arr[0] == "buy":
                Log("Buy, the control without quantity")
            elif arr[0] == "sell":
                Log("Sell, the control with quantity:", arr[1])
            else:
                Log("Other controls trigger:", arr)
        Sleep(1000)
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
void split(const string& s,vector<string>& sv,const char flag = ' ') {
    sv.clear();
    istringstream iss(s);
    string temp;

    while (getline(iss, temp, flag)) {
        sv.push_back(temp);
    }
    return;
}

void main() {
    while(true) {
        LogStatus(_D());
        auto cmd = GetCommand();
        if (cmd != "") {
            vector<string> arr;
            split(cmd, arr, ':');
            if(arr[0] == "buy") {
                Log("Buy, the control without quantity");
            } else if (arr[0] == "sell") {
                Log("Sell, the control with quantity:", arr[1]);
            } else {
                Log("Other controls trigger:", arr);
            }
        }
        Sleep(1000);
    }
}

GetMeta ((()

ফাংশনGetMeta()এর মান প্রদান করেMetaযখন কৌশল টোকেন তৈরি করা হয়, তখন ফাংশনের রিটার্ন মান স্ট্রিং টাইপের হয়। অ্যাপ্লিকেশনঃ উদাহরণস্বরূপ, কৌশলটি বিভিন্ন ভাড়াটেদের জন্য সম্পদ সীমাবদ্ধ করতে হবে। দ্রষ্টব্যঃ যখন কৌশল টোকেন উৎপন্ন হয়,Meta190 স্ট্রিং অতিক্রম করতে পারে না; ফাংশন, শুধুমাত্র প্রকৃত ট্রেডিং জন্য প্রযোজ্য এবং সর্বশেষ ডকার প্রয়োজন। যদি উৎস তথ্য সেট করা হয় না যখন কৌশল টোকেন উৎপন্ন হয়,GetMeta()null প্রদান করে।

আবেদনপত্রের মাধ্যমে প্রদর্শিত সংশ্লিষ্ট তথ্য

function main() {
    // The largest assets value of quote currency allowed by the strategy
    
    // Get the metadata generated when the strategy token is established
    var level = GetMeta()
    
    // Check the corresponding conditions of "Meta"
    if (level == "level1") {
        // "-1" indicates no limitation 
        maxBaseCurrency = -1       
    } else if (level == "level2") {
        maxBaseCurrency = 10     
    } else if (level == "level3") {
        maxBaseCurrency = 1
    } else {
        maxBaseCurrency = 0.5
    }
    
    while(1) {
        Sleep(1000)
        var ticker = exchange.GetTicker()
        
        // Check the assets value
        var acc = exchange.GetAccount()
        if (maxBaseCurrency != -1 && maxBaseCurrency < acc.Stocks + acc.FrozenStocks) {
            // Stop the execution of the strategy trading logic 
            LogStatus(_D(), "level:", level, "The position exceeds the strategy token's using limitation, and stop the execution of the strategy trading logic!")
            continue
        }
        
        // Other trading logic
        
        // Export the information of status bar normally
        LogStatus(_D(), "level:", level, "The strategy runs normally! Ticker data: \n", ticker)
    }
}
def main():
    maxBaseCurrency = null
    level = GetMeta()
    
    if level == "level1":
        maxBaseCurrency = -1       
    elif level == "level2":
        maxBaseCurrency = 10     
    elif level == "level3":
        maxBaseCurrency = 1
    else:
        maxBaseCurrency = 0.5
    
    while True:
        Sleep(1000)
        ticker = exchange.GetTicker()        
        acc = exchange.GetAccount()
        if maxBaseCurrency != -1 and maxBaseCurrency < acc["Stocks"] + acc["FrozenStocks"]:
            LogStatus(_D(), "level:", level, "The position exceeds the strategy token's using limitation, and stop the execution of the strategy trading logic!")
            continue        
        
        # Other trading logic
        
        # Export the information of status bar normally
        LogStatus(_D(), "level:", level, "The strategy runs normally! Ticker data: \n", ticker)
void main() {
    auto maxBaseCurrency = 0.0;
    auto level = GetMeta();
    
    if (level == "level1") {
        maxBaseCurrency = -1;  
    } else if (level == "level2") {
        maxBaseCurrency = 10;
    } else if (level == "level3") {
        maxBaseCurrency = 1;
    } else {
        maxBaseCurrency = 0.5;
    }
    
    while(1) {
        Sleep(1000);
        auto ticker = exchange.GetTicker();  
        auto acc = exchange.GetAccount();
        if (maxBaseCurrency != -1 && maxBaseCurrency < acc.Stocks + acc.FrozenStocks) {
            // Stop the execution of the strategy trading logic
            LogStatus(_D(), "level:", level, "The position exceeds the strategy token's using limitation, and stop the execution of the strategy trading logic!");
            continue;
        }
        
        // Other trading logic
        
        // Export the information of status bar normally
        LogStatus(_D(), "level:", level, "The strategy runs normally! Ticker data: \n", ticker);
    }
}

ডায়াল করুন...

Dial(Address, Timeout), মূল সকেট অ্যাক্সেস, সমর্থনtcp, udp, tlsএবংunixপ্যারামিটার মানঃAddressএকটি স্ট্রিং টাইপ হয়; ইউনিট দ্বিতীয় হয়; যদি সময় আউট হয়, ফাংশনDial(...)একটি শূন্য মান প্রদান করে।

এর বিস্তারিত বর্ণনাAddressপ্যারামিটারঃ

প্যারামিটার বিবরণ
ফাংশন সেট করার জন্য পরামিতিDial যোগ করে পৃথক করুন|সাধারণ ঠিকানার পরে চিহ্নঃwss://ws.okx.com:8443/ws/v5/publicযদি থাকে;|প্যারামিটার স্ট্রিং এর অক্ষর, ব্যবহার||সঙ্গে প্রতিটি পরামিতি সংযোগ&উদাহরণস্বরূপ, ss5 প্রক্সি এবং কম্প্রেশন পরামিতি একসাথে সেট করা হয়ঃDial("wss://ws.okx.com:8443/ws/v5/public|proxy=socks5://xxx:9999&compress=gzip_raw&mode=recv").
ws প্রোটোকলে, ডেটা কম্প্রেশনের সম্পর্কিত পরামিতিঃcompress=parameter value কম্প্রেস হল কম্প্রেস পদ্ধতি; কম্প্রেস পরামিতিগুলি নির্বাচন করা যেতে পারেgzip_rawএবংgzip, ইত্যাদি. যদি gzip পদ্ধতিটি অ-মানক gzip হয়, আপনি এক্সটেনশন পদ্ধতি ব্যবহার করতে পারেনঃgzip_raw, অর্থাৎ, সেটিং যোগ করুনcompress=gzip_rawবিভাজকের পরে|, এবং ব্যবহার&প্রতীক এবং পরবর্তী মোড প্যারামিটার পৃথক করতে হবে।
ws প্রোটোকলে, ডেটা কম্প্রেশনের সম্পর্কিত পরামিতিঃmode=parameter value মোড হল মোড, যার মধ্যে তিনটি বিকল্প রয়েছে, যথাঃdual, sendএবংrecv. dualএটি দ্বি-দিকের, কম্প্রেসড ডেটা প্রেরণ ও গ্রহণ করে।sendকম্প্রেসড ডেটা পাঠানো।recvকম্প্রেসড ডেটা গ্রহণ এবং স্থানীয়ভাবে এটি decompress হয়।
জুতাগুলোকে সেট করার জন্য সংশ্লিষ্ট পরামিতি5 proxy:proxy=parameter value প্রক্সি হল ss5 প্রক্সি সেটিং; প্যারামিটার মান বিন্যাসঃsocks5://name:pwd@192.168.0.1:1080name হল ss5 সার্ভারের ব্যবহারকারীর নাম; pwd হল ss5 সার্ভারের লগইন পাসওয়ার্ড; 1080 হল ss5 সার্ভারের পোর্ট
ws প্রোটোকলে, অন্তর্নিহিত অটো-রি-কানেক্ট সেটিং করার জন্য সংশ্লিষ্ট পরামিতিঃreconnect=parameter value 'পুনরায় সংযোগ' মানে 'পুনরায় সংযোগ' সেট করা কি না;reconnect=trueপুনরায় সংযোগের জন্য কল করা হয়; ডিফল্ট সেটিং পুনরায় সংযোগ না করা।
ws প্রোটোকলে, অন্তর্নিহিত অটো-রি-কানেক্ট সেটিং করার জন্য সংশ্লিষ্ট পরামিতিঃinterval=parameter value interval হল মিলিসেকেন্ডে পুনরায় চেষ্টা করার সময়কাল,interval=10000হল ১০ সেকেন্ডের পুনরায় চেষ্টা করার সময়কাল এবং ডিফল্ট সেটিং হল ১ সেকেন্ড, অর্থাৎinterval=1000.
ws প্রোটোকলে, অন্তর্নিহিত অটো-রি-কানেক্ট সেটিং করার জন্য সংশ্লিষ্ট পরামিতিঃpayload= parameter value payload হল সাবস্ক্রিপশন বার্তা যা ws পুনরায় সংযোগ করার সময় পাঠানো হবে, উদাহরণস্বরূপঃpayload=okok.
function main(){
    // Dial supports tcp://, udp://, tls://, unix:// protocol, so you can add a parameter to specify the number of seconds to timeout
    var client = Dial("tls://www.baidu.com:443")  
    if (client) {
        // "Write" can be followed by a numeric parameter to specify the timeout, and "write" returns the number of bytes successfully sent
        client.write("GET / HTTP/1.1\nConnection: Closed\n\n")
        while (true) {
            // "Read" can be followed by a numeric parameter to specify the timeout, in millisecond. Return null to indicate error, timeout or closed socket
            var buf = client.read()
            if (!buf) {
                 break
            }
            Log(buf)
        }
        client.close()
    }
}
def main():
    client = Dial("tls://www.baidu.com:443")
    if client:
        client.write("GET / HTTP/1.1\nConnection: Closed\n\n")
        while True:
            buf = client.read()
            if not buf:
                break
            Log(buf)
        client.close()
void main() {
    auto client = Dial("tls://www.baidu.com:443");
    if(client.Valid) {
        client.write("GET / HTTP/1.1\nConnection: Closed\n\n");
        while(true) {
            auto buf = client.read();
            if(buf == "") {
                break;
            }
            Log(buf);
        }
        client.close();
    }
}

ফাংশনreadনিম্নলিখিত পরামিতি সমর্থন করেঃ

  • যখন কোন প্যারামিটার পাস করা হয় না, এটি একটি বার্তা না হওয়া পর্যন্ত ব্লক করে, যেমনঃws.read().
  • প্যারামিটারগুলি পাস করার সময়, মিলিসেকেন্ডের ইউনিটে অপেক্ষা করা বার্তাগুলির জন্য টাইমআউট নির্দিষ্ট করুন; উদাহরণস্বরূপঃws.read(2000)টাইমআউট দুই সেকেন্ড (২০০০ মিলিসেকেন্ড) নির্ধারণ করে।
  • নিম্নলিখিত দুটি পরামিতি শুধুমাত্র জন্য বৈধwebsocket: প্যারামিটার পাস করা-1এর মানে হল অবিলম্বে ফিরে যাওয়া, কোন বার্তা আছে কিনা তা নির্বিশেষে, যেমনঃws.read(-1). প্যারামিটার পাস করা-2মানে কোনো বার্তা আছে কিনা তা নির্বিশেষে তাৎক্ষণিকভাবে ফেরত দেওয়া হয়, কিন্তু শুধুমাত্র সর্বশেষ বার্তাটি ফেরত দেওয়া হয়, এবং বাফারে থাকা বার্তাটি বাদ দেওয়া হবে, যেমনws.read(-2).

ফাংশনread()বাফারের বর্ণনাঃ যদি ws প্রোটোকল দ্বারা প্রেরিত তথ্য কৌশল মধ্যে দীর্ঘ ব্যবধান হয়read()ফাংশন কল, এটি ডেটা জমে থাকতে পারে, এবং এই ডেটাগুলি বাফারে সংরক্ষণ করা হয়। বাফারের ডেটা কাঠামো একটি সারি, যার উপরের সীমা 2000। 2000 অতিক্রম করার পরে, সর্বশেষ ডেটা বাফারে প্রবেশ করে এবং প্রাচীনতম ডেটা সাফ করা হয়।

চিত্রনাট্যReadফাংশন প্যারামিটার কোন প্যারামিটার নেই প্যারামিটারঃ -1 প্যারামিটার: -২ প্যারামিটারঃ ২০০০ (ইউনিটঃ এমএস)
বাফারে ইতিমধ্যেই ডেটা আছে অবিলম্বে পুরোনো তথ্য ফেরত দিন অবিলম্বে পুরোনো তথ্য ফেরত দিন অবিলম্বে সর্বশেষ তথ্য ফেরত দিন অবিলম্বে পুরোনো তথ্য ফেরত দিন
বাফারে কোন তথ্য নেই ডাটা ব্লক করা হলে ডাটা ফেরত দিন অবিলম্বে null ফেরত দিন অবিলম্বে null ফেরত দিন 2000ms জন্য অপেক্ষা করুন, যদি কোন তথ্য নেই null ফেরত, যদি তথ্য আছে তথ্য ফেরত
Ws সংযোগ বিচ্ছিন্ন বা নীচের স্তর পুনরায় সংযুক্ত করা হয় read() ফাংশন null ফেরত দেয়, অর্থাৎঃ , এবং write() ফাংশন 0 ফেরত দেয়। যদি এই পরিস্থিতি সনাক্ত করা হয়, close() ফাংশন সংযোগ বন্ধ করতে ব্যবহার করা যেতে পারে। যদি স্বয়ংক্রিয়ভাবে পুনরায় সংযোগ সেট করা হয়, এটি বন্ধ করার প্রয়োজন হবে না, এবং সিস্টেমের নীচের স্তর স্বয়ংক্রিয়ভাবে পুনরায় সংযোগ স্থাপন করবে
  • সমর্থন wss (WebSocket) প্রোটোকল বাইনারেন্স ওয়েবসকেট মার্কেট ইন্টারফেস অ্যাক্সেস করুনঃ

    function main() {
        LogStatus("connecting...")
        // Access Binance websocket interface
        var client = Dial("wss://stream.binance.com:9443/ws/!ticker@arr")
        if (!client) {
            Log("connection failed, program exited")
            return
        }
        
        while (true) {
            // "read" only returns the obtained data after call "read" 
            var buf = client.read()      
            if (!buf) {
                break
            }
            var table = {
                type: 'table',
                title: 'Quote Chart',
                cols: ['Currency', 'Highest', 'Lowest', 'Buy One', 'Sell One', 'Last Executed Price', 'Volume', 'Update Time'],
                rows: []
            }
            var obj = JSON.parse(buf)
            _.each(obj, function(ticker) {
                table.rows.push([ticker.s, ticker.h, ticker.l, ticker.b, ticker.a, ticker.c, ticker.q, _D(ticker.E)])
            })
            LogStatus('`' + JSON.stringify(table) + '`')
        }
        client.close()
    }
    
    import json
    def main():
        LogStatus("connecting...")
        client = Dial("wss://stream.binance.com:9443/ws/!ticker@arr")
        if not client:
            Log("Connection failed, program exited")
            return 
        
        while True:
            buf = client.read()
            if not buf:
                break
            table = {
                "type" : "table", 
                "title" : "Quote Chart", 
                "cols" : ['Currency', 'Highest', 'Lowest', 'Buy One', 'Sell One', 'Last Executed Price', 'Volume', 'Update Time'], 
                "rows" : [] 
            }
            obj = json.loads(buf)
            for i in range(len(obj)):
                table["rows"].append([obj[i]["s"], obj[i]["h"], obj[i]["l"], obj[i]["b"], obj[i]["a"], obj[i]["c"], obj[i]["q"], _D(int(obj[i]["E"]))])
            LogStatus('`' + json.dumps(table) + '`')
        client.close()
    
    void main() {
        LogStatus("connecting...");
        auto client = Dial("wss://stream.binance.com:9443/ws/!ticker@arr");
        if(!client.Valid) {
            Log("Connection failed, program exited");
            return;
        }
        
        while(true) {
            auto buf = client.read();
            if(buf == "") {
                break;
            }
            json table = R"({
                "type" : "table", 
                "title" : "Quote Chart", 
                "cols" : ['Currency', 'Highest', 'Lowest', 'Buy One', 'Sell One', 'Last Executed Price', 'Volume', 'Update Time'], 
                "rows" : []
            })"_json;
            json obj = json::parse(buf);
            for(auto& ele : obj.items()) {
                table["rows"].push_back({ele.value()["s"], ele.value()["h"], ele.value()["l"], ele.value()["b"], ele.value()["a"], ele.value()["c"], 
                    ele.value()["q"], _D(ele.value()["E"])});
            }
            LogStatus("`" + table.dump() + "`");
        }
        client.close();
    }
    

    অ্যাক্সেস OKX ওয়েবসকেট মার্কেট ইন্টারফেসঃ

    var ws = null 
    function main(){
          var param = {
            "op": "subscribe",
            "args": [{
                "channel": "tickers",
                "instId": "BTC-USDT"
            }]
        }
        // When call the function "Dial", specify "reconnect=true" and set to reconnect; specify "payload" as the message to be sent when reconnect. When websocket closes the connection, it will automatically reconnect and send the message
        ws = Dial("wss://ws.okx.com:8443/ws/v5/public|compress=gzip_raw&mode=recv&reconnect=true&payload="+ JSON.stringify(param))
        if(ws){
            ws.write(JSON.stringify(param))
            var pingCyc = 1000 * 20
            var lastPingTime = new Date().getTime()
            while(true){
                var nowTime = new Date().getTime()
                var ret = ws.read()
                Log("ret:", ret)
                if(nowTime - lastPingTime > pingCyc){
                    var retPing = ws.write("ping")
                    lastPingTime = nowTime
                    Log("send: ping", "#FF0000")
                }
                LogStatus("current time:", _D())
                Sleep(1000)
            }
        }
    }
    
    function onexit() {
        ws.close() 
        Log("exit")
    }
    
    import json
    import time
    
    ws = None
    def main():
        global ws 
        param = {
            "op": "subscribe",
            "args": [{
                "channel": "tickers",
                "instId": "BTC-USDT"
            }]
        }
        ws = Dial("wss://ws.okx.com:8443/ws/v5/public|compress=gzip_raw&mode=recv&reconnect=true&payload=" + json.dumps(param))
        if ws:
            pingCyc = 1000 * 20
            lastPingTime = time.time() * 1000
            while True:
                nowTime = time.time() * 1000
                ret = ws.read()
                Log("ret:", ret)
                if nowTime - lastPingTime > pingCyc:
                    retPing = ws.write("ping")
                    lastPingTime = nowTime
                    Log("send: ping", "#FF0000")
                LogStatus("current time:", _D())
                Sleep(1000)
    
    def onexit():
        ws.close()
        Log("exit")
    
    auto objWS = Dial("wss://ws.okx.com:8443/ws/v5/public|compress=gzip_raw&mode=recv&reconnect=true");  
    
    void main() {
            json param = R"({"op": "subscribe", "args": ["spot/ticker:ETH-USDT"]})"_json;
             "op": "subscribe",
            "args": [{
                "channel": "tickers",
                "instId": "BTC-USDT"
            }]
        })"_json;
        
        objWS.write(param.dump());
        if(objWS.Valid) {
            uint64_t pingCyc = 1000 * 20;
            uint64_t lastPingTime = Unix() * 1000;
            while(true) {
                uint64_t nowTime = Unix() * 1000;
                auto ret = objWS.read();
                Log("ret:", ret);
                if(nowTime - lastPingTime > pingCyc) {
                    auto retPing = objWS.write("ping");
                    lastPingTime = nowTime;
                    Log("send: ping", "#FF0000");
                }
                LogStatus("current time:", _D());
                Sleep(1000);
            }
        }
    }  
    
    void onexit() {
        objWS.close();
        Log("exit");
    }
    

    Huobi ওয়েবসকেট মার্কেট ইন্টারফেস অ্যাক্সেস করুনঃ

    var ws = null   
    
    function main(){
        var param = {"sub": "market.btcusdt.detail", "id": "id1"}
        ws = Dial("wss://api.huobi.pro/ws|compress=gzip&mode=recv&reconnect=true&payload="+ JSON.stringify(param))
        if(ws){
            while(1){
                var ret = ws.read()
                Log("ret:", ret)
                // Respond to heartbeat
                try {
                    var jsonRet = JSON.parse(ret)
                    if(typeof(jsonRet.ping) == "number") {
                        var strPong = JSON.stringify({"pong" : jsonRet.ping})
                        ws.write(strPong)
                        Log("respond ping, send pong:", strPong, "#FF0000")
                    }
                } catch(e) {
                    Log("e.name:", e.name, "e.stack:", e.stack, "e.message:", e.message)
                }
                
                LogStatus("current time:", _D())
                Sleep(1000)
            }
        }
    }  
    
    function onexit() {
        ws.close() 
        Log("execute function ws.close()")
    }
    
    import json
    ws = None  
    
    def main():
        global ws
        param = {"sub" : "market.btcusdt.detail", "id" : "id1"}
        ws = Dial("wss://api.huobi.pro/ws|compress=gzip&mode=recv&reconnect=true&payload=" + json.dumps(param))
        if ws:
            while True:
                ret = ws.read()
                Log("ret:", ret)              
                # Respond to heartbeat 
                try:
                    jsonRet = json.loads(ret)
                    if "ping" in jsonRet and type(jsonRet["ping"]) == int:
                        strPong = json.dumps({"pong" : jsonRet["ping"]})
                        ws.write(strPong)
                        Log("respond ping, send pong:", strPong, "#FF0000")
                except Exception as e:
                    Log("e:", e)
                    
                LogStatus("current time: ", _D())
                Sleep(1000)
        
    def onexit():
        ws.close()
        Log("execute function ws.close()")  
    
    using namespace std;
    void main() {
        json param = R"({"sub" : "market.btcusdt.detail", "id" : "id1"})"_json;
        auto ws = Dial("wss://api.huobi.pro/ws|compress=gzip&mode=recv&reconnect=true&payload=" + param.dump());
        if(ws.Valid) {
            while(true) {
                auto ret = ws.read();
                Log("ret:", ret);              
                // Respond to heartbeat
                try 
                {
                    auto jsonRet = json::parse(ret);
                    if(jsonRet["ping"].is_number()) {
                        json pong = R"({"pong" : 0})"_json;
                        pong["pong"] = jsonRet["ping"];
                        auto strPong = pong.dump();
                        ws.write(strPong);
                        Log("respond ping, send pong:", strPong, "#FF0000");
                    }
                } catch(exception &e) 
                {
                    Log("e:", e.what());
                }
                
                LogStatus("current time:", _D());
                Sleep(1000);
            }
        }
    }  
    
    void onexit() {
        // ws.close();
        Log("execute function ws.close()");
    }
    

    ওয়েবসকেট ইন্টারফেসের যাচাইকরণ ইন্টারফেস যা OKX অ্যাক্সেস করেঃ

      function getLogin(pAccessKey, pSecretKey, pPassphrase) {
        // Signature function for login
        var ts = (new Date().getTime() / 1000).toString()
        var login = {
            "op": "login",
            "args":[{
                "apiKey"    : pAccessKey,
                "passphrase" : pPassphrase,
                "timestamp" : ts,
                "sign" : exchange.HMAC("sha256", "base64", ts + "GET" + "/users/self/verify", pSecretKey)
            }]
        }    
        return login
    }    
    
    var client_private = null 
    function main() {
        // Because the read function adopts the timeout setting, the timeout error is filtered, otherwise there will be redundant error output
        SetErrorFilter("timeout")
        
        // Position channel subscription information
        var posSubscribe = {
            "op": "subscribe",
            "args": [{
                "channel": "positions",
                "instType": "ANY"
            }]
        }    
    
        var accessKey = "xxx"
        var secretKey = "xxx"
        var passphrase = "xxx"
    
        client_private = Dial("wss://ws.okx.com:8443/ws/v5/private")
        client_private.write(JSON.stringify(getLogin(accessKey, secretKey, passphrase)))
        Sleep(3000)  // When logging in, we cannot subscribe to private channels immediately, we need to wait for server response
        client_private.write(JSON.stringify(posSubscribe))
        if (client_private) {
            var lastPingTS = new Date().getTime()
            while (true) {
                var buf = client_private.read(-1)
                if (buf) {
                    Log(buf)
                }
                
                // Detect disconnection, reconnect
                if (buf == "" && client_private.write(JSON.stringify(posSubscribe)) == 0) {
                    Log("Disconnection detected, connection closed, reconnect")
                    client_private.close()
                    client_private = Dial("wss://ws.okx.com:8443/ws/v5/private")
                    client_private.write(JSON.stringify(getLogin(accessKey, secretKey, passphrase)))
                    Sleep(3000)
                    client_private.write(JSON.stringify(posSubscribe))
                }
                
                // Send heartbeat packets
                var nowPingTS = new Date().getTime()
                if (nowPingTS - lastPingTS > 10 * 1000) {
                    client_private.write("ping")
                    lastPingTS = nowPingTS
                }            
            }        
        }
    }    
    
    function onexit() {    
        var ret = client_private.close()
        Log("Close the connection!", ret)
    }
    
    import json
    import time
        
    def getLogin(pAccessKey, pSecretKey, pPassphrase):
        ts = str(time.time())
        login = {
            "op": "login",
            "args":[{
                "apiKey"    : pAccessKey,
                "passphrase" : pPassphrase,
                "timestamp" : ts,
                "sign" : exchange.HMAC("sha256", "base64", ts + "GET" + "/users/self/verify", pSecretKey)
            }]
        }
        return login     
    
    client_private = None 
    def main():
        global client_private
        SetErrorFilter("timeout")
        
        posSubscribe = {
            "op": "subscribe",
            "args": [{
                "channel": "positions",
                "instType": "ANY"
            }]
        }      
    
        accessKey = "xxx"
        secretKey = "xxx"
        passphrase = "xxx"
        
        client_private = Dial("wss://ws.okx.com:8443/ws/v5/private")
        client_private.write(json.dumps(getLogin(accessKey, secretKey, passphrase)))
        Sleep(3000)
        client_private.write(json.dumps(posSubscribe))
        if client_private:
            lastPingTS = time.time() * 1000
            while True:
                buf = client_private.read(-1)
                if buf:
                    Log(buf)
                
                if buf == "" and client_private.write(json.dumps(posSubscribe)) == 0:
                    Log("Disconnection detected, connection closed, reconnect")
                    ret = client_private.close()
                    client_private = Dial("wss://ws.okx.com:8443/ws/v5/private")
                    client_private.write(json.dumps(getLogin(accessKey, secretKey, passphrase)))
                    Sleep(3000)
                    client_private.write(json.dumps(posSubscribe))
                
                nowPingTS = time.time() * 1000
                if nowPingTS - lastPingTS > 10 * 1000:
                    client_private.write("ping")
                    lastPingTS = nowPingTS    
    
    def onexit():
        ret = client_private.close()
        Log("Close the connection!", ret)
    

অটো ক্লায়েন্ট_প্রাইভেট = ডায়াল ((wss://ws.okx.com:8443/ws/v5/private);

json getLogin ((স্ট্রিং pAccessKey, string pSecretKey, string pPassphrase) { অটো ts = std::to_string ((Unix()); json লগইন = R"({ op: লগইন, আর্গস: [{ apiKey: , পাসফ্রেজ: , সময়সীমা: , চিহ্ন : }] }) "_json; login[args][0][apiKey] = pAccessKey; login[args][0][passphrase] = pPassphrase; login[args][0][timestamp] = ts; login[args][0][sign] = exchange.HMAC(sha256, base64, ts + GET + /users/self/verify, pSecretKey); রিটার্ন লগইন; }

খালি প্রধান ((() { SetErrorFilter ((timeout); json postSubscribe = R"({ op: সাবস্ক্রাইব করুন, আর্গস: [{ চ্যানেল: পজিশন, instType: any }] }) "_json;

auto accessKey = "xxx";
auto secretKey = "xxx";
auto passphrase = "xxx";

client_private.write(getLogin(accessKey, secretKey, passphrase).dump());
Sleep(3000);
client_private.write(posSubscribe.dump());  

if (client_private.Valid) {
    uint64_t lastPingTS = Unix() * 1000;    

    while (true) {
        auto buf = client_private.read(-1);
        if (buf != "") {
            Log(buf);
        }
        if (buf == "") {
            if (client_private.write(posSubscribe.dump()) == 0) {
                Log("Disconnection detected, connection closed, reconnect");
                client_private.close();
                client_private = Dial("wss://ws.okx.com:8443/ws/v5/private");
                client_private.write(getLogin(accessKey, secretKey, passphrase).dump());
                Sleep(3000);
                client_private.write(posSubscribe.dump());
            }
        }
        
        uint64_t nowPingTS = Unix() * 1000;
        if (nowPingTS - lastPingTS > 10 * 1000) {
            client_private.write("ping");
            lastPingTS = nowPingTS;
        }
    }
}

}

অবৈধ এক্সিট client_private.close ((); লগ ((exit); }


#### HttpQuery(...)

```HttpQuery(Url, PostData, Cookies, Headers, IsReturnHeader)``` is an access of web URL. Parameter value: all are of string types.

Note:
* The ```HttpQuery(...)``` function only supports ```JavaScript``` language.
* For the ```Python``` language, you can use ```urllib``` to send http requests directly.

```HttpQuery(...)``` is mainly used to access the exchange interfaces that do not require signatures, such as public interfaces including market information.
An example of an API that does not require a signature to access OKX: the return value is a ```JSON``` string, which can be parsed by using the function ```JSON.parse()``` in JavaScript language strategies.

```js
function main(){
  // An example of GET access without parameters
  var info = JSON.parse(HttpQuery("https://www.okx.com/api/v5/public/time"))
  Log(info)
  // An example of GET access with parameters
  var ticker = JSON.parse(HttpQuery("https://www.okx.com/api/v5/market/books?instId=BTC-USDT"))
  Log(ticker)
}
import json
import urllib.request
def main():
    # HttpQuery does not support Python, you can use urllib/urllib2 instead
    info = json.loads(urllib.request.urlopen("https://www.okx.com/api/v5/public/time").read().decode('utf-8'))
    Log(info)
    ticker = json.loads(urllib.request.urlopen("https://www.okx.com/api/v5/market/books?instId=BTC-USDT").read().decode('utf-8'))
    Log(ticker)
void main() {
    auto info = json::parse(HttpQuery("https://www.okx.com/api/v5/public/time"));
    Log(info);
    auto ticker = json::parse(HttpQuery("https://www.okx.com/api/v5/market/books?instId=BTC-USDT"));
    Log(ticker);
}

একটি URL এর রিটার্ন কন্টেন্ট পেতে, যদি দ্বিতীয় প্যারামিটারPostDataস্ট্রিং আকারে হয়a=1&b=2&c=abc, দ্বারা জমাPOST, অন্যদের দ্বারাPUT; এর পরামিতিPostDataহয়{method:'PUT', data:'a=1&b=2&c=abc'}.

দ্যPostDataপ্যারামিটার এছাড়াও একটি হতে পারেJSON string.

প্যারামিটারের বিন্যাসCookiesহচ্ছেঃa=10; b=20; প্রতিটি প্যারামিটার একটি সেমিকোলন দ্বারা পৃথক;. প্যারামিটারের বিন্যাসHeadersহচ্ছেঃUser-Agent: Mobile\nContent-Type: text/html; প্রতিটি প্যারামিটার একটি নতুন লাইন অক্ষর দ্বারা পৃথক\n.

দ্বিতীয় প্যারামিটার,PostData, কাস্টমাইজ করা যায়, উদাহরণস্বরূপঃHttpQuery("http://www.abc.com", {method:'PUT', data:'a=1&b=2&c=abc'}); দ্রষ্টব্যঃ যদি আপনি সময়সীমা সেট করতে চানHttpQueryফাংশন, আপনি যোগ করতে পারেনtimeoutঅ্যাট্রিবিউট{method:'put',data:'a=1&B=2&C=ABC'}(ডিফল্ট 60 সেকেন্ড) ।

১ সেকেন্ড টাইমআউট সেট করুনঃHttpQuery("http://www.abc.com", {method:'PUT', data:'a=1&b=2&c=abc', timeout:1000})

স্ট্রিং পাস করার জন্য তৃতীয় পরামিতি প্রয়োজনCookie, কিন্তুPOSTদ্বিতীয় প্যারামিটারটি শূন্যে সেট করার প্রয়োজন নেই। সিমুলেশন পরীক্ষার সময়, কারণ ইউআরএল সিমুলেট করা যায় না, ফাংশন একটি নির্দিষ্ট স্ট্রিং ফেরত দেয়Dummy Data. আপনি এই ইন্টারফেসটি পাঠ্য বার্তা পাঠাতে বা অন্যান্য API ইন্টারফেসগুলির সাথে ইন্টারঅ্যাক্ট করতে ব্যবহার করতে পারেন।

GETপদ্ধতির কলের উদাহরণঃHttpQuery("http://www.baidu.com"). POSTপদ্ধতির কলের উদাহরণঃHttpQuery("http://www.163.com", "a=1&b=2&c=abc").

ফেরত দেওয়ার উদাহরণHeader:

HttpQuery("http://www.baidu.com", null, "a=10; b=20", "User-Agent: Mobile\nContent-Type: text/html", true)  // will return {Header: HTTP Header, Body: HTML}
  • ফাংশনHttpQueryপ্রক্সি সেটিংস ব্যবহার করেঃ

    function main() {
        // This time, set proxy and send http request; without username and password, this http request will be sent through the proxy
        HttpQuery("socks5://127.0.0.1:8889/http://www.baidu.com/")
    
        // Set the proxy and send http request this time, enter the user name and password, only the current call of HttpQuery takes effect, then call HttpQuery ("http://www.baidu.com") again so that the proxy will not be used
        HttpQuery("socks5://username:password@127.0.0.1:8889/http://www.baidu.com/")
    }
    
    # If HttpQuery does not support Python, you can use Python urllib2 library
    
    void main() {
        HttpQuery("socks5://127.0.0.1:8889/http://www.baidu.com/");
        HttpQuery("socks5://username:password@127.0.0.1:8889/http://www.baidu.com/");
    }
    
  • ফাংশনHttpQueryএর অ্যাসিনক্রোন সংস্করণHttpQuery_Go: ব্যবহার পদ্ধতি ফাংশন অনুরূপexchange.Go, যেমন সমন্বিত বাজার তথ্য পাওয়ার জন্য একযোগে এক্সচেঞ্জের পাবলিক ইন্টারফেস অ্যাক্সেস করা।

    function main() {
        // Set up the first asyncthread
        var r1 = HttpQuery_Go("https://www.okx.com/api/v5/market/tickers?instType=SPOT")
        // Set up the second asyncthread
        var r2 = HttpQuery_Go("https://api.huobi.pro/market/tickers")
        
        // Get the return value of the first asyncthread
        var tickers1 = r1.wait()
        // Get the return value of the second asyncthread
        var tickers2 = r2.wait()
        
        // Print result
        Log("tickers1:", tickers1)
        Log("tickers2:", tickers2)
    }
    
    # Not supported
    
    // Not supported
    
  • ফাংশন ব্যবহারHttpQuery(...)ব্যাকটেস্ট সিস্টেমেঃ তথ্য ব্যবহার করে পাওয়া যাবেHttpQuery(...)অনুরোধ পাঠাতে (শুধুমাত্র সমর্থন)GETব্যাকটেস্ট সিস্টেমে 20 বার একটি সীমাবদ্ধতা আরোপ করা হয় এবংHttpQuery(...)অ্যাক্সেস ডাটা ক্যাশে করবে, যখন ফাংশনHttpQuery(...)একই URL-এ দ্বিতীয় অ্যাক্সেসে ক্যাশেড ডেটা ফেরত দেয় (আরও প্রকৃত ওয়েব অনুরোধ নেই) ।

    আমরা একটি সার্ভার বা ডিভাইসে একটি পরিষেবা প্রোগ্রাম চালাতে পারেন যে অনুরোধ দ্বারা পাঠানো সাড়াHttpQuery(...)কৌশল প্রোগ্রামে, এবং পরীক্ষার জন্য Go ভাষায় সার্ভিস প্রোগ্রাম নিম্নরূপ দেখানো হয়ঃ

    package main
    import (
        "fmt"
        "net/http"
        "encoding/json"
    )
    
    func Handle (w http.ResponseWriter, r *http.Request) {
        defer func() {
            fmt.Println("req:", *r)
            ret := map[string]interface{}{
                "schema" : []string{"time","open","high","low","close","vol"},
                "data" : []interface{}{
                    []int64{1564315200000,9531300,9531300,9497060,9497060,787},
                    []int64{1564316100000,9495160,9495160,9474260,9489460,338},
                },
            }
            b, _ := json.Marshal(ret)
            w.Write(b)
        }()
    }
    
    func main () {
        fmt.Println("listen http://localhost:9090")
        http.HandleFunc("/data", Handle)
        http.ListenAndServe(":9090", nil)
    }
    

    ফাংশনটি ব্যবহার করুনHttpQuery(...)কৌশল ব্যাকটেস্টিংয়ের সময় অনুরোধ পাঠাতেঃ

    function main() {
        // You can write the IP address of the device where the service program is run
        Log(HttpQuery("http://xxx.xx.x.xxx:9090/data?msg=hello"));
        Log(exchange.GetAccount());
    }
    
    # If HttpQuery does not support Python, you can use Python urllib2 library
    
    void main() {
        //  You can write the IP address of the device where the service program is run
        Log(HttpQuery("http://xxx.xx.x.xxx:9090/data?msg=hello"));
        Log(exchange.GetAccount());
    }
    

    img

    এটি অনুরোধে প্রতিক্রিয়া তথ্যের ট্রান্সকোডিং সমর্থন করে, এবং এটি সাধারণ কোডিং সমর্থন করে। নির্দিষ্টকরণPostDataপ্যারামিটারঃ{method: "GET", charset: "GB18030"}রেসপন্স ডেটা ট্রান্সকোডিং (GB18030) বুঝতে পারে।

এনকোড ((...)

Encode(algo, inputFormat, outputFormat, data, keyFormat, key string), ফাংশনটি পাস করা পরামিতি অনুযায়ী ডেটা কোড করে এবং একটি স্ট্রিং মান প্রদান করে।

প্যারামিটারalgoকোডিং গণনার জন্য ব্যবহৃত অ্যালগরিদম, যা সেট করা যেতে পারেঃ raw (কোন অ্যালগরিদম নেই), sign, signTx, md4, md5, sha256, sha512, sha1, keccak256, sha3.224, sha3.256, sha3.384, sha3.512, sha3.keccak256, sha3.keccak512, sha512.384, sha512.256, sha512.224, emd160, blake2rip2b.256, blake2b.512, blake2s.1288, blake2s.256। পরামিতি।dataএই তথ্যগুলিকেinputFormat/outputFormat/keyFormatপ্যারামিটার কোডিং পদ্ধতি সমর্থন যেমনraw, hex, base64এবংstring. যদিkeyFormatপ্যারামিটার খালি নয়,keyপ্যারামিটার এনক্রিপশন জন্য ব্যবহৃত হয় (HMAC), অন্যথায় ডিফল্টkeyযখন ` ` `alg