def test_getAccount(): filename = 'config.json' with open(filename) as config_file: config = json.load(config_file) api_key = '' api_secret = '' api_url = '' if 'api_key' in config and 'api_secret' in config and 'api_pass' in config and 'api_url' in config: api_key = config['api_key'] api_secret = config['api_secret'] api_url = config['api_url'] AuthAPI(api_key, api_secret, api_url) elif 'api_key' in config['binance'] and 'api_secret' in config[ 'binance'] and 'api_url' in config['binance']: api_key = config['binance']['api_key'] api_secret = config['binance']['api_secret'] api_url = config['binance']['api_url'] AuthAPI(api_key, api_secret, api_url) exchange = AuthAPI(api_key, api_secret, api_url) assert type(exchange) is AuthAPI df = exchange.getAccount() assert type(df) is pandas.core.frame.DataFrame actual = df.columns.to_list() expected = ['currency', 'balance', 'hold', 'available'] assert len(actual) == len(expected) assert all([a == b for a, b in zip(actual, expected)])
def test_get_fees_with_market(mocker): client_response = {'success': True, 'tradeFee': [{'maker': 0.001, 'symbol': 'CHZUSDT', 'taker': 0.001}]} with open(_get_config_file()) as config_file: config = json.load(config_file) api_key = '' api_secret = '' api_url = '' if 'api_key' in config and 'api_secret' in config and 'api_pass' in config and 'api_url' in config: api_key = config['api_key'] api_secret = config['api_secret'] api_url = config['api_url'] AuthAPI(api_key, api_secret, api_url) elif 'api_key' in config['binance'] and 'api_secret' in config['binance'] and 'api_url' in config['binance']: api_key = config['binance']['api_key'] api_secret = config['binance']['api_secret'] api_url = config['binance']['api_url'] AuthAPI(api_key, api_secret, api_url) exchange = AuthAPI(api_key, api_secret, api_url) assert type(exchange) is AuthAPI mocker.patch("models.exchange.binance.Client.get_trade_fee", return_value=client_response) df = exchange.getFees(MOCK_MARKET) assert type(df) is pandas.core.frame.DataFrame assert len(df) == 1 actual = df.columns.to_list() expected = ['maker_fee_rate', 'taker_fee_rate', 'usd_volume', 'market'] assert len(actual) == len(expected) assert all([a == b for a, b in zip(actual, expected)])
def test_get_maker_fee_with_market(mocker): client_response = { 'success': True, 'tradeFee': [{ 'maker': 0.001, 'symbol': 'CHZUSDT', 'taker': 0.001 }] } with open(_get_config_file()) as config_file: config = json.load(config_file) api_key = '' api_secret = '' api_url = '' if 'api_key' in config and 'api_secret' in config and 'api_pass' in config and 'api_url' in config: api_key = config['api_key'] api_secret = config['api_secret'] api_url = config['api_url'] AuthAPI(api_key, api_secret, api_url) elif 'api_key' in config['binance'] and 'api_secret' in config[ 'binance'] and 'api_url' in config['binance']: api_key = config['binance']['api_key'] api_secret = config['binance']['api_secret'] api_url = config['binance']['api_url'] AuthAPI(api_key, api_secret, api_url) exchange = AuthAPI(api_key, api_secret, api_url) assert type(exchange) is AuthAPI mocker.patch("models.exchange.binance.Client.get_trade_fee", return_value=client_response) fee = exchange.getMakerFee(MOCK_MARKET) assert type(fee) is float assert fee == 0.001
def test_getFeesWithMarket(): filename = 'config.json' with open(filename) as config_file: config = json.load(config_file) api_key = '' api_secret = '' api_url = '' if 'api_key' in config and 'api_secret' in config and 'api_pass' in config and 'api_url' in config: api_key = config['api_key'] api_secret = config['api_secret'] api_url = config['api_url'] AuthAPI(api_key, api_secret, api_url) elif 'api_key' in config['binance'] and 'api_secret' in config[ 'binance'] and 'api_url' in config['binance']: api_key = config['binance']['api_key'] api_secret = config['binance']['api_secret'] api_url = config['binance']['api_url'] AuthAPI(api_key, api_secret, api_url) exchange = AuthAPI(api_key, api_secret, api_url) assert type(exchange) is AuthAPI df = exchange.getFees(VALID_ORDER_MARKET) assert type(df) is pandas.core.frame.DataFrame assert len(df) == 1 actual = df.columns.to_list() expected = ['maker_fee_rate', 'taker_fee_rate', 'usd_volume', 'market'] assert len(actual) == len(expected) assert all([a == b for a, b in zip(actual, expected)])
def test_getMakerFeeWithMarket(): filename = 'config.json' with open(filename) as config_file: config = json.load(config_file) api_key = '' api_secret = '' api_url = '' if 'api_key' in config and 'api_secret' in config and 'api_pass' in config and 'api_url' in config: api_key = config['api_key'] api_secret = config['api_secret'] api_url = config['api_url'] AuthAPI(api_key, api_secret, api_url) elif 'api_key' in config['binance'] and 'api_secret' in config[ 'binance'] and 'api_url' in config['binance']: api_key = config['binance']['api_key'] api_secret = config['binance']['api_secret'] api_url = config['binance']['api_url'] AuthAPI(api_key, api_secret, api_url) exchange = AuthAPI(api_key, api_secret, api_url) assert type(exchange) is AuthAPI fee = exchange.getMakerFee(VALID_ORDER_MARKET) assert type(fee) is float assert fee > 0
def test_getMakerFeeWithoutMarket(): filename = 'config.json' with open(filename) as config_file: config = json.load(config_file) api_key = '' api_secret = '' api_url = '' if 'api_key' in config and 'api_secret' in config and 'api_pass' in config and 'api_url' in config: api_key = config['api_key'] api_secret = config['api_secret'] api_url = config['api_url'] AuthAPI(api_key, api_secret, api_url) elif 'api_key' in config['binance'] and 'api_secret' in config[ 'binance'] and 'api_url' in config['binance']: api_key = config['binance']['api_key'] api_secret = config['binance']['api_secret'] api_url = config['binance']['api_url'] AuthAPI(api_key, api_secret, api_url) exchange = AuthAPI(api_key, api_secret, api_url) assert type(exchange) is AuthAPI fees = exchange.getMakerFee() assert type(fees) is pandas.core.frame.DataFrame assert len(fees) > 0
def test_api_v3_account1(): #global app api = AuthAPI(app.api_key, app.api_secret) with open("tests/unit_tests/responses/account1.json") as fh: responses.add( responses.GET, "https://api.binance.com/api/v3/account", json=json.load(fh), status=200, ) df = api.getAccounts() fh.close() assert len(df) > 1 assert df.columns.tolist() == [ "index", "id", "currency", "balance", "hold", "available", "profile_id", "trading_enabled", ] assert df.dtypes["index"] == "int64" assert df.dtypes["id"] == "object" assert df.dtypes["currency"] == "object" assert df.dtypes["balance"] == "object" assert df.dtypes["hold"] == "object" assert df.dtypes["available"] == "object" assert df.dtypes["profile_id"] == "object" assert df.dtypes["trading_enabled"] == "bool"
def test_getOrdersValidActionSell(): filename = 'config.json' with open(filename) as config_file: config = json.load(config_file) api_key = '' api_secret = '' api_url = '' if 'api_key' in config and 'api_secret' in config and 'api_pass' in config and 'api_url' in config: api_key = config['api_key'] api_secret = config['api_secret'] api_url = config['api_url'] AuthAPI(api_key, api_secret, api_url) elif 'api_key' in config['binance'] and 'api_secret' in config[ 'binance'] and 'api_url' in config['binance']: api_key = config['binance']['api_key'] api_secret = config['binance']['api_secret'] api_url = config['binance']['api_url'] AuthAPI(api_key, api_secret, api_url) exchange = AuthAPI(api_key, api_secret, api_url) assert type(exchange) is AuthAPI df = exchange.getOrders(market=VALID_ORDER_MARKET, action='sell') assert len(df) >= 0 actual = df.columns.to_list() expected = [ 'created_at', 'market', 'action', 'type', 'size', 'filled', 'status', 'price' ] assert len(actual) == len(expected) assert all([a == b for a, b in zip(actual, expected)])
def test_getOrdersValidStatusActive(): filename = 'config.json' with open(filename) as config_file: config = json.load(config_file) api_key = '' api_secret = '' api_url = '' if 'api_key' in config and 'api_secret' in config and 'api_pass' in config and 'api_url' in config: api_key = config['api_key'] api_secret = config['api_secret'] api_url = config['api_url'] AuthAPI(api_key, api_secret, api_url) elif 'api_key' in config['binance'] and 'api_secret' in config['binance'] and 'api_url' in config['binance']: api_key = config['binance']['api_key'] api_secret = config['binance']['api_secret'] api_url = config['binance']['api_url'] AuthAPI(api_key, api_secret, api_url) exchange = AuthAPI(api_key, api_secret, api_url) assert type(exchange) is AuthAPI df = exchange.getOrders(market=VALID_ORDER_MARKET, status='active') if len(df) == 0: pass else: actual = df.columns.to_list() expected = ['created_at', 'market', 'action', 'type', 'size', 'filled', 'status', 'price'] # order is not important, but no duplicate assert len(actual) == len(expected) diff = set(actual) ^ set(expected) assert not diff
def test_getTime(): filename = 'config.json' with open(filename) as config_file: config = json.load(config_file) api_key = '' api_secret = '' api_url = '' if 'api_key' in config and 'api_secret' in config and 'api_pass' in config and 'api_url' in config: api_key = config['api_key'] api_secret = config['api_secret'] api_url = config['api_url'] AuthAPI(api_key, api_secret, api_url) elif 'api_key' in config['binance'] and 'api_secret' in config[ 'binance'] and 'api_url' in config['binance']: api_key = config['binance']['api_key'] api_secret = config['binance']['api_secret'] api_url = config['binance']['api_url'] AuthAPI(api_key, api_secret, api_url) exchange = AuthAPI(api_key, api_secret, api_url) assert type(exchange) is AuthAPI resp = exchange.getTime() assert type(resp) is datetime
def test_get_maker_fee_with_market(): global app exchange = AuthAPI(app.api_key, app.api_secret) assert type(exchange) is AuthAPI fee = exchange.getMakerFee() assert type(fee) is float assert fee == 0.0015
def getOrders(self, market='', action='', status='all'): """Retrieves orders either live or simulation Parameters ---------- market : str, optional Filters orders by market action : str, optional Filters orders by action status : str Filters orders by status, defaults to 'all' """ # validate market is syntactically correct self._checkMarketSyntax(market) if action != '': # validate action is either a buy or sell if not action in ['buy', 'sell']: raise ValueError('Invalid order action.') # validate status is open, pending, done, active or all if not status in [ 'open', 'pending', 'done', 'active', 'all', 'filled' ]: raise ValueError('Invalid order status.') if self.app.getExchange() == 'binance': if self.mode == 'live': # if config is provided and live connect to Binance account portfolio model = BAuthAPI(self.app.getAPIKey(), self.app.getAPISecret(), self.app.getAPIURL()) # retrieve orders from live Binance account portfolio self.orders = model.getOrders(market, action, status) return self.orders else: # return dummy orders if market == '': return self.orders else: return self.orders[self.orders['market'] == market] if self.app.getExchange() == 'coinbasepro': if self.mode == 'live': # if config is provided and live connect to Coinbase Pro account portfolio model = CBAuthAPI(self.app.getAPIKey(), self.app.getAPISecret(), self.app.getAPIPassphrase(), self.app.getAPIURL()) # retrieve orders from live Coinbase Pro account portfolio self.orders = model.getOrders(market, action, status) return self.orders else: # return dummy orders if market == '': return self.orders else: return self.orders[self.orders['market'] == market]
def test_get_orders(mocker): client_response = [{ 'symbol': 'CHZUSDT', 'orderId': 123456789, 'orderListId': -1, 'clientOrderId': 'SOME-CLIENT-ORDER-ID', 'price': '0.00000000', 'origQty': '31.30000000', 'executedQty': '31.30000000', 'cummulativeQuoteQty': '15.68161300', 'status': 'FILLED', 'timeInForce': 'GTC', 'type': 'MARKET', 'side': 'SELL', 'stopPrice': '0.00000000', 'icebergQty': '0.00000000', 'time': 1616845743872, 'updateTime': 1616845743872, 'isWorking': True, 'origQuoteOrderQty': '0.00000000' }] with open(_get_config_file()) as config_file: config = json.load(config_file) api_key = '' api_secret = '' api_url = '' if 'api_key' in config and 'api_secret' in config and 'api_pass' in config and 'api_url' in config: api_key = config['api_key'] api_secret = config['api_secret'] api_url = config['api_url'] AuthAPI(api_key, api_secret, api_url) elif 'api_key' in config['binance'] and 'api_secret' in config[ 'binance'] and 'api_url' in config['binance']: api_key = config['binance']['api_key'] api_secret = config['binance']['api_secret'] api_url = config['binance']['api_url'] AuthAPI(api_key, api_secret, api_url) exchange = AuthAPI(api_key, api_secret, api_url) assert type(exchange) is AuthAPI mocker.patch("models.exchange.binance.Client.get_all_orders", return_value=client_response) df = exchange.getOrders(MOCK_MARKET) assert len(df) > 0 actual = df.columns.to_list() expected = [ 'created_at', 'market', 'action', 'type', 'size', 'filled', 'status', 'price' ] # order is not important, but no duplicate assert len(actual) == len(expected) diff = set(actual) ^ set(expected) assert not diff
def test_get_fees_with_market(): global app exchange = AuthAPI(app.api_key, app.api_secret) assert type(exchange) is AuthAPI df = exchange.getFees() assert type(df) is pandas.core.frame.DataFrame assert len(df) == 1 actual = df.columns.to_list() expected = ["maker_fee_rate", "taker_fee_rate", "usd_volume", "market"] assert len(actual) == len(expected) assert all([a == b for a, b in zip(actual, expected)])
def test_config_json_exists_and_valid(): file = _get_config_file() assert os.path.exists(file) == True with open(file) as config_file: config = json.load(config_file) if 'api_key' in config and 'api_secret' in config and 'api_pass' in config and 'api_url' in config: api_key = config['api_key'] api_secret = config['api_secret'] api_url = config['api_url'] AuthAPI(api_key, api_secret, api_url) elif 'api_key' in config['binance'] and 'api_secret' in config['binance'] and 'api_url' in config['binance']: api_key = config['binance']['api_key'] api_secret = config['binance']['api_secret'] api_url = config['binance']['api_url'] AuthAPI(api_key, api_secret, api_url)
def test_instantiate_authapi_with_api_secret_error(): api_key = "0000000000000000000000000000000000000000000000000000000000000000" api_secret = "ERROR" with pytest.raises(SystemExit) as execinfo: AuthAPI(api_key, api_secret) assert str(execinfo.value) == 'Binance API secret is invalid'
def test_instantiate_authapi_with_api_secret_error(): global app api_secret = "Ivalid" with pytest.raises(SystemExit) as execinfo: AuthAPI(app.api_key, api_secret) assert str(execinfo.value) == "Binance API secret is invalid"
def test_instantiate_authapi_with_api_url_error(): global app api_url = "https://foo.com" with pytest.raises(ValueError) as execinfo: AuthAPI(app.api_key, app.api_secret, api_url) assert str(execinfo.value) == "Binance API URL is invalid"
def test_get_account(mocker): client_response = { 'makerCommission': 10, 'takerCommission': 10, 'buyerCommission': 0, 'sellerCommission': 0, 'canTrade': True, 'canWithdraw': True, 'canDeposit': True, 'updateTime': 1620861508183, 'accountType': 'SPOT', 'balances': [ {'asset': 'BTC', 'free': '0.00000000', 'locked': '0.00000000'}, {'asset': 'LTC', 'free': '0.00000000', 'locked': '0.24944000'} ], 'permissions': ['SPOT'] } with open(_get_config_file()) as config_file: config = json.load(config_file) api_key = '' api_secret = '' api_url = '' if 'api_key' in config and 'api_secret' in config and 'api_pass' in config and 'api_url' in config: api_key = config['api_key'] api_secret = config['api_secret'] api_url = config['api_url'] AuthAPI(api_key, api_secret, api_url) elif 'api_key' in config['binance'] and 'api_secret' in config['binance'] and 'api_url' in config['binance']: api_key = config['binance']['api_key'] api_secret = config['binance']['api_secret'] api_url = config['binance']['api_url'] AuthAPI(api_key, api_secret, api_url) exchange = AuthAPI(api_key, api_secret, api_url) assert type(exchange) is AuthAPI mocker.patch("models.exchange.binance.Client.get_account", return_value=client_response) df = exchange.getAccount() assert type(df) is pandas.core.frame.DataFrame actual = df.columns.to_list() expected = ['currency', 'balance', 'hold', 'available'] assert len(actual) == len(expected) assert all([a == b for a, b in zip(actual, expected)])
def test_instantiate_authapi_with_api_url_error(): api_key = "0000000000000000000000000000000000000000000000000000000000000000" api_secret = "0000000000000000000000000000000000000000000000000000000000000000" api_url = "ERROR" with pytest.raises(ValueError) as execinfo: AuthAPI(api_key, api_secret, api_url) assert str(execinfo.value) == 'Binance API URL is invalid'
def test_getOrdersInvalidStatus(): filename = 'config.json' with open(filename) as config_file: config = json.load(config_file) api_key = '' api_secret = '' api_url = '' if 'api_key' in config and 'api_secret' in config and 'api_pass' in config and 'api_url' in config: api_key = config['api_key'] api_secret = config['api_secret'] api_url = config['api_url'] AuthAPI(api_key, api_secret, api_url) elif 'api_key' in config['binance'] and 'api_secret' in config[ 'binance'] and 'api_url' in config['binance']: api_key = config['binance']['api_key'] api_secret = config['binance']['api_secret'] api_url = config['binance']['api_url'] AuthAPI(api_key, api_secret, api_url) exchange = AuthAPI(api_key, api_secret, api_url) assert type(exchange) is AuthAPI with pytest.raises(ValueError) as execinfo: exchange.getOrders(status='ERROR') assert str(execinfo.value) == 'Invalid order status.'
def test_marketBuyInvalidMarket(): filename = 'config.json' with open(filename) as config_file: config = json.load(config_file) api_key = '' api_secret = '' api_url = '' if 'api_key' in config and 'api_secret' in config and 'api_pass' in config and 'api_url' in config: api_key = config['api_key'] api_secret = config['api_secret'] api_url = config['api_url'] AuthAPI(api_key, api_secret, api_url) elif 'api_key' in config['binance'] and 'api_secret' in config[ 'binance'] and 'api_url' in config['binance']: api_key = config['binance']['api_key'] api_secret = config['binance']['api_secret'] api_url = config['binance']['api_url'] AuthAPI(api_key, api_secret, api_url) exchange = AuthAPI(api_key, api_secret, api_url) assert type(exchange) is AuthAPI with pytest.raises(ValueError) as execinfo: exchange.marketBuy('ERROR', -1) assert str(execinfo.value) == 'Binance market is invalid.'
def test_get_orders(): global app exchange = AuthAPI(app.api_key, app.api_secret) assert type(exchange) is AuthAPI df = exchange.getOrders() assert type(df) is pandas.core.frame.DataFrame assert len(df) > 0 actual = df.columns.to_list() expected = [ "created_at", "market", "action", "type", "size", "filled", "status", "price", ] assert len(actual) == len(expected) diff = set(actual) ^ set(expected) assert not diff
def test_instantiate_authapi_without_error(): global app exchange = AuthAPI(app.api_key, app.api_secret) assert type(exchange) is AuthAPI
def test_instantiate_authapi_without_error(): api_key = "0000000000000000000000000000000000000000000000000000000000000000" api_secret = "0000000000000000000000000000000000000000000000000000000000000000" exchange = AuthAPI(api_key, api_secret) assert type(exchange) is AuthAPI
def getOrders(self, market="", action="", status="all"): """Retrieves orders either live or simulation Parameters ---------- market : str, optional Filters orders by market action : str, optional Filters orders by action status : str Filters orders by status, defaults to 'all' """ # validate market is syntactically correct self._checkMarketSyntax(market) if action != "": # validate action is either a buy or sell if not action in ["buy", "sell"]: raise ValueError("Invalid order action.") # validate status is open, pending, done, active or all if not status in [ "open", "pending", "done", "active", "all", "filled" ]: raise ValueError("Invalid order status.") if self.app.getExchange() == Exchange.BINANCE: if self.mode == "live": # if config is provided and live connect to Binance account portfolio model = BAuthAPI( self.app.getAPIKey(), self.app.getAPISecret(), self.app.getAPIURL(), recv_window=self.app.getRecvWindow(), ) # retrieve orders from live Binance account portfolio self.orders = model.getOrders(market, action, status) return self.orders else: # return dummy orders if market == "": return self.orders else: return self.orders[self.orders["market"] == market] if self.app.getExchange() == Exchange.KUCOIN: if self.mode == 'live': # if config is provided and live connect to Kucoin account portfolio model = KAuthAPI( self.app.getAPIKey(), self.app.getAPISecret(), self.app.getAPIPassphrase(), self.app.getAPIURL(), use_cache=self.app.useKucoinCache(), ) # retrieve orders from live Kucoin account portfolio self.orders = model.getOrders(market, action, status) return self.orders else: if market == '': return self.orders else: return self.orders[self.orders['market'] == market] if self.app.getExchange() == Exchange.COINBASEPRO: if self.mode == "live": # if config is provided and live connect to Coinbase Pro account portfolio model = CBAuthAPI( self.app.getAPIKey(), self.app.getAPISecret(), self.app.getAPIPassphrase(), self.app.getAPIURL(), ) # retrieve orders from live Coinbase Pro account portfolio self.orders = model.getOrders(market, action, status) return self.orders else: # return dummy orders if market == "": return self.orders else: if "market" in self.orders: return self.orders[self.orders["market"] == market] else: return pd.DataFrame() if self.app.getExchange() == Exchange.DUMMY: return self.orders[[ "created_at", "market", "action", "type", "size", "filled", "fees", "price", "status", ]]
def getBalance(self, currency=''): """Retrieves balance either live or simulation Parameters ---------- currency: str, optional Filters orders by currency """ if self.app.getExchange() == 'binance': if self.mode == 'live': model = BAuthAPI(self.app.getAPIKey(), self.app.getAPISecret()) df = model.getAccount() if isinstance(df, pd.DataFrame): if currency == '': # retrieve all balances return df else: # retrieve balance of specified currency df_filtered = df[df['currency'] == currency]['available'] if len(df_filtered) == 0: # return nil balance if no positive balance was found return 0.0 else: # return balance of specified currency (if positive) if currency in ['EUR', 'GBP', 'USD']: return float( self.app.truncate( float(df[df['currency'] == currency] ['available'].values[0]), 2)) else: return float( self.app.truncate( float(df[df['currency'] == currency] ['available'].values[0]), 4)) else: return 0.0 else: # return dummy balances if currency == '': # retrieve all balances return self.balance else: if self.app.getExchange() == 'binance': self.balance = self.balance.replace('QUOTE', currency) else: # replace QUOTE and BASE placeholders if currency in ['EUR', 'GBP', 'USD']: self.balance = self.balance.replace( 'QUOTE', currency) else: self.balance = self.balance.replace( 'BASE', currency) if self.balance.currency[self.balance.currency.isin( [currency])].empty: self.balance.loc[len( self.balance)] = [currency, 0, 0, 0] # retrieve balance of specified currency df = self.balance df_filtered = df[df['currency'] == currency]['available'] if len(df_filtered) == 0: # return nil balance if no positive balance was found return 0.0 else: # return balance of specified currency (if positive) if currency in ['EUR', 'GBP', 'USD']: return float( self.app.truncate( float(df[df['currency'] == currency] ['available'].values[0]), 2)) else: return float( self.app.truncate( float(df[df['currency'] == currency] ['available'].values[0]), 4)) else: if self.mode == 'live': # if config is provided and live connect to Coinbase Pro account portfolio model = CBAuthAPI(self.app.getAPIKey(), self.app.getAPISecret(), self.app.getAPIPassphrase(), self.app.getAPIURL()) if currency == '': # retrieve all balances return model.getAccounts()[[ 'currency', 'balance', 'hold', 'available' ]] else: df = model.getAccounts() # retrieve balance of specified currency df_filtered = df[df['currency'] == currency]['available'] if len(df_filtered) == 0: # return nil balance if no positive balance was found return 0.0 else: # return balance of specified currency (if positive) if currency in ['EUR', 'GBP', 'USD']: return float( self.app.truncate( float(df[df['currency'] == currency] ['available'].values[0]), 2)) else: return float( self.app.truncate( float(df[df['currency'] == currency] ['available'].values[0]), 4)) else: # return dummy balances if currency == '': # retrieve all balances return self.balance else: # replace QUOTE and BASE placeholders if currency in ['EUR', 'GBP', 'USD']: self.balance = self.balance.replace('QUOTE', currency) elif currency in ['BCH', 'BTC', 'ETH', 'LTC', 'XLM']: self.balance = self.balance.replace('BASE', currency) if self.balance.currency[self.balance.currency.isin( [currency])].empty == True: self.balance.loc[len( self.balance)] = [currency, 0, 0, 0] # retrieve balance of specified currency df = self.balance df_filtered = df[df['currency'] == currency]['available'] if len(df_filtered) == 0: # return nil balance if no positive balance was found return 0.0 else: # return balance of specified currency (if positive) if currency in ['EUR', 'GBP', 'USD']: return float( self.app.truncate( float(df[df['currency'] == currency] ['available'].values[0]), 2)) else: return float( self.app.truncate( float(df[df['currency'] == currency] ['available'].values[0]), 4))