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

वैश्विक कार्य

संस्करण

Version()सिस्टम का वर्तमान संस्करण संख्या लौटाता है; लौटाता है मानः स्ट्रिंग प्रकार.

नींद (मिलिसकंड)

Sleep(Millisecond), नींद समारोह, समय की अवधि के लिए कार्यक्रम को रोकता है। पैरामीटर मानःMillisecondएक संख्या प्रकार है। पैरामीटर इकाई मिलीसेकंड है, उदाहरण के लिएःSleep(1000)मतलब एक सेकंड के लिए सोने के लिए। 1 मिलीसेकंड से कम नींद के समय के साथ समर्थन संचालन, जैसे सेटिंग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मेलबॉक्स का एसटीएमपी पासवर्ड है;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.

SetErrorFilter(...)

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()इंटरैक्टिव कमांड (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()का मान देता हैMetaजब रणनीति टोकन उत्पन्न किया जाता है, फ़ंक्शन का रिटर्न मान स्ट्रिंग प्रकार का होता है। अनुप्रयोगः उदाहरण के लिए, रणनीति को विभिन्न किरायेदारों के लिए परिसंपत्तियों की सीमाएं बनाने की आवश्यकता है। नोटः जब रणनीति टोकन उत्पन्न किया जाता है, की लंबाईMeta190 स्ट्रिंग से अधिक नहीं हो सकता है; फ़ंक्शन, केवल वास्तविक ट्रेडिंग के लिए लागू होता है और नवीनतम डॉकर की आवश्यकता होती है। यदि रणनीति टोकन उत्पन्न होने पर स्रोत डेटा सेट नहीं किया जाता है,GetMeta()शून्य लौटाता है.

आवेदनों द्वारा प्रदर्शित संबंधित जानकारी

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=parameter value प्रॉक्सी एसएस5 प्रॉक्सी सेटिंग है; पैरामीटर मान प्रारूपःsocks5://name:pwd@192.168.0.1:1080; name ss5 सर्वर का उपयोगकर्ता नाम है; pwd ss5 सर्वर लॉगिन पासवर्ड है; 1080 ss5 सर्वर का पोर्ट है
ws प्रोटोकॉल में, अंतर्निहित ऑटो-रीकनेक्ट सेट करने के लिए संबंधित पैरामीटरःreconnect=parameter value reconnect का अर्थ है कि reconnect सेट करना है या नहीं;reconnect=trueपुनः कनेक्शन का आह्वान करना है; डिफ़ॉल्ट सेटिंग पुनः कनेक्ट नहीं करना है.
ws प्रोटोकॉल में, अंतर्निहित ऑटो-रीकनेक्ट सेट करने के लिए संबंधित पैरामीटरःinterval=parameter value अंतराल, मिलीसेकंड में पुनःप्रयास का अंतराल है।interval=1000010 सेकंड का पुनः प्रयास अंतराल है, और डिफ़ॉल्ट सेटिंग 1 सेकंड है, अर्थात,interval=1000.
ws प्रोटोकॉल में, अंतर्निहित ऑटो-रीकनेक्ट सेट करने के लिए संबंधित पैरामीटरःpayload= parameter value पेलोड वह सब्सक्रिप्शन संदेश है जो जब 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)दो सेकंड (2000 मिलीसेकंड) का टाइमआउट निर्दिष्ट करता है।
  • निम्नलिखित दो मापदंड केवल के लिए मान्य हैंwebsocket: पैरामीटर पास करना-1इसका अर्थ है कि तुरंत वापस लौटना चाहे कोई संदेश हो या नहीं, जैसे किws.read(-1). पैरामीटर पास करना-2इसका मतलब है कि तुरंत कोई संदेश है या नहीं, पर वापस करने के लिए है, लेकिन केवल नवीनतम संदेश लौटाया जाता है, और बफर में संदेश त्याग दिया जाएगा, जैसे किws.read(-2).

कार्यread()बफर का वर्णनः यदि ws प्रोटोकॉल द्वारा पुश किए गए डेटा रणनीति के बीच लंबे अंतराल के हैंread()फ़ंक्शन कॉल, यह डेटा संचय का कारण बन सकता है, और ये डेटा बफर में संग्रहीत होते हैं। बफर डेटा संरचना एक कतार है, जिसकी ऊपरी सीमा 2000 है। 2000 से अधिक होने के बाद, नवीनतम डेटा बफर में प्रवेश करता है, और सबसे पुराना डेटा साफ़ किया जाता है।

परिदृश्यReadफलन पैरामीटर कोई पैरामीटर नहीं पैरामीटरः -1 पैरामीटरः -2 पैरामीटरः 2000 (इकाईः एमएस)
बफर में पहले से ही डेटा है सबसे पुराना डेटा तुरंत लौटाएं सबसे पुराना डेटा तुरंत लौटाएं नवीनतम डेटा तुरंत लौटाएं सबसे पुराना डेटा तुरंत लौटाएं
बफर में कोई डेटा नहीं जब डेटा अवरुद्ध हो तो डेटा लौटाएँ तुरंत शून्य लौटाएँ तुरंत शून्य लौटाएँ 2000ms के लिए प्रतीक्षा करें, कोई डेटा नहीं है तो शून्य लौटाएं, डेटा है तो डेटा लौटाएं
Ws कनेक्शन डिस्कनेक्ट है या नीचे की परत फिर से कनेक्ट है read() फ़ंक्शन शून्य लौटाता है, अर्थातः , और फ़ंक्शन write() 0 लौटाता है. यदि यह स्थिति पता चली है, तो फ़ंक्शन close() का उपयोग कनेक्शन को बंद करने के लिए किया जा सकता है. यदि स्वचालित रूप से पुनः कनेक्ट सेट किया जाता है, तो इसे बंद करने की आवश्यकता नहीं होगी, और सिस्टम की निचली परत स्वचालित रूप से फिर से कनेक्ट होगी.
  • समर्थन wss (वेबसॉकेट) प्रोटोकॉल बाइनेंस वेबसॉकेट मार्केट इंटरफेस का उपयोग करेंः

    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()");
    }
    

    ओकेएक्स तक पहुँचने वाले वेबसॉकेट इंटरफ़ेस का सत्यापन इंटरफ़ेसः

      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, स्ट्रिंग pSecretKey, स्ट्रिंग pPassphrase) { ऑटो ts = std::to_string ((Unix()); json लॉगिन = R"({ op: लॉगिन, args: [{ 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 ((टाइमआउट); json postSubscribe = R"({ op: साइनअप, args: [{ चैनल: स्थिति, 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;
        }
    }
}

}

अमान्य onexit (() { 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);
}

एक यूआरएल की वापसी सामग्री प्राप्त करने के लिए, अगर दूसरे पैरामीटर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 सेकंड है) ।

1 सेकंड टाइमआउट सेट करेंःHttpQuery("http://www.abc.com", {method:'PUT', data:'a=1&b=2&c=abc', timeout:1000})

तीसरा पैरामीटर स्ट्रिंग पास करने के लिए आवश्यक हैCookie, लेकिनPOSTदूसरे पैरामीटर को शून्य पर सेट करने के लिए आवश्यक नहीं है। सिमुलेशन परीक्षण के दौरान, क्योंकि यूआरएल का अनुकरण नहीं किया जा सकता है, फ़ंक्शन एक निश्चित स्ट्रिंग देता हैDummy Data. आप इस इंटरफ़ेस का उपयोग पाठ संदेश भेजने या अन्य एपीआई इंटरफेस के साथ बातचीत करने के लिए कर सकते हैं.

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(...)रणनीति कार्यक्रम में, और परीक्षण के लिए गो भाषा में सेवा कार्यक्रम निम्नानुसार दिखाया गया हैः

    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जब ` `