The library is used to develop automatic trading on Binance Futures Market from MT5 platform.
- Support all order types: Limit, Market, Stop-Limit, Stop-Market, StopLoss and TakeProfit.
- Automatically display the chart on the screen.
Usage:
- Open MQL5 demo account
- Move BinanceFuturesLib.ex5 from folder \MQL5\Scripts\Market to MQL5\Libraries
- Download Header file and EA sample https://www.mql5.com/en/code/download/34976.zip
- Copy BinanceFutures.mqh header file to folder \MQL5\Include
- Copy BinanceFuturesEA-Sample.mq5 to folder \MQL5\Experts
- Attach BinanceFuturesEA-Sample to the chart
Example how to call Binance Futures Library from EA
#include <BinanceFutures.mqh>
string Symbol = "BTCUSDT";
string HistoryData = "1W";
string ApiKey = "";
string SecretKey = "";
BinanceFutures binance;
int OnInit()
{
binance.init(Symbol,HistoryData,ApiKey,SecretKey);
binance.showChart();
/*
//--Place buy market order BTCUSDT quantity 0.01 BTC at market price--//
binance.orderBuyMarket("BTCUSDT" // symbol name
,0.01 // order quantity
,0 // stopLoss price
,0); // takeProfit price
//--Place buy limit order BTCUSDT quantity 0.01 BTC at limit price 15500 USDT--//
binance.orderBuyLimit("BTCUSDT" // symbol name
,0.01 // order quantity
,15500 // limit price
,"GTC" // time in force: GTC, IOC, FOK, default GTC
,0 // stopLoss price
,0); // takeProfit price
//--Place sell market order BTCUSDT quantity 0.02 BTC at market price--//
binance.orderSellMarket("BTCUSDT" // symbol name
,0.02 // order quantity
,0 // stopLoss price
,0); // takeProfit price
//--Place sell limit order BTCUSDT quantity 0.02 BTC at limit price 25500 USDT--//
binance.orderSellLimit("BTCUSDT" // symbol name
,0.02 // order quantity
,25500 // limit price
,"GTC" // time in force: GTC, IOC, FOK, default GTC
,0 // stopLoss price
,0); // takeProfit price
//--Get orderBook data--//
OrderBook orderBook[];
binance.getOrderBook(Symbol(),orderBook);
for(int i = 0; i < ArraySize(orderBook); i++)
{
Print("AskPrice[",i,"] = ", orderBook[i].askPrice);
Print("AskQty[",i,"] = ", orderBook[i].askQty);
Print("BidPrice[",i,"] = ", orderBook[i].bidPrice);
Print("BidQty[",i,"] = ", orderBook[i].bidQty);
}
//--Get open orders--//
OpenOrders openOrders[];
binance.getOpenOrders(Symbol(),openOrders);
for(int i = 0; i < ArraySize(openOrders); i++)
{
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;
bool closePosition = openOrders[i].closePosition;
}
//--Get open positions--//
OpenPositions openPositions[];
binance.getOpenPositions(Symbol(),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;
}
//--Check Balance-//
double balance = binance.balance();
//--Set Leverage to 10x--//
binance.setLeverage(10);
*/
return 0;
}
void OnTimer()
{
binance.getTickData();
}
void OnDeinit(const int reason)
{
binance.deinit();
}
void OnTick()
{
}