ٹریڈنگ آرڈر کا نوٹیفیکیشن قیمت: 1000، // آرڈر دینے کی قیمت؛ نوٹ کریں کہ مارکیٹ آرڈرز کی یہ صفت 0 یا -1 ہو سکتی ہے رقم: 10، // آرڈر کی رقم کی جگہ؛ نوٹ مارکیٹ کے احکامات کی یہ وصف رقم رقم، نہیں سکوں نمبر ہو سکتا ہے DealAmount : 10، // عملدرآمد حجم؛ پلیٹ فارم انٹرفیس اس قسم کے اعداد و شمار فراہم نہیں کرتا تو، شاید 0 میں بھرنے کے لئے استعمال کریں AVGPrice: 1000، // اوسط عملدرآمد کی قیمت؛ نوٹ کچھ پلیٹ فارم اس ڈیٹا کو فراہم نہیں کرتے.(اس صورت میں جب اعداد و شمار فراہم یا حساب نہیں کیا جا سکتا ہے، صفات کی ترتیب 0 ہے) حالت: 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ہے) ، جو ایک بہت سست حکمت عملی backtest کی قیادت کرے گا.

ورچوئل ہے

IsVirtual()، اس بات کا تعین کرنے کے لئے کہ آیا یہ ایک تخروپن بیک ٹسٹ ہے۔ واپسی کی قیمت: بول ٹائپ۔ سیمولیٹ بیک ٹسٹ کی حیثیت لوٹاتا ہےtrue، اور اصلی روبوٹ واپس آتا ہےfalse.

میل ((...)

Mail(smtpServer, smtpUsername, smtpPassword, mailTo, title, body)ایک میل بھیجنے کا فنکشن ہے۔ پیرامیٹر ویلیو: تمام سٹرنگ ٹائپ کے ہیں۔ ریٹرن ویلیو: بول ٹائپ۔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مثال کے طور پر، SMTP ایس ایس ایل QQmail کے طریقہ کار: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()بوٹ عمل ID لوٹاتا ہے۔ واپسی کی قدر: تار کی قسم۔

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()

فنکشن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کمپریسڈ ڈیٹا وصول کرنے اور اسے مقامی طور پر ڈیکمپریس کرنا ہے.
اس سے متعلق پیرامیٹرز جو جوتے کو ترتیب دینے کے لئے ہیں5 پراکسی:proxy=parameter value پروکسی ایس ایس 5 پروکسی سیٹنگ ہے۔ پیرامیٹر ویلیو فارمیٹ:socks5://name:pwd@192.168.0.1:1080name ss5 سرور صارف نام ہے pwd ss5 سرور لاگ ان پاس ورڈ ہے 1080 ss5 سرور کی پورٹ ہے
ws پروٹوکول میں، بنیادی آٹو دوبارہ منسلک کرنے کے لئے متعلقہ پیرامیٹرز کی ترتیب:reconnect=parameter value reconnect کا مطلب ہے کہ reconnect کو سیٹ کرنا ہے یا نہیں۔reconnect=trueدوبارہ رابطہ قائم کرنے کے لئے ہے؛ ڈیفالٹ کی ترتیب دوبارہ رابطہ قائم کرنے کے لئے نہیں ہے.
ws پروٹوکول میں، بنیادی آٹو دوبارہ منسلک کرنے کے لئے متعلقہ پیرامیٹرز کی ترتیب:interval=parameter value وقفہ milliseconds میں دوبارہ کوشش کرنے کا وقفہ ہے،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 (یونٹ: ایم ایس)
بفر میں پہلے ہی ڈیٹا موجود ہے فوری طور پر سب سے پرانے اعداد و شمار واپس فوری طور پر سب سے پرانے اعداد و شمار واپس فوری طور پر تازہ ترین اعداد و شمار واپس فوری طور پر سب سے پرانے اعداد و شمار واپس
بفر میں کوئی ڈیٹا نہیں جب ڈیٹا بلاک ہو تو ڈیٹا واپس کریں فوری طور پر null لوٹائیں فوری طور پر null لوٹائیں 2000ms کے لئے انتظار کریں، کوئی ڈیٹا نہیں ہے تو null واپس، ڈیٹا ہے تو ڈیٹا واپس
Ws کنکشن منقطع ہے یا نیچے کی پرت دوبارہ منسلک ہے read() فنکشن null لوٹاتا ہے ، یعنی: ، اور فنکشن 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()");
    }
    

    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،سلسلہ pSecretKey،سلسلہ pPassphrase آٹو ts = std::to_string ((یونیکس)) ؛ 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 posSubscribe = 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;
        }
    }
}

}

void onexit ((() { client_private.close (() ؛ لاگ (( باہر نکلیں) ؛ }


#### 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آپ اس انٹرفیس کو ٹیکسٹ پیغامات بھیجنے یا دیگر 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(...)اسی یو آر ایل پر دوسری رسائی پر کیچڈ ڈیٹا واپس کرتا ہے (کوئی اور اصل ویب درخواستیں نہیں) ۔

    ہم ایک سرور یا ایک آلہ پر ایک سروس پروگرام چلا سکتے ہیں جو کی طرف سے بھیجے گئے درخواستوں کا جواب دیتا ہے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.128 ، blake2s.256۔ پیرامیٹر۔dataہے کہ اعداد و شمار پر عملدرآمد کیا جائے.inputFormat/outputFormat/keyFormatپیرامیٹرز کوڈنگ کے طریقوں کی حمایت جیسےraw, hex, base64اورstring. اگرkeyFormatپیرامیٹر خالی نہیں ہے،keyپیرامیٹر خفیہ کاری کے لئے استعمال کیا جاتا ہے (HMAC) ، دوسری صورت میں ڈیفالٹkeyاستعمال کیا جاتا ہے.