Binance Library
- Bibliotheken
- Hadil Mutaqin SE
- Version: 1.82
- Aktualisiert: 16 Januar 2025
- Aktivierungen: 5
Die Bibliothek wird verwendet, um den automatischen Handel auf dem Binance Spot Market von der MT5-Plattform aus zu entwickeln.
- Unterstützt alle Ordertypen: Limit, Markt, StopLimit und StopMarket
- Unterstützung des Testnet-Modus
- Automatische Anzeige des Charts auf dem Bildschirm
Verwendung:
1. Öffnen Sie das MQL5-Demokonto
2.Header-Datei und EA-Beispiel herunterladen https://drive.google.com/uc?export=download&id=1kjUX7Hyy02EiwTLgVi8qdaCNvNzazjln
- Kopieren Sie Binance.mqh in den Ordner \MQL5\Include
- Kopieren Sie BinanceEA-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.binance.vision
4. Öffnen Sie einen beliebigen Chart und fügen Sie BinanceEA-Sample dem Chart hinzu
Binance 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, die verwendet wird, um eine Order zu platzieren, gibt bei Erfolg orderId zurück, andernfalls -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 string timeInForce = "GTC", // timeInForce: AGB, IOC, FOK, Standard-GTC string comment = "" // Kommentar zur Bestellung );
Abbrechen von offenen Aufträgen, gibt true zurück, wenn erfolgreich, sonst false
bool cancelOrder ( long orderId = -1 // Auftragsnummer, Standardwert -1 storniert alle offenen Aufträge );
Ermittelt die Anzahl der offenen Aufträge
int ordersTotal ( ORDERTYPE orderType = -1 // enum ORDERTYPE: BUY_LIMIT, SELL_LIMIT, BUY_STOP, SELL_STOP, BUY_STOPLIMIT, SELL_STOPLIMIT, default -1 Anzahl aller offenen Aufträge );
Verfügbares Guthaben abfragen
double getBalance ( string asset // Name der Anlage );
Abrufen von Börseninformationen, gibt bei Erfolg eine ExchangeInfo-Struktur zurück
void getExchangeInfo ( ExchangeInfo &exchangeInfo // [out] ExchangeInfo-Struktur );
Orderbuch abfragen, gibt im Erfolgsfall ein OrderBook-Strukturarray zurück
void getOrderBook ( OrderBook &orderBook[], // [out] Array der OrderBook-Struktur int limit = 5 // Grenzwert: 5, 10, 20, 50, 100, Standardwert 5 );
Ermittelt offene Orders, gibt im Erfolgsfall ein OpenOrders-Strukturarray zurück
void getOpenOrders ( OpenOrders &openOrders[] // [out] OpenOrders-Struktur-Array );
Abfrage der Handelshistorie, liefert im Erfolgsfall ein TradeHistory-Strukturarray
void getTradeHistory ( TradeHistory &tradeHistory[], // [out] Array der Struktur tradeHistory int limit = 10 // Grenze standardmäßig 10, maximal 1000 );
Beispiel für den Aufruf der Binance Library aus EA
#include <Binance.mqh>
input string Symbol = "BTCUSDC";
input string HistoricalData = "1W";
input string ApiKey = "";
input string SecretKey = "";
Binance 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,120000);
// Place buy stoplimit order
// b.order(BUY_STOPLIMIT,0.001,110000,120000);
// Place sell market order
// b.order(SELL_MARKET,0.001);
// Place sell limit order
// b.order(SELL_LIMIT,0.001,120000);
// 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();
// Get available asset balance
// double balanceBTC = b.getBalance("BTC");
// double balanceUSDC = b.getBalance("USDC");
// Get the number of all open orders
// int ordTotal = b.ordersTotal();
/* // Get exchangeInfo
ExchangeInfo exchangeInfo;
b.getExchangeInfo(exchangeInfo);
string baseAsset = exchangeInfo.baseAsset;
string quoteAsset = exchangeInfo.quoteAsset;
double minQty = exchangeInfo.minQty;
double maxQty = exchangeInfo.maxQty;
double minNotional = exchangeInfo.minNotional;
int qtyDigit = exchangeInfo.qtyDigit;
int priceDigit = exchangeInfo.priceDigit;
*/
/* // Get orderBook
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++)
{
long orderId = openOrders[i].orderId;
string symbol = openOrders[i].symbol;
string side = openOrders[i].side;
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 origQty = openOrders[i].origQty;
double executedQty = openOrders[i].executedQty;
ulong time = openOrders[i].time;
}
*/
/* // Get trade history
TradeHistory tradeHistory[];
b.getTradeHistory(tradeHistory);
for(int i = 0; i < ArraySize(tradeHistory); i++)
{
long orderId = tradeHistory[i].orderId;
string symbol = tradeHistory[i].symbol;
double price = tradeHistory[i].price;
double qty = tradeHistory[i].qty;
double quoteQty = tradeHistory[i].quoteQty;
double commission = tradeHistory[i].commission;
string commissionAsset = tradeHistory[i].commissionAsset;
ulong time = tradeHistory[i].time;
bool isBuyer = tradeHistory[i].isBuyer;
bool isMaker = tradeHistory[i].isMaker;
}
*/
} 

The best Binance library. I do recommend it to everyone.