Javascript Bitfinex REST API:如何在激活前检查活动订单,然后在一个脚本中执行或取消后检查历史订单?
我希望在订单执行后获取订单信息,但当我查找活动订单时,订单处于活动状态,但当我在exchange上取消订单时,脚本将与历史订单列表一起退出,而不是与最近的订单列表一起退出。如果我再次运行脚本并在历史订单中查找最近的order.id,那么我会看到它被取消。如何在一张支票中完成Javascript Bitfinex REST API:如何在激活前检查活动订单,然后在一个脚本中执行或取消后检查历史订单?,javascript,node.js,rest,api,orders,Javascript,Node.js,Rest,Api,Orders,我希望在订单执行后获取订单信息,但当我查找活动订单时,订单处于活动状态,但当我在exchange上取消订单时,脚本将与历史订单列表一起退出,而不是与最近的订单列表一起退出。如果我再次运行脚本并在历史订单中查找最近的order.id,那么我会看到它被取消。如何在一张支票中完成 const bitfinexHistoricalOrders = new RESTv2(userConfig.bitfinex.h_orders) const bitfinexActiveOrders = new RESTv
const bitfinexHistoricalOrders = new RESTv2(userConfig.bitfinex.h_orders)
const bitfinexActiveOrders = new RESTv2(userConfig.bitfinex.a_orders)
const bitfinexBuy = new RESTv2(userConfig.bitfinex.buy)
const START = Date.now() - (24 * 60 * 60 * 1000 * 1000) // 1 day
let pair = 'BTCUSD'
let orderID = 35448795794
function CheckBitfinexOrderManual(pair, orderID) {
bitfinexActiveOrders.activeOrders().then(orders => {
if (orders.length > 0) {
for (const o of orders) {
console.log(o.id, o.status)
if (o.status === 'ACTIVE' && o.id === orderID) {
log(logSymbols.warning, chalk.gray(`${chalk.green('Bitfinex')} manual order ${o.id} not yet filled`))
}
}
} else if (!orders.length) {
CheckBitfinexOrderManualH(pair, orderID)
}
}).catch(err => {
console.log(`${chalk.green('Bitfinex')} error of manual Active Orders: ${err}`)
return
})
}
function CheckBitfinexOrderManualH(pair, orderID) {
bitfinexHistoricalOrders.orderHistory(`t${pair}`, START, END, 10, (error, history) => {
for (const h of history) {
console.log(h.id, h.amountOrig, h.status)
if (h.id === orderID && h.status.includes('EXECUTED')) {
log(logSymbols.success, chalk.gray(`${chalk.green('Bitfinex')} manual LIMIT order ${h.id} filled`))
return
} else if (h.id === orderID && h.status.includes('PARTIALLY FILLED')) {
log(logSymbols.success, chalk.gray(`${chalk.green('Bitfinex')} manual LIMIT order ${h.id} partially filled`))
return
} else if (h.id === orderID && h.status.includes('CANCELED')) {
log(logSymbols.success, chalk.gray(`${chalk.green('Bitfinex')} manual LIMIT order ${h.id} canceled`))
return
}
}
}).catch((err) => {
log(logSymbols.error, `${chalk.green('Bitfinex')} check manual LIMIT order API error ${err}`)
return
})
}
const buy = new Order({
cid: Date.now(),
type: Order.type.EXCHANGE_LIMIT, //EXCHANGE_FOK,
symbol: `tBTCUSD`,
amount: 0.01,
price: 6500,
tif: moment().add(30, 'minutes').format('YYYY-MM-DD HH:mm:ss') //TimeInForce 30 minutes
}, bitfinexBuy)
buy.submit().then(() => {
log(logSymbols.success, chalk.grey(`${chalk.green('Bitfinex')} manual buy LIMIT order ${buy.id} set.`))
orderID = buy.id
setTimeout(CheckBitfinexOrderManual, 10000, pair, buy.id)
setTimeout(CheckBitfinexOrderManualH, 10000, pair, buy.id)
}).catch((err) => {
log(logSymbols.error, `${chalk.green('Bitfinex')} manual buy LIMIT error ${err.message}`)
return
})
Binance Allorder在一个活动订单和另一个订单中包含所有内容。它们没有一个端点可以同时提供活动订单和历史订单,但您可以使用WebSocket跟踪订单。通过WebSocket连接,当您打开连接时,您可以获得未结订单的快照,并在任何更改时进行更新:我在询问REST方法以及为什么我的脚本无法实现我的意图。。。