```exchange.GetOrders()```函数请求数据成功时返回{@struct/Order Order}结构数组,请求数据失败时返回空值。
{@struct/Order Order}数组、空值
exchange.GetOrders()
exchange.GetOrders(symbol)
参数```symbol```用于设置所要查询的**交易品种**或者**交易品种的范围**。
对于现货交易所对象,不传```symbol```参数时,请求所有现货品种的未完成订单数据。
对于期货交易所对象,不传```symbol```参数时,默认以当前交易对、合约代码所在维度范围请求所有品种的未完成订单数据。
symbol
false
string
```javascript
/*backtest
start: 2024-05-21 00:00:00
end: 2024-09-05 00:00:00
period: 5m
basePeriod: 1m
exchanges: [{"eid":"Binance","currency":"BTC_USDT"}]
*/
function main() {
var arrSymbol = ["ETH_USDT", "BTC_USDT", "LTC_USDT", "SOL_USDT"]
for (var symbol of arrSymbol) {
var t = exchange.GetTicker(symbol)
exchange.CreateOrder(symbol, "buy", t.Last / 2, 0.01)
}
var spotOrders = exchange.GetOrders()
var tbls = []
for (var orders of [spotOrders]) {
var tbl = {type: "table", title: "test GetOrders", cols: ["Symbol", "Id", "Price", "Amount", "DealAmount", "AvgPrice", "Status", "Type", "Offset", "ContractType"], rows: []}
for (var order of orders) {
tbl.rows.push([order.Symbol, order.Id, order.Price, order.Amount, order.DealAmount, order.AvgPrice, order.Status, order.Type, order.Offset, order.ContractType])
}
tbls.push(tbl)
}
LogStatus("`" + JSON.stringify(tbls) + "`")
// 打印输出一次信息后返回,防止后续回测时订单成交,影响数据观察
return
}
'''backtest
start: 2024-05-21 00:00:00
end: 2024-09-05 00:00:00
period: 5m
basePeriod: 1m
exchanges: [{"eid":"Binance","currency":"BTC_USDT"}]
'''
import json
def main():
arrSymbol = ["ETH_USDT", "BTC_USDT", "LTC_USDT", "SOL_USDT"]
for symbol in arrSymbol:
t = exchange.GetTicker(symbol)
exchange.CreateOrder(symbol, "buy", t["Last"] / 2, 0.01)
spotOrders = exchange.GetOrders()
tbls = []
for orders in [spotOrders]:
tbl = {"type": "table", "title": "test GetOrders", "cols": ["Symbol", "Id", "Price", "Amount", "DealAmount", "AvgPrice", "Status", "Type", "Offset", "ContractType"], "rows": []}
for order in orders:
tbl["rows"].append([order.Symbol, order.Id, order.Price, order.Amount, order.DealAmount, order.AvgPrice, order.Status, order.Type, order.Offset, order.ContractType])
tbls.append(tbl)
LogStatus("`" + json.dumps(tbls) + "`")
return
/*backtest
start: 2024-05-21 00:00:00
end: 2024-09-05 00:00:00
period: 5m
basePeriod: 1m
exchanges: [{"eid":"Binance","currency":"BTC_USDT"}]
*/
void main() {
auto arrSymbol = {"ETH_USDT", "BTC_USDT", "LTC_USDT", "SOL_USDT"};
for (const auto& symbol : arrSymbol) {
auto t = exchange.GetTicker(symbol);
exchange.CreateOrder(symbol, "buy", t.Last / 2, 0.01);
}
auto spotOrders = exchange.GetOrders();
json tbls = R"([])"_json;
std::vector<std::vector<Order>> arr = {spotOrders};
for (const auto& orders : arr) {
json tbl = R"({
"type": "table",
"title": "test GetOrders",
"cols": ["Symbol", "Id", "Price", "Amount", "DealAmount", "AvgPrice", "Status", "Type", "Offset", "ContractType"],
"rows": []
})"_json;
for (const auto& order : orders) {
json arrJson = R"([])"_json;
arrJson.push_back("Symbol");
arrJson.push_back("Id");
arrJson.push_back(order.Price);
arrJson.push_back(order.Amount);
arrJson.push_back(order.DealAmount);
arrJson.push_back(order.AvgPrice);
arrJson.push_back(order.Status);
arrJson.push_back(order.Type);
arrJson.push_back(order.Offset);
arrJson.push_back(order.ContractType);
tbl["rows"].push_back(arrJson);
}
tbls.push_back(tbl);
}
LogStatus(_D(), "\n", "`" + tbls.dump() + "`");
return;
}
使用现货交易所对象,对多个不同交易对,以当前价格的一半作为下单价下买单,然后查询未完成订单信息。
/*backtest
start: 2024-05-21 00:00:00
end: 2024-09-05 00:00:00
period: 5m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
function main() {
var arrSymbol = ["BTC_USDT.swap", "BTC_USDT.quarter", "ETH_USDT.swap", "ETH_USDT.quarter"]
for (var symbol of arrSymbol) {
var t = exchange.GetTicker(symbol)
exchange.CreateOrder(symbol, "buy", t.Last / 2, 1)
exchange.CreateOrder(symbol, "sell", t.Last * 2, 1)
}
var defaultOrders = exchange.GetOrders()
var swapOrders = exchange.GetOrders("USDT.swap")
var futuresOrders = exchange.GetOrders("USDT.futures")
var btcUsdtSwapOrders = exchange.GetOrders("BTC_USDT.swap")
var tbls = []
var arr = [defaultOrders, swapOrders, futuresOrders, btcUsdtSwapOrders]
var tblDesc = ["defaultOrders", "swapOrders", "futuresOrders", "btcUsdtSwapOrders"]
for (var index in arr) {
var orders = arr[index]
var tbl = {type: "table", title: tblDesc[index], cols: ["Symbol", "Id", "Price", "Amount", "DealAmount", "AvgPrice", "Status", "Type", "Offset", "ContractType"], rows: []}
for (var order of orders) {
tbl.rows.push([order.Symbol, order.Id, order.Price, order.Amount, order.DealAmount, order.AvgPrice, order.Status, order.Type, order.Offset, order.ContractType])
}
tbls.push(tbl)
}
LogStatus("`" + JSON.stringify(tbls) + "`")
// 打印输出一次信息后返回,防止后续回测时订单成交,影响数据观察
return
}
'''backtest
start: 2024-05-21 00:00:00
end: 2024-09-05 00:00:00
period: 5m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
'''
import json
def main():
arrSymbol = ["BTC_USDT.swap", "BTC_USDT.quarter", "ETH_USDT.swap", "ETH_USDT.quarter"]
for symbol in arrSymbol:
t = exchange.GetTicker(symbol)
exchange.CreateOrder(symbol, "buy", t["Last"] / 2, 1)
exchange.CreateOrder(symbol, "sell", t["Last"] * 2, 1)
defaultOrders = exchange.GetOrders()
swapOrders = exchange.GetOrders("USDT.swap")
futuresOrders = exchange.GetOrders("USDT.futures")
btcUsdtSwapOrders = exchange.GetOrders("BTC_USDT.swap")
tbls = []
arr = [defaultOrders, swapOrders, futuresOrders, btcUsdtSwapOrders]
tblDesc = ["defaultOrders", "swapOrders", "futuresOrders", "btcUsdtSwapOrders"]
for index in range(len(arr)):
orders = arr[index]
tbl = {"type": "table", "title": tblDesc[index], "cols": ["Symbol", "Id", "Price", "Amount", "DealAmount", "AvgPrice", "Status", "Type", "Offset", "ContractType"], "rows": []}
for order in orders:
tbl["rows"].append([order["Symbol"], order["Id"], order["Price"], order["Amount"], order["DealAmount"], order["AvgPrice"], order["Status"], order["Type"], order["Offset"], order["ContractType"]])
tbls.append(tbl)
LogStatus("`" + json.dumps(tbls) + "`")
return
/*backtest
start: 2024-05-21 00:00:00
end: 2024-09-05 00:00:00
period: 5m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
void main() {
auto arrSymbol = {"BTC_USDT.swap", "BTC_USDT.quarter", "ETH_USDT.swap", "ETH_USDT.quarter"};
for (const auto& symbol : arrSymbol) {
auto t = exchange.GetTicker(symbol);
exchange.CreateOrder(symbol, "buy", t.Last / 2, 1);
exchange.CreateOrder(symbol, "sell", t.Last * 2, 1);
}
auto defaultOrders = exchange.GetOrders();
auto swapOrders = exchange.GetOrders("USDT.swap");
auto futuresOrders = exchange.GetOrders("USDT.futures");
auto btcUsdtSwapOrders = exchange.GetOrders("BTC_USDT.swap");
json tbls = R"([])"_json;
std::vector<std::vector<Order>> arr = {defaultOrders, swapOrders, futuresOrders, btcUsdtSwapOrders};
std::string tblDesc[] = {"defaultOrders", "swapOrders", "futuresOrders", "btcUsdtSwapOrders"};
for (int index = 0; index < arr.size(); index++) {
auto orders = arr[index];
json tbl = R"({
"type": "table",
"cols": ["Symbol", "Id", "Price", "Amount", "DealAmount", "AvgPrice", "Status", "Type", "Offset", "ContractType"],
"rows": []
})"_json;
tbl["title"] = tblDesc[index];
for (const auto& order : orders) {
json arrJson = R"([])"_json;
arrJson.push_back(order.Symbol);
arrJson.push_back(to_string(order.Id)); // Order订单结构中的Id属性类型为TId,使用FMZ平台内置的一个C++函数to_string编码
arrJson.push_back(order.Price);
arrJson.push_back(order.Amount);
arrJson.push_back(order.DealAmount);
arrJson.push_back(order.AvgPrice);
arrJson.push_back(order.Status);
arrJson.push_back(order.Type);
arrJson.push_back(order.Offset);
arrJson.push_back(order.ContractType);
tbl["rows"].push_back(arrJson);
}
tbls.push_back(tbl);
}
LogStatus(_D(), "\n", "`" + tbls.dump() + "`");
return;
}
使用期货交易所对象,对多个不同交易对、合约代码的品种下单。下单价格远离盘口对手价,保持订单处于未成交状态,按多种方式查询订单。
function main() {
var orders = exchange.GetOrders("BTC_USDT") // 现货品种举例
// var orders = exchange.GetOrders("BTC_USDT.swap") // 期货品种举例
Log("orders:", orders)
}
def main():
orders = exchange.GetOrders("BTC_USDT") # 现货品种举例
# orders = exchange.GetOrders("BTC_USDT.swap") # 期货品种举例
Log("orders:", orders)
void main() {
auto orders = exchange.GetOrders("BTC_USDT"); // 现货品种举例
// auto orders = exchange.GetOrders("BTC_USDT.swap"); // 期货品种举例
Log("orders:", orders);
}
调用exchange.GetOrders()
函数时传入Symbol
参数指定请求具体交易对、合约代码的订单数据。
在GetOrders
函数中,symbol参数的使用场景归纳:
交易所对象分类 | symbol参数 | 查询范围 | 备注 |
---|---|---|---|
现货 | 不传symbol参数 | 查询所有现货交易对 | 所有调用场景,如果交易所接口不支持则报错返回空值,不再赘述 |
现货 | 指定交易品种,symbol参数为:”BTC_USDT” | 查询指定的BTC_USDT交易对 | 对于现货交易所对象,参数symbol格式为:”BTC_USDT” |
期货 | 不传symbol参数 | 查询当前交易对、合约代码维度范围的所有交易品种 | 假如当前交易对为BTC_USDT,合约代码为swap,即查询所有的USDT本位永续合约。等价于调用GetOrders("USDT.swap") |
期货 | 指定交易品种,symbol参数为:”BTC_USDT.swap” | 查询指定的BTC的USDT本位永续合约 | 对于期货交易所对象,参数symbol格式为:FMZ平台定义的交易对与合约代码组合,以字符"." 间隔。 |
期货 | 指定交易品种范围,symbol参数为:”USDT.swap” | 查询所有USDT本位永续合约 | - |
支持期权的期货交易所 | 不传symbol参数 | 查询当前交易对维度范围的所有期权合约 | 假如当前交易对为BTC_USDT,合约设置为期权合约,例如币安期权合约:BTC-240108-40000-C |
支持期权的期货交易所 | 指定具体交易品种 | 查询指定的期权合约 | 例如对于币安期货交易所,symbol参数:BTC_USDT.BTC-240108-40000-C |
支持期权的期货交易所 | 指定交易品种范围,symbol参数为:”USDT.option” | 查询所有USDT本位期权合约 | - |
在GetOrders
函数中,期货交易所对象查询维度范围归纳:
symbol参数 | 请求范围定义 | 备注 |
---|---|---|
USDT.swap | USDT本位永续合约范围。 | 对于交易所API接口不支持的维度,调用时会报错返回空值。 |
USDT.futures | USDT本位交割合约范围。 | - |
USD.swap | 币本位永续合约范围。 | - |
USD.futures | 币本位交割合约范围。 | - |
USDT.option | USDT本位期权合约范围。 | - |
USD.option | 币本位期权合约范围。 | - |
USDT.futures_combo | 差价组合合约范围。 | Futures_Deribit交易所 |
USD.futures_ff | 混合保证金交割合约范围。 | Futures_Kraken交易所 |
USD.swap_pf | 混合保证金永续合约范围。 | Futures_Kraken交易所 |
当交易所对象exchange
代表的账户在查询范围内或指定的交易品种没有挂单时(处于未成交状态的活动订单),调用该函数返回空数组,即:[]
。
以下交易所查询当前未完成订单的接口必须传入品种参数,使用这些交易所调用GetOrders函数,没有传入symbol参数时只请求当前品种的未完成订单,并非所有品种的未完成订单(因为交易所接口不支持)。
Zaif, MEXC, LBank, Korbit, Coinw, BitMart, Bithumb, BitFlyer, BigONE.
不支持exchange.GetOrders()
函数的交易所:
函数名 | 不支持的现货交易所 | 不支持的期货交易所 |
---|---|---|
GetOrders | – | Futures_Bibox |
{@struct/Order Order}, {@fun/Trade/exchange.GetOrder exchange.GetOrder}, {@fun/Trade/exchange.GetHistoryOrders exchange.GetHistoryOrders}
exchange.GetOrder exchange.GetHistoryOrders