Bitfinex REST API:如何检查活动订单直到有效,然后在一个脚本中执行或取消后检查历史订单?

问题描述 投票:0回答:1

我想在订单执行后获取订单信息,但是当我寻找有效的订单时,该订单是活动的,但是当我取消交换订单时,脚本将退出历史订单列表,而不是最近的订单列表。如果我再次运行脚本并以历史顺序查找最近的order.id,那么我将其取消。一口气怎么做?

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 allOrders将所有事物合而为一(活动和其他)。

javascript node.js rest api orders
1个回答
0
投票

他们没有可以为您提供活动和历史订单的端点,但是您可以使用WebSocket跟踪您的订单。使用WebSocket连接,您可以在打开连接时获得未结订单的快照,并在发生任何更改时进行更新:https://docs.bitfinex.com/reference#ws-auth-orders

© www.soinside.com 2019 - 2024. All rights reserved.