CCXT-12-查询账本

1. 查询账本 - fetchLedger

有些交易所提供额外的访问点用于查询整合的账本历史。账本就是变化的历史,记录改变用户余额的操作,包括充值和提现等。 使用ccxt统一API中的fetchLedger方法查询账本,原型如下:

async fetchLedger (code = undefined, since = undefined, limit = undefined, params = {})

有些交易所不允许一次查询所有的账本条目,需要在调用fetchLedger 方法时指定code参数。

2. 账本记录结构

账本记录结构如下:

{
    'id': 'hqfl-f125f9l2c9',                // string id of the ledger entry, e.g. an order id
    'direction': 'out',                     // or 'in'
    'account': '06d4ab58-dfcd-468a',        // string id of the account if any
    'referenceId': 'bf7a-d4441fb3fd31',     // string id of the trade, transaction, etc...
    'referenceAccount': '3146-4286-bb71',   // string id of the opposite account (if any)
    'type': 'trade',                        // string, reference type, see below
    'currency': 'BTC',                      // string, unified currency code, 'ETH', 'USDT'...
    'amount': 123.45,                       // absolute number, float (does not include the fee)
    'timestamp': 1544582941735,             // milliseconds since epoch time in UTC
    'datetime': "2018-12-12T02:49:01.735Z", // string of timestamp, ISO8601
    'before': 0,                            // amount of currency on balance before
    'after': 0,                             // amount of currency on balance after
    'status': 'ok',                         // 'ok, 'pending', 'canceled'
    'fee': {                                // object or or undefined
        'cost': 54.321,                     // absolute number on top of the amount
        'currency': 'ETH',                  // string, unified currency code, 'ETH', 'USDT'...
    },
    'info': { ... },                        // raw ledger entry as is from the exchange
}

补充说明: 账本记录的类型就是与之关联的操作类型。如果amout来自委托单,那么关联的交易类型就是trade,同时referenceId字段的值记录交易ID。如果amount来自提现操作,那么这条记录关联的就是链上交易。可能值如下:

  • trade
  • transaction
  • fee
  • rebate
  • cashback
  • referral
  • transfer
  • whatever

referenceId字段表示引用ID,记录对应事件的ID。 status字段描述账本变化是成功(ok)、待定(pending)还是取消(ok)等状态。 大多数情况下都应该是ok。 type字段可以关联常规交易、链上交易(充值或提现操作)或交易所内部转账。 如果账本记录关联的是内部转账,那么account字段将包含该记录要修改的账户ID, referenceAccount字段的值则是相对方向的账户ID。