Skip to content

Commit

Permalink
Add missing Binancea module desc
Browse files Browse the repository at this point in the history
  • Loading branch information
miohtama committed May 3, 2024
1 parent d08039a commit ba66ed3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
6 changes: 6 additions & 0 deletions tradingstrategy/binance/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"""Binance data import helpers.
- Download Binance data to be used in your Python application
- Spot market prices and volume, :term:`OHLCV`
- Lending rates in margin trading
"""
20 changes: 18 additions & 2 deletions tradingstrategy/binance/downloader.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Get candlestick price and volume data from Binance.
"""

import requests
Expand Down Expand Up @@ -34,12 +35,23 @@
logger = logging.getLogger(__name__)


#: Binance API
#:
#: Use env vars to set a proxy to work around country restrictions
#:
BASE_BINANCE_API_URL = os.getenv("BASE_BINANCE_API_URL", "https://api.binance.com")

#: Binance margin API
#:
#: Use env vars to set a proxy to work around country restrictions
#:
BASE_BINANCE_MARGIN_API_URL = os.getenv("BASE_BINANCE_MARGIN_API_URL", "https://www.binance.com/bapi/margin")


class BinanceDataFetchError(ValueError):
"""Something wrong with Binance."""
"""Something wrong with Binance.
"""


class BinanceDownloader:
Expand Down Expand Up @@ -102,7 +114,7 @@ def fetch_candlestick_data(
dataframes = []
total_size = 0

with tqdm(total=len(symbols)) as progress_bar:
with tqdm(total=len(symbols), desc=desc) as progress_bar:
for symbol in symbols:
df = self.fetch_candlestick_data_single_pair(
symbol, time_bucket, start_at, end_at, force_download
Expand Down Expand Up @@ -393,6 +405,10 @@ def _fetch_lending_rates(
f"- Check Binance Futures API is allowed in your country.\n"
f"- Check symbol matches with valid symbols in method description.\n"
f"\n"
f"You can override Binance margin API URL to a HTTP proxy with:"
f""
f"""export BASE_BINANCE_MARGIN_API_URL="https://user:pass@proxy.example.com/bapi/margin" """
f"\n"
f"Response: {response.status_code} {response.text}"
)

Expand Down
1 change: 1 addition & 0 deletions tradingstrategy/utils/groupeduniverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ def __init__(
self.pairs: pd.GroupBy = self.df.groupby(by=self.primary_key_column)

if forward_fill:
old_pairs = self.pairs
self.pairs = _forward_fill(
self.pairs,
freq=self.time_bucket.to_frequency(),
Expand Down

0 comments on commit ba66ed3

Please sign in to comment.