def get_withdrawal_history(self, currency): if not isinstance(currency, symbol.Currency): raise NotValidCurrency() result = [] try: r = self.apiclient.getwithdrawalhistory(currency, 10) except Exception: raise ExchangeConnectionException() if r['success'] is True: data = r['result'] for d in data: try: d['Opened'] = datetime.strptime(d['Opened'], '%Y-%m-%dT%H:%M:%S.%f')\ .replace(tzinfo=timezone.utc).astimezone(tz=pytz.timezone('Asia/Seoul')).replace(tzinfo=None) except ValueError: d['Opened'] = datetime.strptime(d['Opened'], '%Y-%m-%dT%H:%M:%S') \ .replace(tzinfo=timezone.utc).astimezone(tz=pytz.timezone('Asia/Seoul')).replace(tzinfo=None) fm = { 'currency': currency, 'date': d['Opened'], 'amount': Decimal(str(d['Amount'])) } result.append(fm) return result else: raise ExchangeNotProcessedException(r['message'])
def get_balance(self, currency=None): balance_list = [] if currency is None or currency == symbol.Currency("KRW"): try: r = self.thumb.balance('all') except Exception: raise ExchangeConnectionException() else: if not isinstance(currency, symbol.Currency): raise NotValidCurrency() try: r = self.thumb.balance(conv_currency_code(currency)) except Exception: raise ExchangeConnectionException() if r['status'] == "0000": data = r['data'] if currency == symbol.Currency("KRW"): dic = { 'currency': currency, 'available': data['available_krw'], 'pending': data['in_use_krw'], 'total': data['total_krw'] } balance_list.append(dic) else: i = 0 for key, val in data.items(): if i < 4: pass elif i % 5 == 4: total = Decimal(str(val)) elif i % 5 == 0: pending = Decimal(str(val)) elif i % 5 == 1: available = Decimal(str(val)) dic = { 'currency': conv_code_currency(key.split('_')[1].upper()), 'available': available, 'pending': pending, 'total': total } balance_list.append(dic) i += 1 return balance_list else: raise ExchangeNotProcessedException(r['message'])
def withdrawal(self, currency, address, amount, tag=None): if not isinstance(currency, symbol.Currency): raise NotValidCurrency() try: r = self.apiclient.withdraw(conv_currency_code(currency), address, amount, tag) except Exception: raise ExchangeConnectionException() if r['success'] is True: return True else: raise ExchangeNotProcessedException(r['message'])
def get_address(self, currency): if not isinstance(currency, symbol.Currency): raise NotValidCurrency() try: r = self.apiclient.getdepositaddress(currency) except Exception: raise ExchangeConnectionException() if r['success'] is True: data = r['result'] fm = {'currency': currency, 'address': data['Address']} return fm else: raise ExchangeNotProcessedException(r['message'])
def get_balance(self, currency=None): result = [] if currency is None: try: r = self.apiclient.getbalances() except Exception: raise ExchangeConnectionException() if r['success'] is True: data = r['result'] for d in data: fm = { 'currency': conv_code_currency(d['Currency']), 'available': Decimal(str(d['Available'])), 'pending': Decimal(str(d['Pending'])), 'total': Decimal(str(d['Balance'])) } result.append(fm) else: raise ExchangeNotProcessedException(r['message']) else: if not isinstance(currency, symbol.Currency): raise NotValidCurrency() try: r = self.apiclient.getbalance(conv_currency_code(currency)) except Exception: raise ExchangeConnectionException() if r['success'] is True: data = r['result'] fm = { 'currency': conv_code_currency(data['Currency']), 'available': Decimal(str(data['Available'])), 'pending': Decimal(str(data['Pending'])), 'total': Decimal(str(data['Balance'])) } result.append(fm) else: raise ExchangeNotProcessedException(r['message']) return result
def get_address(self, currency): if not isinstance(currency, symbol.Currency): raise NotValidCurrency() try: r = self.thumb.wallet_address(conv_currency_code(currency)) except Exception: raise ExchangeConnectionException() if r['status'] == "0000": data = r['data'] if "&dt=" in data['wallet_address']: dic = { 'currency': currency, 'address': data['wallet_address'].split("&dt=")[0], 'destination_tag': data['wallet_address'].split("&dt=")[1] } else: dic = {'currency': currency, 'address': data['wallet_address']} return dic else: raise ExchangeNotProcessedException(r['message'])