Skip to content

Commit

Permalink
Merge branch 'master' into update_api
Browse files Browse the repository at this point in the history
  • Loading branch information
dextertd authored Sep 28, 2023
2 parents f1e7901 + 0253d22 commit 9409ae1
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add the `HTTP` method `get_server_time()`
- Add `HTTP` methods for spot margin trading
- Add `HTTP` method `get_long_short_ratio()`
- Add optional `private_auth_expire` arg for WebSocket (https://github.com/bybit-exchange/pybit/pull/154)

### Deprecated
- The `HTTP` method `enable_universal_transfer_for_sub_uid()`

### Fixed
- Improve `close_position` logic


## [5.5.0] - 2023-07-17
### Added
- `helpers.py` which includes the `Helpers` class and the `close_position` method, which can be imported and employed like so:
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 9409ae1

Please sign in to comment.