def parse_transaction(self, transaction, currency=None): # # withdraw # # { # id: '1', # address: '1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2', # amount: '0.01', # state: 'pending', # currency: 'BTC', # withdrawal_fee: '0.0007', # created_at: '1626000533', # updated_at: '1626000533', # payment_id: null, # transaction_hash: null, # broadcasted_at: null, # wallet_label: null, # chain_name: 'Bitcoin', # network: null # }, # # fetchWithdrawals # # { # id: '2', # address: '1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2', # amount: '0.01', # state: 'processed', # currency: 'BTC', # withdrawal_fee: '0.0005', # created_at: '1614718276', # updated_at: '1614720926', # payment_id: '', # transaction_hash: 'xxxxxxxx...', # broadcasted_at: '1614720762', # wallet_label: 'btc', # chain_name: 'Bitcoin', # network: null # }, # # fetchDeposits # # ... # id = self.safe_string(transaction, 'id') address = self.safe_string(transaction, 'address') tag = self.safe_string_2(transaction, 'payment_id', 'memo_value') txid = self.safe_string(transaction, 'transaction_hash') currencyId = self.safe_string_2(transaction, 'currency', 'asset') code = self.safe_currency_code(currencyId, currency) timestamp = self.safe_timestamp(transaction, 'created_at') updated = self.safe_timestamp(transaction, 'updated_at') type = 'withdrawal' status = self.parse_transaction_status(self.safe_string(transaction, 'state')) amountString = self.safe_string(transaction, 'amount') feeCostString = self.safe_string(transaction, 'withdrawal_fee') amount = self.parse_number(Precise.string_sub(amountString, feeCostString)) network = self.safe_string(transaction, 'chain_name') return { 'info': transaction, 'id': id, 'txid': txid, 'timestamp': timestamp, 'datetime': self.iso8601(timestamp), 'network': network, 'address': address, 'addressTo': None, 'addressFrom': None, 'tag': tag, 'tagTo': None, 'tagFrom': None, 'type': type, 'amount': amount, 'currency': code, 'status': status, 'updated': updated, 'fee': { 'currency': code, 'cost': self.parse_number(feeCostString), }, }
# decimal_to_precision('foo'), # "invalid number(contains an illegal character 'f')") # # throws(() => # decimal_to_precision('0.01', TRUNCATE, -1, TICK_SIZE), # "TICK_SIZE cant be used with negative numPrecisionDigits") # ---------------------------------------------------------------------------- w = '-1.123e-6' x = '0.00000002' y = '69696900000' assert Precise.string_mul(x, y) == '1393.938' assert Precise.string_mul(y, x) == '1393.938' assert Precise.string_add(x, y) == '69696900000.00000002' assert Precise.string_add(y, x) == '69696900000.00000002' assert Precise.string_sub(x, y) == '-69696899999.99999998' assert Precise.string_sub(y, x) == '69696899999.99999998' assert Precise.string_div(x, y) == '0.000000000000028695' assert Precise.string_div(y, x) == '34848450000' assert Precise.string_mul(x, w) == '-0.00000000000002246' assert Precise.string_mul(w, x) == '-0.00000000000002246' assert Precise.string_add(x, w) == '-0.000001103' assert Precise.string_add(w, x) == '-0.000001103' assert Precise.string_sub(x, w) == '0.000001143' assert Precise.string_sub(w, x) == '-0.000001143' assert Precise.string_div(x, w) == '-0.000000000017809439' assert Precise.string_div(w, x) == '-0.0000005615'
def parse_ledger_entry(self, item, currency=None): # { # id: '12087495079', # amount: '-0.0100000000000000', # balance: '0.0645419900000000', # created_at: '2021-10-28T17:14:32.593168Z', # type: 'transfer', # details: { # from: '2f74edf7-1440-4586-86dc-ae58c5693691', # profile_transfer_id: '3ef093ad-2482-40d1-8ede-2f89cff5099e', # to: 'dda99503-4980-4b60-9549-0b770ee51336' # } # }, # { # id: '11740725774', # amount: '-1.7565669701255000', # balance: '0.0016490047745000', # created_at: '2021-10-22T03:47:34.764122Z', # type: 'fee', # details: { # order_id: 'ad06abf4-95ab-432a-a1d8-059ef572e296', # product_id: 'ETH-DAI', # trade_id: '1740617' # } # } id = self.safe_string(item, 'id') amountString = self.safe_string(item, 'amount') direction = None afterString = self.safe_string(item, 'balance') beforeString = Precise.string_sub(afterString, amountString) if Precise.string_lt(amountString, '0'): direction = 'out' amountString = Precise.string_abs(amountString) else: direction = 'in' amount = self.parse_number(amountString) after = self.parse_number(afterString) before = self.parse_number(beforeString) timestamp = self.parse8601(self.safe_value(item, 'created_at')) type = self.parse_ledger_entry_type(self.safe_string(item, 'type')) code = self.safe_currency_code(None, currency) details = self.safe_value(item, 'details', {}) account = None referenceAccount = None referenceId = None if type == 'transfer': account = self.safe_string(details, 'from') referenceAccount = self.safe_string(details, 'to') referenceId = self.safe_string(details, 'profile_transfer_id') else: referenceId = self.safe_string(details, 'order_id') status = 'ok' return { 'id': id, 'currency': code, 'account': account, 'referenceAccount': referenceAccount, 'referenceId': referenceId, 'status': status, 'amount': amount, 'before': before, 'after': after, 'fee': None, 'direction': direction, 'timestamp': timestamp, 'datetime': self.iso8601(timestamp), 'type': type, 'info': item, }