MCPcopy Create free account
hub / github.com/ccxt/ccxt / fetchLedger

Method fetchLedger

ts/src/xt.ts:3670–3721  ·  view source on GitHub ↗

* @method * @name xt#fetchLedger * @description fetch the history of changes, actions done by the user or operations that altered the balance of the user * @see https://doc.xt.com/#futures_usergetBalanceBill * @param {string} [code] unified currency code * @param {int} [sinc

(code: Str = undefined, since: Int = undefined, limit: Int = undefined, params = {})

Source from the content-addressed store, hash-verified

3668 * @returns {object} a [ledger structure]{@link https://docs.ccxt.com/en/latest/manual.html#ledger-structure}
3669 */
3670 async fetchLedger (code: Str = undefined, since: Int = undefined, limit: Int = undefined, params = {}): Promise<LedgerEntry[]> {
3671 await this.loadMarkets ();
3672 const request = {};
3673 let currency: Currency = undefined;
3674 if (code !== undefined) {
3675 currency = this.currency (code);
3676 }
3677 if (since !== undefined) {
3678 request['startTime'] = since;
3679 }
3680 if (limit !== undefined) {
3681 request['limit'] = limit;
3682 }
3683 let type: Str = undefined;
3684 let subType: SubType = undefined;
3685 let response = undefined;
3686 [ type, params ] = this.handleMarketTypeAndParams ('fetchLedger', undefined, params);
3687 [ subType, params ] = this.handleSubTypeAndParams ('fetchLedger', undefined, params);
3688 if (subType === 'inverse') {
3689 response = await this.privateInverseGetFutureUserV1BalanceBills (this.extend (request, params));
3690 } else if ((subType === 'linear') || (type === 'swap') || (type === 'future')) {
3691 response = await this.privateLinearGetFutureUserV1BalanceBills (this.extend (request, params));
3692 } else {
3693 throw new NotSupported (this.id + ' fetchLedger() does not support spot transactions, only swap and future wallet transactions are supported');
3694 }
3695 //
3696 // {
3697 // "returnCode": 0,
3698 // "msgInfo": "success",
3699 // "error": null,
3700 // "result": {
3701 // "hasPrev": false,
3702 // "hasNext": false,
3703 // "items": [
3704 // {
3705 // "id": "207260567109387525",
3706 // "coin": "usdt",
3707 // "symbol": "btc_usdt",
3708 // "type": "FEE",
3709 // "amount": "-0.0213",
3710 // "side": "SUB",
3711 // "afterAmount": null,
3712 // "createdTime": 1679116769914
3713 // },
3714 // ]
3715 // }
3716 // }
3717 //
3718 const data = this.safeValue (response, 'result', {});
3719 const ledger = this.safeValue (data, 'items', []);
3720 return this.parseLedger (ledger, currency, since, limit);
3721 }
3722
3723 parseLedgerEntry (item, currency: Currency = undefined): LedgerEntry {
3724 //

Callers 2

Calls 9

loadMarketsMethod · 0.45
currencyMethod · 0.45
extendMethod · 0.45
safeValueMethod · 0.45
parseLedgerMethod · 0.45

Tested by

no test coverage detected