OKEx V5 Gets All Unfilled Orders
JavaScript strategy by 夏天不打你.
JavaScriptOther
The original spec has no written description. Read the source below.
Source JavaScript
function getAllPendingOrdersInOkex(num) {
var pending_orders = [];
// Limit order
var param = "instType=SWAP";
var ret = exchanges[num].IO("api", "GET", "/api/v5/trade/orders-pending", param);
// take profit and stop loss order
param = "instType=SWAP" + "&ordType=oco,conditional";
var ret2 = exchanges[num].IO("api", "GET", "/api/v5/trade/orders-algo-pending", param);
if (!ret) {
Log(exchanges[num].GetLabel(), ":Failed to get limit order!", "@");
return null;
}
if (!ret2) {
Log(exchanges[num].GetLabel(), ":Failed to fetch take-profit/stop-loss order!", "@");
return null;
}
for (let i = 0; i < ret.data.length; i++) {
let type = "";
if (ret.data[i].posSide == "long") {
type = ret.data[i].side == "buy" ? "Limit order to open long: Limit order to close long";
} else if (ret.data[i].posSide == "short") {
type = ret.data[i].side == "sell" ? "Limit order to open short: Limit order to close short";
} else {
type = "Order Type Error";
}
let symbol = ret.data[i].instId.replace("-USDT-SWAP", "") + "_USDT";
pending_orders.push({
OrderId: ret.data[i].ordId,
Symbol: symbol,
Price: Number(ret.data[i].px),
Amount: Number(ret.data[i].sz),
DealAmount: Number(ret.data[i].accFillSz),
Type: type,
StopPrice: 0,
TakeProfitPrice: 0,
Time: ret.data[i].uTime,
});
}
for (let i = 0; i < ret2.data.length; i++) {
let type = "";
let stop_price = 0;
let take_profit_price = 0;
if (ret2.data[i].slTriggerPx && ret2.data[i].tpTriggerPx) {
type = ret2.data[i].posSide == "long" ? "Long position take profit and stop loss : Short position take profit and stop loss";
stop_price = Number(ret2.data[i].slTriggerPx);
take_profit_price = Number(ret2.data[i].tpTriggerPx);
} else if (ret2.data[i].slTriggerPx) {
type = ret2.data[i].posSide == "long" ? "Long position stop loss: Short position stop loss";
stop_price = Number(ret2.data[i].slTriggerPx);
} else if (ret2.data[i].tpTriggerPx) {
type = ret2.data[i].posSide == "long" ? "Long position take profit: Short position take profit";
take_profit_price = Number(ret2.data[i].tpTriggerPx);
} else {
type = "Order Type Error";
}
let symbol = ret2.data[i].instId.replace("-USDT-SWAP", "") + "_USDT";
pending_orders.push({
OrderId: ret2.data[i].algoId,
Symbol: symbol,
Price: 0,
Amount: Number(ret2.data[i].sz),
DealAmount: 0,
Type: type,
StopPrice: stop_price,
TakeProfitPrice: take_profit_price,
Time: ret2.data[i].cTime,
});
}
return pending_orders;
}
function main() {
getAllPendingOrdersInOkex(0);
}Published by 夏天不打你 on the FMZ strategy square · last modified 2022-01-14. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.
Build this with AgenKit
A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/OKEx-V5-Gets-All-Unfilled-Orders.md- npx agenkit install engineering-kit in your project
- Paste the command into your agent and approve each phase
- Get tests, backtest, risk controls and a paper-trading switch
Understand it first
Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.