Binance Library
- Bibliotecas
- Hadil Mutaqin SE
- Versión: 1.82
- Actualizado: 16 enero 2025
- Activaciones: 5
La librería se utiliza para desarrollar trading automático en el Mercado Spot de Binance desde la plataforma MT5.
- Soporta todos los tipos de órdenes: Límite, Mercado, StopLimit y StopMarket
- Soporta el modo Testnet
- Muestra automáticamente el gráfico en la pantalla
Uso:
1. Abrir cuenta demo MQL5
2. Descargue elarchivo Headery el ejemplo deEA https://drive.google.com/uc?export=download&id=1kjUX7Hyy02EiwTLgVi8qdaCNvNzazjln
- Copiar Binance.mqh a la carpeta \MQL5\Include
- Copia BinanceEA-Sample.mq5 a la carpeta \MQL5\Expertos
3. Permitir WebRequest de MT5 Herramientas menú >> Opciones >> Asesores Expertos y añadir URL:
https://testnet.binance.vision
4. Abra cualquier gráfico y adjunte BinanceEA-Sample al gráfico
Funciones de la Biblioteca Binance:
Esta función debe ser llamada desde la función OnInit()
void init ( string symbol, // nombre del símbolo string historicalData, // historicalData: 1W = 1 semana, 1M = 1 mes, 3M = 3 meses, 6M = 6 meses, 1Y = 1 año string apiKey, // clave api binance string secretKey, // clave secreta de binance bool testnet = false // modo testnet );
Esta función debe ser llamada desde la función OnTimer()
void getTickData(); Esta función debe ser llamada desde la función OnDeinit()
void deinit(); La función utilizada para colocar la orden, devuelve orderId si tiene éxito, de lo contrario -1
long order ( ORDERTYPE orderType, // enum ORDERTYPE: COMPRA_MERCADO, VENTA_MERCADO, COMPRA_LIMITE, VENTA_LIMITE, COMPRA_STOP, VENTA_STOP, COMPRA_STOPLIMIT, VENTA_STOPLIMIT double quantity, // cantidad del pedido double limitPrice = 0, // precio límite de la orden double stopPrice = 0, // orden stopPrecio string timeInForce = "GTC", // timeInForce: GTC, IOC, FOK, por defecto GTC string comment = "" // comentario de pedido );
Cancelar órdenes abiertas, devuelve true si se ha realizado correctamente, false en caso contrario
bool cancelOrder ( long orderId = -1 // Id de orden, por defecto -1 cancelar todas las órdenes abiertas );
Obtener el número de órdenes abiertas
int ordersTotal ( ORDERTYPE orderType = -1 // enum ORDERTYPE: BUY_LIMIT, SELL_LIMIT, BUY_STOP, SELL_STOP, BUY_STOPLIMIT, SELL_STOPLIMIT, por defecto -1 número de todas las órdenes abiertas );
Obtener el saldo de activos disponibles
double getBalance ( string asset // nombre del activo );
Obtener información de la bolsa, devuelve la estructura ExchangeInfo si tiene éxito
void getExchangeInfo ( ExchangeInfo &exchangeInfo // [out] Estructura ExchangeInfo );
Obtener el libro de órdenes, devuelve la estructura OrderBook en caso de éxito
void getOrderBook ( OrderBook &orderBook[], // [out] Matriz de la estructura OrderBook int limit = 5 // límite: 5, 10, 20, 50, 100, por defecto 5 );
Obtener órdenes abiertas, devuelve la estructura OpenOrders en caso de éxito
void getOpenOrders ( OpenOrders &openOrders[] // [out] matriz de la estructura OpenOrders );
Obtener el historial de operaciones, devuelve la estructura TradeHistory si se ha realizado correctamente
void getTradeHistory ( TradeHistory &tradeHistory[], // [out] matriz de la estructura tradeHistory int limit = 10 // límite por defecto 10, máximo 1000 );
Ejemplo de cómo llamar a la Biblioteca Binance desde 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.