นี่คือส่วนที่สำคัญที่สุดของการสาธิตสคริปต์ใหม่ multiexchangewatch.mq5 (มีให้พร้อมกับรุ่นเบต้าของห้องสมุด)
NB: หากสคริปต์กำลังทำงานเป็นครั้งแรกมันจะขอให้แกะแอปพลิเคชันเซิร์ฟเวอร์ CCXT (ด้วยตนเอง) (แยกเป็น CCXTAppSrvBundle.jsc จากทรัพยากรในตัว) และเรียกใช้ node.js ด้วย
ก่อนอื่นให้รวมส่วนหัว
#embody "ccxtjsmtlib.mqh" #embody "ccxtutil.mqh" #embody <MQL5Book/Feedback.mqh>
ในอินพุตควรตั้งค่าเซิร์ฟเวอร์โหนด
enter group "Connection settings" enter string NodeServer = "http://127.0.0.1:8124"; enter string NodeAuth = "";
จากนั้นระบุจำนวนการแลกเปลี่ยนที่คุณต้องการตรวจสอบทัศนคติและนาฬิกาประเภทหนึ่ง โดยค่าเริ่มต้นสคริปต์จะดูหนังสือสั่งซื้อสำหรับ BCH/USDT
ในการเติมอินพุตเหล่านี้อย่างถูกต้องด้วยค่าที่ต้องการคุณอาจต้องส่งออกรายการการแลกเปลี่ยนที่รองรับและตลาดของพวกเขาล่วงหน้า สามารถดูได้ในสคริปต์ตัวอย่างอื่น ccxtappsrvshowcase.mq5ให้มาพร้อมกับ lib
enter string Exchanges = "ascendex,bitmart,binance"; enter string Ticker = "BCH/USDT"; enter string Watch = "watchOrderBook"; enter uint WatchingDuration = 10;
แล้ว เริ่มต้น ตัวจัดการเหตุการณ์ทำงานได้ ความคิดเห็นแบบอินไลน์อธิบายกระบวนการ ฟังก์ชั่นการนำเข้าคลาสและวิธีการจากไลบรารีจะถูกเน้นเป็นสีเหลือง
string Trade(); void OnStart() { PrintFormat("CCXT AppSrvLibrary model: %.2f", AppSrvLibraryVersion()); const static string standing() = {"Cannot deploy", "App server ZIP is deployed, however not extracted", "App server information are deployed"}; const int d = DeployCcxtAppServer(); Print(standing(d + 1)); if(d <= 0) { return; } SetNodeServer(NodeServer, NodeAuth); CcxtLink *hyperlink = GetLink(); AutoPtr<CcxtJsExchangeProIntf> ccxt(); const int n = StringSplit(Exchanges, ',', Trade); ArrayResize(ccxt, n); for(int i = 0; i < n; i++) { ccxt(i) = CreateExchangePro(Trade(i)); if(hyperlink.getLastHttpCode() != 200 || !ccxt(i)() || ccxt(i)()().t >= JS_NULL) { Print("Building failed for change: ", Trade(i)); return; } const bool isPro = !!*ccxt(i)()("professional"); if(!isPro) { PrintFormat("WARNING! %s is not PRO, there isn't any websocket help", Trade(i)); } if(!ccxt(i)()("has")(Watch).get<bool>()) { PrintFormat("WARNING! %s doesn't help '%s' subscriptions", Trade(i), Watch); } } int lively = 0; for(int i = 0; i < n; i++) { if(ccxt(i)().improve()) { if(!ccxt(i)().watchAnything(StringFormat("%s("%s")", Watch, Ticker))) { PrintFormat("Cannot begin %s for %s", Watch, Trade(i)); ccxt(i)().shut(); ccxt(i) = NULL; } else { lively++; } } else { if(ccxt(i)().isConnected()) { Print("Cannot improve to websockets"); string headers()(2); if(ccxt(i)().ws().getHeaders(headers)) { } ccxt(i)().ws().shut(); ccxt(i)().shut(); ccxt(i) = NULL; } } } if(!lively) return; PrintFormat("* Monitoring %d subscriptions", lively); const uint begin = GetTickCount(); whereas(!IsStopped() && (!WatchingDuration || GetTickCount() - begin < WatchingDuration * 1000)) { for(int i = 0; i < n; i++) { if(ccxt(i)() && ccxt(i)().isConnected()) { AutoPtr<JsValue> j = ccxt(i)().readMessage(false); if(j()) { ChronoComment(j().stringify(0, 0)); } } } } Print("* Unsubscribing..."); for(int i = 0; i < n; i++) { if(ccxt(i)() && ccxt(i)().isConnected()) { ccxt(i)().un().watchAnything(StringFormat("%s("%s")", Watch, Ticker)); } } GracefullClose(ccxt); // not introduced right here within the weblog GracefullClose(ccxt, 5, true); Remark(""); }
เมื่อสคริปต์กำลังทำงานรายการหนังสือคำสั่งซื้อขาเข้า (JSON-Messages) จะถูกส่งออกและอัปเดตอย่างแข็งขันในแผนภูมิ
ด้านบนของ dataflow นั้นง่ายต่อการใช้กลยุทธ์การเก็งกำไรที่หลากหลายและคำนวณสถิติรวม
(tagstotranslate) Trade (T) Crypto (T) Demo (T) Library (T) Script (T) CCXT (T) Node.js