Delta Exchange Library API Sample Script

19 July 2026, 09:30
Rajesh Kumar Nait
0
313

Product URL : https://www.mql5.com/en/market/product/186465

Delta API info : https://docs.delta.exchange/#introduction

Go to Tools -> Options and add URL under expert tab - 

api.india.delta.exchange
#property copyright "Copyright 2026"
#property link      "https://www.mql5.com"
#property version   "1.0"
#property script_show_inputs

struct DeltaConfig {
   string            api_url;
   string            api_key;
   string            api_secret;
   string            symbol_prefix;
   bool              debug;
};

#import "..\Libraries\Library_Delta.ex5"
void   Delta_Init(DeltaConfig &config);
string GetServerTime();
string GetAssets();
string GetIndices();
string GetProducts();
string GetProduct(string symbol);
string GetTickers();
string GetTicker(string symbol);
string GetOrderbook(string symbol);
string GetPublicTrades(string symbol);
string GetCandles(string symbol, string resolution, long start, long end);
string PlaceOrder(int product_id, string side, long size, string order_type, string limit_price, string stop_order_type, string stop_price, string trail_amount, string time_in_force, bool post_only, bool reduce_only, string client_order_id);
string OrderLimit(int product_id, string side, long size, double limit_price, string time_in_force, bool reduce_only);
string OrderMarket(int product_id, string side, long size, bool reduce_only);
string OrderStopLimit(int product_id, string side, long size, double stop_price, double limit_price, bool reduce_only);
string OrderStopMarket(int product_id, string side, long size, double stop_price, bool reduce_only);
string OrderTakeProfitLimit(int product_id, string side, long size, double stop_price, double limit_price, bool reduce_only);
string OrderTakeProfitMarket(int product_id, string side, long size, double stop_price, bool reduce_only);
string OrderTrailingStop(int product_id, string side, long size, double trail_amount, bool reduce_only);
string EditOrder(int product_id, long order_id, long size, double limit_price);
string CancelOrder(int product_id, long order_id);
string CancelAllOrders(int product_id);
string PlaceBracketOrder(string body);
string EditBracketOrder(string body);
string BatchCreateOrders(int product_id, string ordersArray);
string BatchEditOrders(int product_id, string ordersArray);
string BatchCancelOrders(int product_id, string ordersArray);
string GetActiveOrders(int product_id, string state);
string GetOrderById(long order_id);
string GetOrderByClientId(string client_oid);
string GetOrdersHistory(int product_id);
string GetFills(int product_id);
string ChangeLeverage(int product_id, double leverage);
string GetLeverage(int product_id);
string GetPositions(int product_id);
string GetPositionsMargined();
string ChangeMargin(int product_id, double delta_margin);
string SetAutoTopup(int product_id, bool auto_topup);
string CloseAllPositions(bool close_all_portfolio, bool close_all_isolated);
string GetWalletBalances();
string GetWalletTransactions();
void   CreateSymbols_Delta_Futures();
void   RunUpdate_Futures(datetime StartDateTime);
#import

input string   InpApiUrl        = "https://api.india.delta.exchange";
input string   InpApiKey        = "";
input string   InpApiSecret     = "";
input string   InpSymbolPrefix  = "";
input bool     InpDebug         = true;

input string   InpSymbol        = "BTCUSD";
input int      InpProductId     = 27;
input double   InpLimitPrice    = 50000.0;
input long     InpSize          = 1;

void OnStart() {
   DeltaConfig cfg;
   cfg.api_url       = InpApiUrl;
   cfg.api_key       = InpApiKey;
   cfg.api_secret    = InpApiSecret;
   cfg.symbol_prefix = InpSymbolPrefix;
   cfg.debug         = InpDebug;
   Delta_Init(cfg);

   //Print("=== Public market data ===");
   //Print("Assets: ", GetAssets());
   //Print("Indices: ", GetIndices());
   //Print("Ticker ", InpSymbol, ": ", GetTicker(InpSymbol));
   //Print("Product ", InpSymbol, ": ", GetProduct(InpSymbol));
   //Print("Orderbook ", InpSymbol, ": ", GetOrderbook(InpSymbol));
   //Print("Public trades ", InpSymbol, ": ", GetPublicTrades(InpSymbol));

   //long endT   = (long)TimeGMT();
   //long startT = endT - 3600;
   //Print("Candles 5m: ", GetCandles(InpSymbol, "5m", startT, endT));

   Print("=== Account / trading (requires valid API keys) ===");
   Print("Wallet balances: ", GetWalletBalances());
//   Print("Positions: ", GetPositions(InpProductId));
//   Print("Leverage: ", GetLeverage(InpProductId));
//
//   Print("Change leverage to 10x: ", ChangeLeverage(InpProductId, 10));
//
//   string limitResp = OrderLimit(InpProductId, "buy", InpSize, InpLimitPrice, "gtc", false);
//   Print("Limit order: ", limitResp);
//
//   Print("Market order: ", OrderMarket(InpProductId, "buy", InpSize, false));
//   Print("Stop market order: ", OrderStopMarket(InpProductId, "sell", InpSize, InpLimitPrice * 0.95, true));
//   Print("Take profit limit order: ", OrderTakeProfitLimit(InpProductId, "sell", InpSize, InpLimitPrice * 1.05, InpLimitPrice * 1.05, true));
//
//   Print("Active orders: ", GetActiveOrders(InpProductId, "open"));
//   Print("Orders history: ", GetOrdersHistory(InpProductId));
//   Print("Fills: ", GetFills(InpProductId));

//   string bracket = "{";
//   bracket += "\"product_id\":" + IntegerToString(InpProductId);
//   bracket += ",\"product_symbol\":\"" + InpSymbol + "\"";
//   bracket += ",\"stop_loss_order\":{\"order_type\":\"limit_order\",\"stop_price\":\"" + DoubleToString(InpLimitPrice * 0.95, 1) + "\",\"limit_price\":\"" + DoubleToString(InpLimitPrice * 0.945, 1) + "\"}";
//   bracket += ",\"take_profit_order\":{\"order_type\":\"limit_order\",\"stop_price\":\"" + DoubleToString(InpLimitPrice * 1.05, 1) + "\",\"limit_price\":\"" + DoubleToString(InpLimitPrice * 1.055, 1) + "\"}";
//   bracket += ",\"bracket_stop_trigger_method\":\"last_traded_price\"";
//   bracket += "}";
//   Print("Bracket order: ", PlaceBracketOrder(bracket));
//
//   string batch = "[{\"size\":" + IntegerToString(InpSize) + ",\"side\":\"buy\",\"limit_price\":\"" + DoubleToString(InpLimitPrice, 1) + "\",\"order_type\":\"limit_order\"}]";
//   Print("Batch create: ", BatchCreateOrders(InpProductId, batch));
//
//   Print("Cancel all orders: ", CancelAllOrders(InpProductId));
//   Print("Close all positions: ", CloseAllPositions(false, true));
//
//   Print("=== Symbol creation and history download ===");
//   CreateSymbols_Delta_Futures();
//   RunUpdate_Futures(TimeGMT() - 86400);

   Print("Sample finished.");
}

FAQs

1. I want to map my MT5 broker crypto symbol to Delta exchage, how can i do it?

The clean way is to separate the MT5 broker symbol from the Delta product symbol.

For example:

MT5 broker symbol     Delta symbol
-----------------------------------
BTCUSD                BTCUSD
BTCUSDm               BTCUSD
ETHUSD                ETHUSD
ETHUSDm               ETHUSD

Delta's API identifies products by their symbol , and BTCUSD is explicitly a Delta perpetual-futures product. The current API also provides GET /v2/products and GET /v2/products/{symbol} for discovering/validating products.

use this function to call 

usage :

string GetDeltaSymbol(string mt5_symbol)
//+------------------------------------------------------------------+
//| Convert MT5 broker symbol -> Delta Exchange symbol               |
//+------------------------------------------------------------------+
string GetDeltaSymbol(string mt5_symbol)
{
   string s = StringUpper(mt5_symbol);

   // ---------------------------------------------------------------
   // Remove common broker suffixes
   // Examples:
   // BTCUSD
   // BTCUSDm
   // BTCUSD.a
   // BTCUSD_i
   // BTCUSDpro
   // ---------------------------------------------------------------

   // Explicit crypto mappings
   if(StringFind(s, "BTCUSD") == 0)
      return "BTCUSD";

   if(StringFind(s, "ETHUSD") == 0)
      return "ETHUSD";

   if(StringFind(s, "SOLUSD") == 0)
      return "SOLUSD";

   if(StringFind(s, "XRPUSD") == 0)
      return "XRPUSD";

   if(StringFind(s, "BNBUSD") == 0)
      return "BNBUSD";

   if(StringFind(s, "ADAUSD") == 0)
      return "ADAUSD";

   if(StringFind(s, "DOGEUSD") == 0)
      return "DOGEUSD";

   if(StringFind(s, "AVAXUSD") == 0)
      return "AVAXUSD";

   if(StringFind(s, "DOTUSD") == 0)
      return "DOTUSD";

   if(StringFind(s, "LINKUSD") == 0)
      return "LINKUSD";

   // ---------------------------------------------------------------
   // USDT symbols
   // ---------------------------------------------------------------

   if(StringFind(s, "BTCUSDT") == 0)
      return "BTCUSDT";

   if(StringFind(s, "ETHUSDT") == 0)
      return "ETHUSDT";

   if(StringFind(s, "SOLUSDT") == 0)
      return "SOLUSDT";

   if(StringFind(s, "XRPUSDT") == 0)
      return "XRPUSDT";

   if(StringFind(s, "BNBUSDT") == 0)
      return "BNBUSDT";

   if(StringFind(s, "DOGEUSDT") == 0)
      return "DOGEUSDT";

   // ---------------------------------------------------------------
   // Not recognized
   // ---------------------------------------------------------------

   Print("WARNING: No Delta symbol mapping found for MT5 symbol: ",
         mt5_symbol);

   return "";
}

Then wherever you currently have:

string symbol = _Symbol;

use:

string mt5_symbol   = _Symbol;
string delta_symbol = GetDeltaSymbol(mt5_symbol);

if(delta_symbol == "")
{
   Print("ERROR: Cannot map MT5 symbol ", mt5_symbol,
         " to Delta Exchange.");
   return;
}
Print("MT5 Symbol: ", mt5_symbol,
      " -> Delta Symbol: ", delta_symbol);

So if your broker gives:

_Symbol = BTCUSD

you get:

MT5 Symbol: BTCUSD -> Delta Symbol: BTCUSD

And if the broker gives:

BTCUSDm

you get:

MT5 Symbol: BTCUSDm -> Delta Symbol: BTCUSD