diff --git a/README.md b/README.md index 12f1be6..61dd0e4 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,32 @@ async def main(): asyncio.run(main()) ``` +### Request Configuration + +You can get the request configuration using `bpx.base.base_account` and `bpx.base.base_public` without doing a request. + +```python +from bpx.base.base_account import BaseAccount +from bpx.base.base_public import BasePublic +from bpx.models.request_configuration import RequestConfiguration # unnecessary + +base_public = BasePublic() +base_account = BaseAccount("", "", window=5000, debug=True) + +# let's get url and headers for this account request +request_config: RequestConfiguration = base_account.get_balances() +url = request_config.url +headers = request_config.headers +# let's get url for this public request +request_url: str = base_public.get_ticker_url(symbol="SOL_USDC") +``` + +### Can be useful + +`bpx.models` - models that are in use by request. + +`bpx.constants` - constants that may help if you don't know which variables are existing. + ## Useful sources [Discord channel to get help](https://discord.gg/backpack) diff --git a/bpx/constants/enums.py b/bpx/constants/enums.py index f460232..dcbeb8f 100644 --- a/bpx/constants/enums.py +++ b/bpx/constants/enums.py @@ -2,17 +2,6 @@ from typing import Optional -class Blockchain(Enum): - ETHEREUM = "Ethereum" - SOLANA = "Solana" - Polygon = "Polygon" - BITCOIN = "Bitcoin" - - @classmethod - def has_value(cls, value): - return value in cls._value2member_map_ - - class TimeInterval(Enum): ONE_MINUTE = "1m" THREE_MINUTES = "3m" @@ -34,6 +23,9 @@ class TimeInterval(Enum): def has_value(cls, value): return value in cls._value2member_map_ + def __str__(self): + return self.value + class TimeInForce(Enum): GTC = "GTC" @@ -44,6 +36,9 @@ class TimeInForce(Enum): def has_value(cls, value): return value in cls._value2member_map_ + def __str__(self): + return self.value + class SelfTradePrevention(Enum): REJECT_TAKER = "RejectTaker" @@ -54,3 +49,6 @@ class SelfTradePrevention(Enum): @classmethod def has_value(cls, value): return value in cls._value2member_map_ + + def __str__(self): + return self.value diff --git a/examples/public_example.py b/examples/public_example.py index 51664b7..d4b3d35 100644 --- a/examples/public_example.py +++ b/examples/public_example.py @@ -1,4 +1,5 @@ from bpx.public import Public +from datetime import datetime, timedelta def public_example(): @@ -16,8 +17,12 @@ def public_example(): depth = public.get_depth("SOL_USDC") print("Depth for SOL_USDC:", depth) - klines_timestamp = 1715692417 - klines = public.get_klines("SOL_USDC", "1m", klines_timestamp) + now = datetime.now() + time_1_minute_ago = now - timedelta(minutes=1) + timestamp_1_minute_ago = int(time_1_minute_ago.timestamp()) + time_11_minutes_ago = now - timedelta(minutes=11) + timestamp_11_minutes_ago = int(time_11_minutes_ago.timestamp()) + klines = public.get_klines("SOL_USDC", "1m", timestamp_11_minutes_ago, timestamp_1_minute_ago) print("K-lines for SOL_USDC:", klines) status = public.get_status() diff --git a/tests/test_base_account.py b/tests/test_base_account.py index 5d1fa6c..c689eec 100644 --- a/tests/test_base_account.py +++ b/tests/test_base_account.py @@ -82,3 +82,4 @@ def test_withdrawal(account): assert request_config.url == "https://api.backpack.exchange/wapi/v1/capital/withdrawals" assert request_config.data["address"] == "1BitcoinAddress" assert request_config.data["blockchain"] == "Bitcoin" + diff --git a/tests/tests_api/test_public.py b/tests/tests_api/test_public.py index 9adfb49..494d4b0 100644 --- a/tests/tests_api/test_public.py +++ b/tests/tests_api/test_public.py @@ -1,5 +1,6 @@ import pytest from bpx.public import Public +from datetime import datetime, timedelta @pytest.fixture @@ -25,10 +26,13 @@ def test_get_depth_returns_dict(public_client: Public): def test_get_klines_returns_list(public_client: Public): - start_time = 1715692417 - end_time = 1715778817 + now = datetime.now() + time_1_minute_ago = now - timedelta(minutes=1) + timestamp_1_minute_ago = int(time_1_minute_ago.timestamp()) + time_11_minutes_ago = now - timedelta(minutes=11) + timestamp_11_minutes_ago = int(time_11_minutes_ago.timestamp()) assert isinstance( - public_client.get_klines("BTC_USDC", "1d", start_time, end_time), list + public_client.get_klines("BTC_USDC", "5m", timestamp_11_minutes_ago, timestamp_1_minute_ago), list ) @@ -56,4 +60,4 @@ def test_get_recent_trades_returns_list(public_client: Public): def test_get_history_trades_returns_list(public_client: Public): - assert isinstance(public_client.get_history_trades("WEN_USDC"), list) + assert isinstance(public_client.get_history_trades("WEN_USDC"), list) \ No newline at end of file