Skip to content

Commit

Permalink
Will attempt to access API endpoints that require valid config on sta…
Browse files Browse the repository at this point in the history
…rtup, informative error on fail
  • Loading branch information
rel-s authored and edeng23 committed May 12, 2021
1 parent c4d8a81 commit 849ac08
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions binance_trade_bot/binance_api_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def get_price(self, ticker_symbol):

class BinanceAPIManager:
def __init__(self, config: Config, db: Database, logger: Logger):
# initializing the client class calls `ping` API endpoint, verifying the connection
self.binance_client = Client(
config.BINANCE_API_KEY,
config.BINANCE_API_SECRET_KEY,
Expand Down Expand Up @@ -63,6 +64,12 @@ def get_fee(self, origin_coin: Coin, target_coin: Coin, selling: bool):
return base_fee * 0.75
return base_fee

def get_account(self):
"""
Get account information
"""
return self.binance_client.get_account()

def get_all_market_tickers(self) -> AllTickers:
"""
Get ticker price of all coins
Expand Down
7 changes: 7 additions & 0 deletions binance_trade_bot/crypto_trading.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ def main():
config = Config()
db = Database(logger, config)
manager = BinanceAPIManager(config, db, logger)
# check if we can access API feature that require valid config
try:
_ = manager.get_account()
except Exception as e: # pylint: disable=broad-except
logger.error("Couldn't access Binance API - API keys may be wrong or lack sufficient permissions")
logger.error(e)
return
strategy = get_strategy(config.STRATEGY)
if strategy is None:
logger.error("Invalid strategy name")
Expand Down

0 comments on commit 849ac08

Please sign in to comment.