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

Method parseLedgerEntry

ts/src/luno.ts:1298–1350  ·  view source on GitHub ↗
(entry, currency: Currency = undefined)

Source from the content-addressed store, hash-verified

1296 }
1297
1298 parseLedgerEntry (entry, currency: Currency = undefined): LedgerEntry {
1299 // const details = this.safeValue (entry, 'details', {});
1300 const id = this.safeString (entry, 'row_index');
1301 const account_id = this.safeString (entry, 'account_id');
1302 const timestamp = this.safeInteger (entry, 'timestamp');
1303 const currencyId = this.safeString (entry, 'currency');
1304 const code = this.safeCurrencyCode (currencyId, currency);
1305 currency = this.safeCurrency (currencyId, currency);
1306 const available_delta = this.safeString (entry, 'available_delta');
1307 const balance_delta = this.safeString (entry, 'balance_delta');
1308 const after = this.safeString (entry, 'balance');
1309 const comment = this.safeString (entry, 'description');
1310 let before = after;
1311 let amount = '0.0';
1312 const result = this.parseLedgerComment (comment);
1313 const type = result['type'];
1314 const referenceId = result['referenceId'];
1315 let direction: Str = undefined;
1316 let status: Str = undefined;
1317 if (!Precise.stringEquals (balance_delta, '0.0')) {
1318 before = Precise.stringSub (after, balance_delta);
1319 status = 'ok';
1320 amount = Precise.stringAbs (balance_delta);
1321 } else if (Precise.stringLt (available_delta, '0.0')) {
1322 status = 'pending';
1323 amount = Precise.stringAbs (available_delta);
1324 } else if (Precise.stringGt (available_delta, '0.0')) {
1325 status = 'canceled';
1326 amount = Precise.stringAbs (available_delta);
1327 }
1328 if (Precise.stringGt (balance_delta, '0') || Precise.stringGt (available_delta, '0')) {
1329 direction = 'in';
1330 } else if (Precise.stringLt (balance_delta, '0') || Precise.stringLt (available_delta, '0')) {
1331 direction = 'out';
1332 }
1333 return this.safeLedgerEntry ({
1334 'info': entry,
1335 'id': id,
1336 'direction': direction,
1337 'account': account_id,
1338 'referenceId': referenceId,
1339 'referenceAccount': undefined,
1340 'type': type,
1341 'currency': code,
1342 'amount': this.parseToNumeric (amount),
1343 'timestamp': timestamp,
1344 'datetime': this.iso8601 (timestamp),
1345 'before': this.parseToNumeric (before),
1346 'after': this.parseToNumeric (after),
1347 'status': status,
1348 'fee': undefined,
1349 }, currency) as LedgerEntry;
1350 }
1351
1352 /**
1353 * @method

Callers

nothing calls this directly

Calls 13

parseLedgerCommentMethod · 0.95
safeStringMethod · 0.45
safeIntegerMethod · 0.45
safeCurrencyCodeMethod · 0.45
safeCurrencyMethod · 0.45
stringEqualsMethod · 0.45
stringSubMethod · 0.45
stringAbsMethod · 0.45
stringLtMethod · 0.45
stringGtMethod · 0.45
safeLedgerEntryMethod · 0.45
parseToNumericMethod · 0.45

Tested by

no test coverage detected