Bybit EA Connection Library Documentation for MT5
Product URL : https://www.mql5.com/en/market/product/164455
Documentation of Bybit API URL: https://bybit-exchange.github.io/docs/v5/guide
Tutorial 1 : Trading Operations
Script Demo :
Note : Once you purchased the Library, It will be found under Scripts/Market Folder
#property copyright "Copyright 2026, Rajesh Kumar Nait" #property link "https://www.mql5.com/en/users/rajeshnait/seller" #property version "1.00" #property description "Uncomment code which is required" #includeCJAVal jv(NULL, jtUNDEF); struct BybitConfig { string api_url; string api_key; string api_secret; string api_suffix; string symbol_prefix; string category; string isLeverage; bool debug; }; #import "..\Libraries\Library_Bybit_new.ex5" void Bybit_Init(BybitConfig &config); string GetTime(); string Get_exchangeInfo(); string orderLimit(string symbol, string side, double quantity, double price); string orderAmend(string symbol, string orderId, double qty, double price); string orderMarket(string symbol, string side, double quantity); string setTradingStop(string symbol, string slTrigger, string tpTrigger); string orderCancel(string symbol, string orderId); string orderCancelAll(string symbol); string orderRealtime( string symbol, string orderId, string openOnly); string orderHistory( string symbol, string orderId, string execType, string startTime, string endTime, string cursor); string tradeHistory( string symbol, string orderId, string orderStatus, string startTime, string endTime, string cursor); string getWalletBalance(string accountType); string setLeverage(string symbol, string buyLeverage, string sellLeverage); string getPositionMode(string symbol, string cursor); void CreateSymbols_Bybit(); void RunUpdate(string symbol, datetime StartDateTime); #import bool Bybit_debug = true; string Bybit_Key = "L51zfkjJZOCdF3ufip"; string Bybit_Secret = "txnyks6V3dkyhUWWY64l5ay02B0V6V5MNNZa"; string Bybit_URL = "https://api-testnet.bybit.com"; string Bybit_suffix = "/v5/"; string Bybit_SymbolPrefix = "bf_"; string category = "linear"; string isLeverage = "1"; datetime MaxDate= D'2026-2-1 00:00:00'; string sym; BybitConfig config; void OnStart() { config.api_url = Bybit_URL; config.api_key = Bybit_Key; config.api_secret = Bybit_Secret; config.api_suffix = Bybit_suffix; config.symbol_prefix = Bybit_SymbolPrefix; config.debug = Bybit_debug; config.category = category; config.isLeverage = isLeverage; Bybit_Init(config);
FAQ
1. How to remove symbol prefix from my symbol when sending order to binance? if symbol prefix is a_BTCUSDT, when sending order via API you should send “BTCUSDT” only
here is the script tutorial to remove prefix from your symbol
void OnStart() { string sym = _Symbol; string prefix = "bf_"; int length = 3; string resultString; if (StringSubstr(sym, 0, length) == prefix) { resultString = StringSubstr(sym, length); } else { resultString = sym; } Print("Original Symbol: ", sym); Print("Result String: ", resultString); }
2. How do i run chart to be updated every few seconds via API?
Binance recommends to update chart via Websocket which is available on product Crypto Charting because API is not for real time chart and running it too frequently may result in temporary IP ban by Binance, but if you wish not to use it and update history via API
here is how you can do it by adding this on your EA.
#property copyright "Copyright 2024, MetaQuotes Ltd." #property link "https://www.mql5.com" #property version "1.00" int updatetime = 60; int OnInit() { EventSetTimer(1); return(INIT_SUCCEEDED); } void OnDeinit(const int reason) { EventKillTimer(); } void OnTimer() { while(!IsStopped()) { datetime now = TimeGMT(); static datetime UpdateTime = now; if(UpdateTime==now) { datetime mydate = iTime("bf_ETHUSDT",PERIOD_M1,2); RunUpdate("ETHUSDT", mydate); Print("Update Done"); UpdateTime=now + updatetime; } } }