Skip to content

Commit

Permalink
update README.md, delete hardcode, add __str__ to enums
Browse files Browse the repository at this point in the history
  • Loading branch information
sndmndss committed Aug 28, 2024
1 parent a6dc83e commit fce4a23
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 17 deletions.
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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("<PUBLIC_KEY>", "<SECRET_KEY>", 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)
Expand Down
20 changes: 9 additions & 11 deletions bpx/constants/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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
9 changes: 7 additions & 2 deletions examples/public_example.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from bpx.public import Public
from datetime import datetime, timedelta


def public_example():
Expand All @@ -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()
Expand Down
1 change: 1 addition & 0 deletions tests/test_base_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

12 changes: 8 additions & 4 deletions tests/tests_api/test_public.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest
from bpx.public import Public
from datetime import datetime, timedelta


@pytest.fixture
Expand All @@ -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
)


Expand Down Expand Up @@ -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)

0 comments on commit fce4a23

Please sign in to comment.