Binance Futures Library
- Bibliotheken
- Hadil Mutaqin SE
- Version: 1.53
- Aktualisiert: 16 Januar 2025
- Aktivierungen: 5
Die Bibliothek wird verwendet, um den automatischen Handel auf dem Binance-Futures-Markt von der MT5-Plattform aus zu entwickeln.
- Unterstützt Binance Futures USD-M und COIN-M
- Unterstützung des Testnet-Modus
- Unterstützt alle Ordertypen: Limit, Market, StopLimit, StopMarket, StopLoss und TakeProfit
- Automatische Anzeige des Charts auf dem Bildschirm
Verwendung:
1. Eröffnen Sie ein MQL5 Demo-Konto
2. Laden Sie die Header-Datei und das EA-Beispiel herunter https://drive.google.com/uc?export=download&id=17fWrZFeMZoSvH9-2iv4WDJhcyxG2eW17
- Kopieren Sie BinanceFutures.mqh in den Ordner \MQL5\Include
- Kopieren Sie BinanceFuturesEA-Sample.mq5 in den Ordner \MQL5\Experts
3. Erlauben Sie WebRequest im Menü MT5 Tools >> Optionen >> Expert Advisors und fügen Sie die URL hinzu:
https://testnet.binancefuture.com
4. Öffnen Sie einen beliebigen Chart und fügen Sie BinanceFuturesEA-Sample in den Chart ein
Binance Futures Library Funktionen:
Diese Funktion muss von der Funktion OnInit() aufgerufen werden
void init ( string symbol, // Symbolname string historicalData, // historicalData: 1W = 1 Woche, 1M = 1 Monat, 3M = 3 Monate, 6M = 6 Monate, 1Y = 1 Jahr string apiKey, // binance api schlüssel string secretKey, // Binance-Geheimschlüssel bool testnet = false // Testnetz-Modus );
Diese Funktion muss von der OnTimer() Funktion aufgerufen werden
void getTickData(); Diese Funktion muss von der OnDeinit() Funktion aufgerufen werden
void deinit(); Die Funktion wird verwendet, um eine Order zu platzieren, gibt orderId zurück, wenn erfolgreich, ansonsten -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, // Bestellmenge double limitPrice = 0, // BestellgrenzePreis double stopPrice = 0, // Bestellung stopPreis double stopLossPrice = 0, // StopLoss-Kurs double takeProfitPrice = 0, // takeProfit Preis string timeInForce = "GTC", // timeInForce: AGB, IOC, FOK, Standard-GTC string comment = "" // Kommentar zur Bestellung );
Stoploss und Takeprofit setzen, gibt bei Erfolg true zurück, sonst false
bool setSLTP ( SIDE side, // enum SIDE: KAUFEN, VERKAUFEN double stopLossPrice, // StopLoss-Kurs double takeProfitPrice // Gewinnmitnahmepreis );
Stornieren offener Orders, gibt bei Erfolg true zurück, sonst false
bool cancelOrder ( long orderId = -1 // Auftragsnummer, Standardwert -1 storniert alle offenen Aufträge );
Offene Positionen schließen, gibt bei Erfolg true zurück, sonst false
bool closePosition ( SIDE side = -1 // enum SIDE: BUY, SELL, default -1 alle offenen Positionen schließen );
Get exchange info, liefert bei Erfolg die ExchangeInfo-Struktur
void getExchangeInfo ( ExchangeInfo &exchangeInfo // [out] ExchangeInfo-Struktur );
Orderbuch abrufen, liefert im Erfolgsfall OrderBook-Struktur-Array
void getOrderBook ( OrderBook &orderBook[], // [out] Array der OrderBook-Struktur int limit = 5 // Grenzwert: 5, 10, 20, 50, 100, Standardwert 5 );
Ermittelt offene Orders, liefert im Erfolgsfall OpenOrders-Struktur-Array
void getOpenOrders ( OpenOrders &openOrders[] // [out] OpenOrders-Struktur-Array );
Ermittelt offene Positionen, gibt im Erfolgsfall ein OpenPositions-Strukturarray zurück
void getOpenPositions ( OpenPositions &openPositions[] // [out] Array der OpenPositions-Struktur );
Liefert die Anzahl der offenen Orders
int ordersTotal ( ORDERTYPE orderType = -1 // enum ORDERTYPE: BUY_LIMIT, SELL_LIMIT, BUY_STOP, SELL_STOP, BUY_STOPLIMIT, SELL_STOPLIMIT, default -1 die Anzahl aller offenen Aufträge );
Liefert die Anzahl der offenen Positionen
int positionsTotal ( SIDE side = -1 // enum SIDE: BUY, SELL, default -1 die Anzahl aller offenen Positionen );
Leverage setzen, gibt bei Erfolg true zurück, sonst false
bool setLeverage ( int leverage // Hebelwirkung );
Verfügbares Guthaben abfragen
double getBalance(); Hedge-Positionsmodus einstellen, bei Erfolg wird true zurückgegeben, sonst false
bool setHedgeMode();
Einweg-Positionsmodus einstellen, bei Erfolg wird true zurückgegeben, sonst false
bool setOneWayMode();
Isolierten Margin-Typ setzen, bei Erfolg true, sonst false
bool setIsolatedMargin();
Setze gekreuzten Margin-Typ, gibt true zurück, wenn erfolgreich, sonst false
bool setCrossedMargin();
Beispiel für den Aufruf der Binance Futures Library aus EA
#include <BinanceFutures.mqh>
input string Symbol = "BTCUSDC";
input string HistoricalData = "1W";
input string ApiKey = "";
input string SecretKey = "";
BinanceFutures b;
int OnInit()
{
b.init(Symbol,HistoricalData,ApiKey,SecretKey);
return 0;
}
void OnTimer()
{
b.getTickData();
}
void OnDeinit(const int reason)
{
b.deinit();
}
void OnTick()
{
// Place buy market order
// b.order(BUY_MARKET,0.001);
// Place buy limit order
// b.order(BUY_LIMIT,0.001,75000);
// Place buy stop order
// b.order(BUY_STOP,0.001,0,115000);
// Place buy stoplimit order
// b.order(BUY_STOPLIMIT,0.001,110000,115000);
// Place sell market order
// b.order(SELL_MARKET,0.001);
// Place sell limit order
// b.order(SELL_LIMIT,0.001,115000);
// Place sell stop order
// b.order(SELL_STOP,0.001,0,75000);
// Place sell stoplimit order
// b.order(SELL_STOPLIMIT,0.001,80000,75000);
// Cancel all open orders
// b.cancelOrder();
// Close all open positions
// b.closePosition();
// Set leverage to 10x
// b.setLeverage(10);
// Set crossed margin type
// b.setCrossedMargin();
// Set isolated margin type
// b.setIsolatedMargin();
// Set hedge position Mode
// b.setHedgeMode();
// Set oneWay position Mode
// b.setOneWayMode();
// Get the number of all open orders
// int ordTotal = b.ordersTotal();
// Get the number of all open positions
// int posTotal = b.positionsTotal();
// Get available balance
// double balance = b.getBalance();
/* // Get exchangeInfo data
ExchangeInfo exchangeInfo;
b.getExchangeInfo(exchangeInfo);
double minQty = exchangeInfo.minQty;
double maxQty = exchangeInfo.maxQty;
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;
ulong time = openOrders[i].time;
}
}
*/
/* // 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;
}
*/
}

