Delta Exchange Library API Sample Script

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

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

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.");
}