Binance Futures Library
- ライブラリ
- Hadil Mutaqin SE
- バージョン: 1.49
- アップデート済み: 8 1月 2025
- アクティベーション: 5
The library is used to develop automatic trading on Binance Futures Market from MT5 platform.
- Support Binance Futures USD-M and Futures COIN-M
- Support Testnet mode
- Support all order types: Limit, Market, StopLimit, StopMarket, StopLoss and TakeProfit
- Automatically display the chart on the screen
Usage:
- Open MQL5 demo account
- Download Header file and EA sample https://drive.google.com/uc?export=download&id=17fWrZFeMZoSvH9-2iv4WDJhcyxG2eW17
- Copy BinanceFutures.mqh header file to folder \MQL5\Include
- Copy BinanceFuturesEA-Sample.mq5 to folder \MQL5\Experts
- Allow WebRequest from MT5 Tools menu >> Options >> Expert Advisors and add URL:
https://testnet.binancefuture.com
- Open any chart and attach BinanceFuturesEA-Sample to the chart
Binance Futures Library Functions:
This function must be called from the OnInit() function
void init ( string symbol, // symbol name string historyData, // history data: 1W = 1 week, 1M = 1 month, 3M = 3 months, 6M = 6 months, 1Y = 1 year, MAX = maximum available data string apiKey, // binance api key string secretKey, // binance secret key bool testnet = false // testnet mode );
This function must be called from the OnTimer() function
void getTickData();
This function must be called from the OnDeinit() function
void deinit();
The function used to place order, returns orderId if successful, otherwise -1
long order ( ORDERTYPE orderType, // enum ORDERTYPE: BUY_MARKET, SELL_MARKET, BUY_LIMIT, SELL_LIMIT, BUY_STOP, SELL_STOP, BUY_STOPLIMIT, SELL_STOPLIMIT double quantity, // order quantity double limitPrice, // order limitPrice double stopPrice, // order stopPrice double stopLossPrice, // stopLoss price double takeProfitPrice, // takeProfit price string timeInForce = "GTC", // timeInForce: GTC, IOC, FOK, default GTC string comment = "" // order comment );
Returns balance value
double getBalance();
Set stoploss and takeprofit, returns true if successful, otherwise false
bool setSLTP ( SIDE side, // enum SIDE: BUY, SELL double stopLossPrice, // stopLoss price double takeProfitPrice // takeprofit price );
Cancel open orders, returns true if successful, otherwise false
bool cancelOrder ( long orderId = -1 // order Id, default -1 cancel all open orders );
Close open positions, returns true if successful, otherwise false
bool closePosition ( SIDE side = -1 // enum SIDE: BUY, SELL, default -1 close all open positions );
Get Exchange info data, returns ExchangeInfo structure if successful
void getExchangeInfo ( ExchangeInfo& exchangeInfo // [out] ExchangeInfo structure );
Get orderBook data, returns OrderBook structure array if successful
void getOrderBook ( OrderBook& orderBook[], // [out] OrderBook structure array int limit = 5 // limit: 5, 10, 20, 50, 100, default 5 );
Get open orders, returns OpenOrders structure array if successful
void getOpenOrders ( OpenOrders& openOrders[] // [out] OpenOrders structure array );
Get open positions, returns OpenPositions structure array if successful
void getOpenPositions ( OpenPositions& openPositions[] // [out] OpenPositions structure array );
Set leverage, returns true if successful, otherwise false
bool setLeverage(int leverage);
Set hedge position mode, returns true if successful, otherwise false
bool setHedgeMode();
Set one-way position mode, returns true if successful, otherwise false
bool setOneWayMode();
Set isolated margin type, returns true if successful, otherwise false
bool setIsolatedMargin();
Set crossed margin type, returns true if successful, otherwise false
bool setCrossedMargin();
Returns the number of open orders
int ordersTotal(ORDERTYPE orderType = -1);
Returns the number of open positions
int positionsTotal(SIDE side = -1);
Example how to call Binance Futures Library from EA
#include <BinanceFutures.mqh> input string Symbol = "BTCUSDT"; // Symbol name input string HistoryData = "1W"; // History data (1W = 1 week, 1M = 1 month, 3M = 3 months, 6M = 6 months, 1Y = 1 year, MAX = maximum available data) input string ApiKey = ""; // Binance api key input string SecretKey = ""; // Binance secret key BinanceFutures b; int OnInit() { b.init(Symbol,HistoryData,ApiKey,SecretKey); return 0; } void OnTimer() { b.getTickData(); } void OnDeinit(const int reason) { b.deinit(); } void OnTick() { // b.order(BUY_MARKET,0.01,0,0,0,0); // Place buy market order // b.order(BUY_LIMIT,0.01,75000,0,0,0); // Place buy limit order // b.order(BUY_STOP,0.01,0,115000,0,0); // Place buy stop order // b.order(BUY_STOPLIMIT,0.01,110000,115000,0,0); // Place buy stoplimit order // b.order(SELL_MARKET,0.01,0,0,0,0); // Place sell market order // b.order(SELL_LIMIT,0.01,115000,0,0,0); // Place sell limit order // b.order(SELL_STOP,0.01,0,75000,0,0); // Place sell stop order // b.order(SELL_STOPLIMIT,0.01,80000,75000,0,0); // Place sell stoplimit order // b.getBalance(); //--Check balance // b.cancelOrder(); //--Cancel all open orders // b.closePosition(BUY); //--Close buy position // b.closePosition(SELL); //--Close sell position // b.closePosition(); //--Close all open positions // b.setLeverage(10); //--Set leverage to 10x // b.setCrossedMargin(); //--Set crossed margin type // b.setIsolatedMargin(); //--Set isolated margin type // b.setHedgeMode(); //--Set hedge position Mode // b.setOneWayMode(); //--Set oneWay position Mode /* // Get exchangeInfo data ExchangeInfo exchangeInfo; b.getExchangeInfo(exchangeInfo); double minQty = exchangeInfo.minQty; double maxQty = exchangeInfo.maxQty; double stepSize = exchangeInfo.stepSize; double minNotional = exchangeInfo.minNotional; int qtyDigit = exchangeInfo.qtyDigit; int priceDigit = exchangeInfo.priceDigit; int contractSize = exchangeInfo.contractSize; */ /* // Get orderBook data OrderBook orderBook[]; b.getOrderBook(orderBook); for(int i = 0; i < ArraySize(orderBook); i++) { double askPrice = orderBook[i].askPrice; double askQty = orderBook[i].askQty; double bidPrice = orderBook[i].bidPrice; double bidQty = orderBook[i].bidQty; } */ /* // Get open orders OpenOrders openOrders[]; b.getOpenOrders(openOrders); for(int i = 0; i < ArraySize(openOrders); i++) { bool closePosition = openOrders[i].closePosition; if(closePosition == false) { long orderId = openOrders[i].orderId; string symbol = openOrders[i].symbol; string side = openOrders[i].side; string positionSide = openOrders[i].positionSide; string type = openOrders[i].type; string status = openOrders[i].status; string timeInForce = openOrders[i].timeInForce; double price = openOrders[i].price; double stopPrice = openOrders[i].stopPrice; double avgPrice = openOrders[i].avgPrice; double origQty = openOrders[i].origQty; double executedQty = openOrders[i].executedQty; } } */ /* // Get open positions OpenPositions openPositions[]; b.getOpenPositions(openPositions); for(int i = 0; i < ArraySize(openPositions); i++) { string symbol = openPositions[i].symbol; string side = openPositions[i].side; string positionSide = openPositions[i].positionSide; double positionAmt = openPositions[i].positionAmt; double entryPrice = openPositions[i].entryPrice; double markPrice = openPositions[i].markPrice; double unRealizedProfit = openPositions[i].unRealizedProfit; double liquidationPrice = openPositions[i].liquidationPrice; } */ }