应部分用户需求,使用bithumb 的时候希望查询 某个ID 的订单信息, 封装了 交易所的这个接口 : https://api.bithumb.com/info/order_detail 只能查询完全成交的订单,其它状态的订单是查询不到的。
接口信息如下:
/*
https://api.bithumb.com/info/order_detail
order_id :
type : bid : Buy ask : sell
currency : Currency code ,Default : BTC
*/
function main() {
var id = exchange.Sell(-1, 0.01) // 下市价单 成交,因为 $.GetOrder 只能查询 完全成交的订单。
// 下限价单不成交的话,去查询这个ID ,会报错 Futures_OP 4: status: 5600, message: 거래 체결내역이 존재하지 않습니다. (在交易中不存在), ,意思是查询不到这个订单
Sleep(5000)
var order = $.GetOrder(exchange, id) // 传入交易所 Bithumb 的交易所对象, 传入ID ,查询不到 返回 null
Log(order)
}
function GetOrder(e, id, type){ /* https://api.bithumb.com/info/order_detail order_id : type : bid : Buy ask : sell currency : Currency code ,Default : BTC */ var symbol = e.GetCurrency() var arr = symbol.split("_") var currency = arr[0] var ret = e.IO("api", "POST", "/info/order_detail", "order_id=" + id + "&type=" + type + "¤cy=" + currency) // ret /* { "status":"0000", "data":[ { "order_currency":"BTC", "payment_currency":"KRW", "units_traded":"0.01", "price":"4322000", "cont_no":"32314118", "transaction_date":"1546054726834326", "type":"Buy", "fee":"64.83", "total":"43220" } ] } */ /* order 结构 { Id :交易单唯一标识 Price :下单价格 Amount :下单数量 DealAmount :成交数量 AvgPrice :成交均价, # 注意 ,有些交易所不提供该数据,不提供的设置为 0 。 Status :订单状态, 参考常量里的订单状态 Type :订单类型, 参考常量里的订单类型 } */ var order = null var typeValue = null if(type == "Buy"){ typeValue = ORDER_TYPE_BUY } else { typeValue = ORDER_TYPE_SELL } if(ret){ order = { Info : ret, // 原始信息 Id : id, // 交易单唯一标识 Price : ret.data[0].price, // 下单价格 Amount : ret.data[0].units_traded, // 下单数量 DealAmount: ret.data[0].units_traded, // 成交数量 AvgPrice : ret.data[0].price, // 成交均价, # 注意 ,有些交易所不提供该数据,不提供的设置为 0 。 Status : ORDER_STATE_CLOSED, // 订单状态, 参考常量里的订单状态 Type : typeValue, // 类型 } } return order } $.GetOrder = function(e, id, type){ if(e.GetName() != "Bithumb"){ Log("the parameter e is not bithumb!") return null } if(typeof(id) == "undefined"){ Log("id 参数错误!") return null } if(type == "Buy"){ GetOrder(e, id, type) } else if (type == "Sell") { GetOrder(e, id, type) } else { var buyOrder = GetOrder(e, id, "Buy") if(buyOrder){ return buyOrder } var sellOrder = GetOrder(e, id, "Sell") if(sellOrder){ return sellOrder } else { return null } } } function main() { var id = exchange.Sell(-1, 0.01) // 下市价单 成交,因为 $.GetOrder 只能查询 完全成交的订单。 // 下限价单不成交的话,去查询这个ID ,会报错 Futures_OP 4: status: 5600, message: 거래 체결내역이 존재하지 않습니다. (在交易中不存在), ,意思是查询不到这个订单 Sleep(5000) var order = $.GetOrder(exchange, id) // 传入交易所 Bithumb 的交易所对象, 传入ID ,查询不到 返回 null Log(order) }
Apexjo 你好:请问我怎么才能知道一笔订单目前处于的状态?是挂单中?撤单?还是完全成交?
andy77 这个接口 ,经过测试 ,只能返回一笔订单中 最后一次的交易记录? 比如 我下单 卖5个BTC,分了三次成交,那通过此接口只能返回 最后一次的成交记录? 是这样吗?
小小梦 这个不是 路径,就是 您代码 调用 : var order = $.GetOrder(exchange, 订单ID) 要打印 所有 原始信息,就调用 Log("订单原始信息:", order.Info)
andy77 请问这个 order.Info 的完整路径是?
小小梦 ``` var order = $.GetOrder(exchange, id) Log(order.Info) ``` 这个 order.Info 里面有你所有的订单,你看下。如果 没有那就是 交易所接口的问题了。这个 order.Info 是 访问这个查询订单接口,交易所返回的原始信息。
andy77 我传入的ID 是1553066625577400, 这笔订单 一共分了二次成交,这样没有错吧。为什么我通过order_detail接口查询 只返回了二次成交中的一笔? 这样说能明白?
小小梦 然后你的问题是为什么查询不到所有订单?原因是你传入什么ID 查询哪个ID 的订单。 ``` {"status":"0000","order_id":"1553066625577400","data":[{"cont_id":"453427","units":"206.1855","price":4.85,"total":1000,"fee":"1.5"},{"cont_id":"453428","units":"1890.664500000000000000","price":4.85,"total":9170,"fee":"13.75"}]} ``` 这些 和你要查询的订单有什么关系?
andy77 上面那个接口 是下单接口同步返回的。
小小梦 不太明白您意思。 ``` {"status":"0000","order_id":"1553066625577400","data":[{"cont_id":"453427","units":"206.1855","price":4.85,"total":1000,"fee":"1.5"},{"cont_id":"453428","units":"1890.664500000000000000","price":4.85,"total":9170,"fee":"13.75"}]} ``` 您上面的这个信息是什么接口返回的? 不是https://api.bithumb.com/info/order_detail 查询返回的吧。
andy77 嗯。 ID 是订单号(order_id) ,在一个ID里 还有几个 cont_id, 比如 这笔订单 {"status":"0000","order_id":"1553066625577400","data":[{"cont_id":"453427","units":"206.1855","price":4.85,"total":1000,"fee":"1.5"},{"cont_id":"453428","units":"1890.664500000000000000","price":4.85,"total":9170,"fee":"13.75"}]} 下单时就同步返回了,一共分二笔成交, 但是我再用order_detail 接口去查询 只返回 {"status":"0000","data":[{"cont_no":"453428","transaction_date":"1553066625607856","type":"ask","order_currency":"TMTG","payment_currency":"KRW","units_traded":"1890.66450000","price":"4.85","fee":"13.75","total":"9170"}]} 最后一笔的成交记录
小小梦 这个是根据ID 查询的, 您输入 哪个订单的ID , 就查询那个订单。
andy77 经测试 ,我这5个BTC 都完全成交了,但是只返回了 最后一次成交的信息? 前面二次成交记录 已经查不到了
小小梦 不是,这个根据订单ID 查询的,但是交易所 不维护 完全成交 之外的订单信息,就是 说,只能查询到完全成交的订单。挂单 和 撤销的都是查询不到的。