Sunday, July 27, 2025
Homeการซื้อขายCCXT Software Server Showcase: เข้าถึงการแลกเปลี่ยน crypto ผ่าน Library MQL5 จาก Metatrader 5...

CCXT Software Server Showcase: เข้าถึงการแลกเปลี่ยน crypto ผ่าน Library MQL5 จาก Metatrader 5 – อื่น ๆ – 3 กรกฎาคม 2025


CCXT เป็นไลบรารี JavaScript สำหรับการทำงานกับการแลกเปลี่ยน crypto ท็อป 100 ทั้งหมด สำหรับรายละเอียดเพิ่มเติมเกี่ยวกับ CCXT กรุณาเยี่ยมชม เอกสาร CCXT ทั่วไป และขั้นสูงมากขึ้น CCXT Professional
ccxtappserverlib เป็นไลบรารี MQL5 สำหรับการทำงานกับการแลกเปลี่ยน crypto ผ่าน node.js และ เซิร์ฟเวอร์แอปพลิเคชัน CCXT สร้างขึ้นที่ด้านบนของ CCXT

รุ่นเบต้าล่าสุดของ ccxtappserver ห้องสมุดรวมถึงการแคชที่ได้รับการปรับปรุงให้ดีที่สุดของการแลกเปลี่ยน “ตลาด” (ข้อกำหนดของเครื่องมือและเงื่อนไขการซื้อขายอื่น ๆ ) รอยเท้าหน่วยความจำน้อยลงในระหว่างการแยกวิเคราะห์ไฟล์ JSON ขนาดใหญ่การจัดการข้อผิดพลาดที่ดีขึ้นและตัวอย่างใหม่

blogpost นี้จะนำเสนอการแสดงเบื้องต้นที่มีฟังก์ชั่นที่สำคัญที่สุดจาก API สาธารณะ – สคริปต์ ccxtappsrvshowcase.mq5

ก่อนอื่นให้รวมส่วนหัว

#embrace "ccxtjsmtlib.mqh" 
#embrace "ccxtutil.mqh"

ในอินพุตการตั้งค่าโหนดเซิร์ฟเวอร์ควรทำ (โดยค่าเริ่มต้นจะเป็น localhost และพอร์ต 8124)

enter group "Connection settings"
enter string NodeServer = "http://127.0.0.1:8124";
enter string NodeAuth = ""; 

ถัดไปให้การแลกเปลี่ยนเฉพาะที่คุณต้องการทำงานด้วย ปล่อยให้อินพุตว่างเปล่าเพื่อดูการพิมพ์ด้วยรายการของการแลกเปลี่ยนที่รองรับทั้งหมด

enter string Trade = ""; 

ยังมีทิกเกอร์ที่คุณสนใจหากคุณไม่ทราบชื่อให้เรียกใช้สคริปต์เป็นครั้งแรกและดูที่ MQL5/Recordsdata/CCXT/ โฟลเดอร์ที่ข้อมูลที่ได้รับทั้งหมดถูกทิ้งโดยค่าเริ่มต้นดังนั้นคุณสามารถค้นหา JSON-Recordsdata พร้อมข้อมูลตลาดเต็มรูปแบบ

enter string Ticker = "BCH/USDT";

สำหรับการดูการทดสอบ (การสมัครสมาชิกผ่าน WebSockets) ระบุระยะเวลาของพวกเขา:

enter uint WatchingDuration = 10; 

สคริปต์แสดงให้เห็นถึงวิธีการตั้งค่าข้อมูลรับรองสำหรับ API ส่วนตัว แต่จะไม่ใช้ฟังก์ชั่นส่วนตัวใด ๆ

enter group "Trade settings (Personal API)"
enter string ApiKey = "";
enter string Secret = "";
enter string Uid = "";
enter string Login = "";
enter string Password = "";

การตั้งค่าเพิ่มเติมช่วยให้คุณสามารถควบคุมระดับการบันทึกการทิ้งข้อมูลที่ได้รับทั้งหมดและหมดเวลา

enter group "Auxiliary settings"
enter ushort Logging = 1; 
enter bool Dumping = true;
enter uint Timeout = 5; 

จากนั้นตัวจัดการกิจกรรมหลัก เริ่มต้น เข้ามาเล่น ฟังก์ชั่นการนำเข้าคลาสและวิธีการจากไลบรารีจะถูกเน้นเป็นสีเหลือง บางส่วนถูกละเว้นเพื่อความกะทัดรัด (สำหรับรายละเอียดดูที่ซอร์สโค้ดเต็มรูปแบบแจกจ่ายด้วยไลบรารี)

ความคิดเห็นแบบอินไลน์เป็นการอธิบายตนเองฉันคิดว่า

หากสคริปต์ทำงานเป็นครั้งแรกมันจะขอให้แกะ (ด้วยตนเอง) CCXT แอปพลิเคชันเซิร์ฟเวอร์ (แยกเป็น ccxtappsrvbundle.jsc จากทรัพยากรในตัว) และเรียกใช้ node.js ด้วย

void OnStart()
{
   
   
   
   PrintFormat("CCXT AppSrvLibrary model: %.2f", AppSrvLibraryVersion());
   const static string standing() = {"Cannot deploy",
      "App server ZIP is deployed, however not extracted",
      "App server recordsdata are deployed"};
   const int d = DeployCcxtAppServer();
   Print(standing(d + 1));
   if(d <= 0)
   {
      return; 
   }

   
   
   
   SetNodeServer(NodeServer, NodeAuth);

   CcxtLink::Settings settings = {Logging, Dumping, Testing, Timeout, 0};
   CcxtLink *hyperlink = GetLink();  
   hyperlink.applySettings(settings);
   
   
   if(!StringLen(Trade))
   {
      Print("Full listing of exchanges:");
      Print(ListExchanges().stringify());
      Print("Professional listing of exchanges with websockets assist:");
      Print(ListExchanges(true).stringify());

      Print("App Server Model: ", AppSrvVersion().stringify());
      Print("CCXT lib model: ", CcxtVersion()("model").stringify());
      return;
   }

   
   
   
   CCXT::Credentials credentials = {ApiKey, Secret, Uid, Login, Password};
   
   
   CcxtJsExchangeProIntf *ccxt = CreateExchangePro(Trade, credentials, false);
   AutoPtr<CcxtJsExchangeProIntf> auto(ccxt);
   
   
   
   
   
   if(hyperlink.getLastHttpCode() != 200) 
   {
      return;
   }

   
   const bool isPro = !!*ccxt("professional");
   if(ShowExchangeProperties)
   {
      Print("Is professional: ", isPro);
      Print("Required Credentials:");
      ccxt("requiredCredentials").print();
      Print("Supported options:");         
      ccxt("has").print();
      AutoPtr<JsValue> f = ccxt.get("services"); 
      Print("Services: ", f().stringify());
   }

   

   
   
   
   AutoPtr<JsValue> examine = ccxt.get();
   if(Dumping) DumpJsonToFile("CCXT/check-" + Trade, examine());
   
   
   
   
   
   if(ccxt.name("now").t != JS_PRIMITIVE)
   {
      ccxt.loadMarkets(false , false );
      JsValue *information = ccxt.get("markets"); 
      if(Dumping) DumpJsonToFile("CCXT/onlymarkets-" + Trade, information);

      
      
      
      
      
      
   }
   else
   {
      Print("Markets are already loaded on Node");
   }

   

   
   
   

   JsValue *orderbook = ccxt.fetchOrderBook(Ticker, 10);
   if(Dumping) DumpJsonToFile("CCXT/orderbook-" + Trade + "-" + Escape(Ticker), orderbook);
   
   JsValue *ticker = ccxt.fetchTicker(Ticker);
   if(Dumping) DumpJsonToFile("CCXT/ticker-" + Trade + "-" + Escape(Ticker), ticker);
   
   JsValue *ohlcv = ccxt.fetchOHLCV(Ticker, "1m", t ? t - 1000 * 60 * 10 : 0, 10);
   if(Dumping) DumpJsonToFile("CCXT/ohlcv-" + Trade + "-" + Escape(Ticker), ohlcv);

   JsValue *trades = ccxt.fetchTrades(Ticker, t ? t - 10000 : 0, 10);
   if(Dumping) DumpJsonToFile("CCXT/trades-" + Trade + "-" + Escape(Ticker), trades);
   
   if(!!*ccxt("has")("fetchBidsAsks")) 
   {
      string array() = {Ticker};
      JsValue *bidsasks = ccxt.fetchBidsAsks(array);
      if(Dumping) DumpJsonToFile("CCXT/bidsasks-" + Trade + "-" + Escape(Ticker), bidsasks);
   }

   
   
   
   ccxt.fetchAnything(NULL);
   ...

URL ที่ร้องขอและชื่อที่เกี่ยวข้องของไฟล์ที่บันทึกไว้จะแสดงในบันทึก

และตอนนี้ไปส่วน CCXT Professional ตาม WebSockets และการสมัครรับการแจ้งเตือนสด

   
  
   
   if(isPro && ccxt.improve())
   {
      
      ccxt.watchOrderBook(Ticker);
      ccxt.watchTrades(Ticker);
      string tickers() = {Ticker};
      ccxt.watchBidsAsks(tickers);
      ccxt.watchTrades(Ticker); 
      const uint begin = GetTickCount();
      whereas(!IsStopped() && ccxt.isConnected() && (!WatchingDuration || GetTickCount() - begin < WatchingDuration * 1000))
      {
         AutoPtr<JsValue> j = ccxt.readMessage(); 
         if(j())
         {
            Remark(j().stringify()); 
         }
         else
         {
            
         }
      }
   }
   else
   {
      if(isPro && ccxt.isConnected())
      {
         Print("Cannot improve to websockets");
         string headers()(2);
         if(ccxt.ws().getHeaders(headers))
         {
            
         }
         ccxt.ws().shut(); 
      }
   }

   
   if(ccxt.isConnected())
   {
      Print("Unsubscribing...");
      
      ccxt.un().watchOrderBook(Ticker);
      ccxt.un().watchTrades(Ticker);
      ccxt.un().watchBidsAsks(); 
      ccxt.un().watchTrades(Ticker); 

      const uint begin = GetTickCount(); 
      whereas(!IsStopped() && ccxt.isConnected() && (GetTickCount() - begin < 5 * 1000))
      {
         Print("studying...");
         AutoPtr<JsValue> j = ccxt.readMessage();
         if(j())
         {
            Remark(j().stringify());
         }
         else
         {
            break;
         }
      }
      
      Print("Closing...");
      
      ccxt.shut();
      
      whereas(!IsStopped()) 
      {
         AutoPtr<JsValue> j = ccxt.readMessage();
         if(j())
         {
            Remark(j().stringify());
         }
         else
         {
            break;
         }
      }
   }
}

เมื่อสคริปต์กำลังทำงานข้อมูล WebSocket ที่เข้ามาทั้งหมดจะแสดงเป็นความคิดเห็นในแผนภูมิ (แม้ว่าข้อมูลสามารถอัปเดตได้อย่างรวดเร็ว)

ดูการแลกเปลี่ยน crypto ผ่าน CCXT Application Server Library

ปัจจุบันไลบรารีเซิร์ฟเวอร์แอปพลิเคชัน CCXT อยู่ในเวทีเบต้าและพร้อมใช้งานสำหรับการทดสอบตามคำขอ

(tagstotranslate) Trade (T) Crypto (T) Demo (T) Library (T) Script (T) CCXT (T) Node.js

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

ความเห็นล่าสุด