Skip to content

Commit

Permalink
Add type annotations and use get_env_key
Browse files Browse the repository at this point in the history
  • Loading branch information
cjdsellers committed Dec 9, 2023
1 parent 1c13167 commit 1da0d11
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
18 changes: 9 additions & 9 deletions nautilus_trader/adapters/binance/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
# -------------------------------------------------------------------------------------------------

import asyncio
import os
from functools import lru_cache

from nautilus_trader.adapters.binance.common.enums import BinanceAccountType
Expand All @@ -27,6 +26,7 @@
from nautilus_trader.adapters.binance.spot.data import BinanceSpotDataClient
from nautilus_trader.adapters.binance.spot.execution import BinanceSpotExecutionClient
from nautilus_trader.adapters.binance.spot.providers import BinanceSpotInstrumentProvider
from nautilus_trader.adapters.env import get_env_key
from nautilus_trader.cache.cache import Cache
from nautilus_trader.common.clock import LiveClock
from nautilus_trader.common.component import MessageBus
Expand Down Expand Up @@ -431,27 +431,27 @@ def create( # type: ignore
def _get_api_key(account_type: BinanceAccountType, is_testnet: bool) -> str:
if is_testnet:
if account_type.is_spot_or_margin:
return os.environ["BINANCE_TESTNET_API_KEY"]
get_env_key("BINANCE_TESTNET_API_KEY")
else:
return os.environ["BINANCE_FUTURES_TESTNET_API_KEY"]
get_env_key("BINANCE_FUTURES_TESTNET_API_KEY")

if account_type.is_spot_or_margin:
return os.environ["BINANCE_API_KEY"]
return get_env_key("BINANCE_API_KEY")
else:
return os.environ["BINANCE_FUTURES_API_KEY"]
return get_env_key("BINANCE_FUTURES_API_KEY")


def _get_api_secret(account_type: BinanceAccountType, is_testnet: bool) -> str:
if is_testnet:
if account_type.is_spot_or_margin:
return os.environ["BINANCE_TESTNET_API_SECRET"]
return get_env_key("BINANCE_TESTNET_API_SECRET")
else:
return os.environ["BINANCE_FUTURES_TESTNET_API_SECRET"]
return get_env_key("BINANCE_FUTURES_TESTNET_API_SECRET")

if account_type.is_spot_or_margin:
return os.environ["BINANCE_API_SECRET"]
return get_env_key("BINANCE_API_SECRET")
else:
return os.environ["BINANCE_FUTURES_API_SECRET"]
return get_env_key("BINANCE_FUTURES_API_SECRET")


def _get_http_base_url(account_type: BinanceAccountType, is_testnet: bool, is_us: bool) -> str:
Expand Down
6 changes: 3 additions & 3 deletions nautilus_trader/adapters/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
import os


def get_env_key(key: str):
def get_env_key(key: str) -> str:
if key not in os.environ:
raise RuntimeError(f"Cannot find env var {key}")
raise RuntimeError(f"Cannot find env var '{key}'")
else:
return os.environ[key]


def get_env_key_or(key: str, default: str):
def get_env_key_or(key: str, default: str) -> str:
if key not in os.environ:
return default
else:
Expand Down

0 comments on commit 1da0d11

Please sign in to comment.