Skip to content

Commit

Permalink
Merge pull request #163 from bybit-exchange/update_changelog
Browse files Browse the repository at this point in the history
Update changelog
  • Loading branch information
dextertd authored Sep 26, 2023
2 parents f1b797d + b3a91d5 commit 0253d22
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Your `api_secret` is the private key (RSA) you generate
- Learn more [here](https://www.bybit.com/en-US/help-center/bybitHC_Article?id=000001923&language=en_US)
- See examples files: [HTTP](https://github.com/bybit-exchange/pybit/blob/master/examples/http_example_rsa_authentication.py) and [WebSocket](https://github.com/bybit-exchange/pybit/blob/master/examples/websocket_example_rsa_authentication.py)
- Add optional `private_auth_expire` arg for WebSocket (https://github.com/bybit-exchange/pybit/pull/154)

## [5.5.0] - 2023-07-17
### Added
Expand Down
4 changes: 2 additions & 2 deletions pybit/_http_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ class _V5HTTPManager:
recv_window: bool = field(default=5000)
force_retry: bool = field(default=False)
retry_codes: defaultdict[dict] = field(
default_factory=lambda: {},
default_factory=dict,
init=False,
)
ignore_codes: dict = field(
default_factory=lambda: {},
default_factory=dict,
init=False,
)
max_retries: bool = field(default=3)
Expand Down
6 changes: 5 additions & 1 deletion pybit/_websocket_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def __init__(
retries=10,
restart_on_error=True,
trace_logging=False,
private_auth_expire=1
):
self.testnet = testnet
self.domain = domain
Expand All @@ -50,6 +51,9 @@ def __init__(
self.ws_name = ws_name
if api_key:
self.ws_name += " (Auth)"

# Delta time for private auth expiration in seconds
self.private_auth_expire = private_auth_expire

# Setup the callback directory following the format:
# {
Expand Down Expand Up @@ -202,7 +206,7 @@ def generate_rsa():
return base64.b64encode(signature).decode()

# Generate expires.
expires = _helpers.generate_timestamp() + 1000
expires = _helpers.generate_timestamp() + (self.private_auth_expire * 1000)

# Generate signature.
_val = f"GET/realtime{expires}"
Expand Down
18 changes: 18 additions & 0 deletions tests/test_pybit.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,21 @@ def test_topic_category_mismatch(self):
)

ws.order_stream(callback=self._callback_function)

class PrivateWebSocketTest(unittest.TestCase):
# Connect to private websocket and see if we can auth.
def _callback_function(msg):
print(msg)

def test_private_websocket_connect(self):
ws_private = WebSocket(
testnet=True,
channel_type="private",
api_key="...",
api_secret="...",
trace_logging=True,
#private_auth_expire=10
)

ws_private.position_stream(callback=self._callback_function)
#time.sleep(10)

0 comments on commit 0253d22

Please sign in to comment.