Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions derive_client/_clients/rest/async_http/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ async def _initialize_bridge(self) -> None:
except BridgePrimarySignerRequiredError:
raise NotConnectedError("Bridge unavailable: requires signer to be the LightAccount owner.")

@property
def logger(self) -> LoggerType:
return self._logger

@property
def account(self) -> LightAccount:
"""Get the LightAccount instance (this is not a web3 contract instance)."""
Expand Down
4 changes: 4 additions & 0 deletions derive_client/_clients/rest/http/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ def _initialize_bridge(self) -> BridgeClient:
except BridgePrimarySignerRequiredError:
raise NotConnectedError("Bridge unavailable: requires signer to be the LightAccount owner.")

@property
def logger(self) -> LoggerType:
return self._logger

@property
def account(self) -> LightAccount:
"""Get the LightAccount instance (this is not a web3 contract instance)."""
Expand Down
13 changes: 8 additions & 5 deletions derive_client/_clients/websockets/client.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
"""
Synchronous WebSocket client for Derive.
Asynchronous WebSocket client for Derive.
"""

from __future__ import annotations

import contextlib
from logging import Logger
from pathlib import Path
from textwrap import dedent
from typing import Generator
Expand All @@ -27,13 +26,13 @@
from derive_client._clients.websockets.api import PrivateAPI, PublicAPI
from derive_client._clients.websockets.session import WebSocketSession
from derive_client.config import CONFIGS
from derive_client.data_types import ChecksumAddress, Environment
from derive_client.data_types import ChecksumAddress, Environment, LoggerType
from derive_client.data_types.generated_models import PublicLoginParamsSchema
from derive_client.utils.logger import get_logger


class WebSocketClient:
"""Synchronous WebSocket client for real-time data and operations."""
"""Asynchronous WebSocket client for real-time data and operations."""

@validate_call(config=ConfigDict(arbitrary_types_allowed=True))
def __init__(
Expand All @@ -43,7 +42,7 @@ def __init__(
session_key: str,
subaccount_id: int,
env: Environment,
logger: Logger | None = None,
logger: LoggerType | None = None,
request_timeout: float = 10.0,
):
config = CONFIGS[env]
Expand Down Expand Up @@ -177,6 +176,10 @@ async def _instantiate_subaccount(self, subaccount_id: int) -> Subaccount:
private_api=self._private_api, # type: ignore
)

@property
def logger(self) -> LoggerType:
return self._logger

@property
def account(self) -> LightAccount:
"""Get the LightAccount instance."""
Expand Down
6 changes: 3 additions & 3 deletions derive_client/_clients/websockets/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import inspect
import uuid
import weakref
from logging import Logger
from typing import TYPE_CHECKING, Any, Awaitable, Callable, Optional, Type, cast

import msgspec
Expand All @@ -19,6 +18,7 @@
from websockets.exceptions import ConnectionClosed

from derive_client._clients.utils import JSONRPCEnvelope, decode_envelope
from derive_client.data_types import LoggerType
from derive_client.utils.logger import get_logger

if TYPE_CHECKING:
Expand Down Expand Up @@ -75,7 +75,7 @@ def __init__(
reconnect: bool = True,
reconnect_delay: float = 1.0,
max_reconnect_delay: float = 60.0,
logger: Logger | None = None,
logger: LoggerType | None = None,
on_disconnect: LifecycleCallback | None = None,
on_reconnect: LifecycleCallback | None = None,
on_before_resubscribe: LifecycleCallback | None = None,
Expand Down Expand Up @@ -546,7 +546,7 @@ async def _run_handler(self, channel: str, handler: Handler, notification: Any)
self._logger.error(f"Handler error for {channel}: {e}", exc_info=True)

@staticmethod
def _finalize(logger: Logger) -> None:
def _finalize(logger: LoggerType) -> None:
"""Finalizer for cleanup."""
logger.debug("WebSocketSession garbage collected without explicit close()")

Expand Down
2 changes: 1 addition & 1 deletion docs/reference/clients/asynchttpclient.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
show_root_heading: false
heading_level: 2
members_order: source
members: ['__init__', 'account', 'active_subaccount', 'bridge', 'cached_subaccounts', 'collateral', 'connect', 'disconnect', 'fetch_subaccount', 'fetch_subaccounts', 'from_env', 'markets', 'mmp', 'orders', 'positions', 'rfq', 'timeout', 'trades', 'transactions']
members: ['__init__', 'account', 'active_subaccount', 'bridge', 'cached_subaccounts', 'collateral', 'connect', 'disconnect', 'fetch_subaccount', 'fetch_subaccounts', 'from_env', 'logger', 'markets', 'mmp', 'orders', 'positions', 'rfq', 'timeout', 'trades', 'transactions']
show_bases: false
show_source: false
inherited_members: false
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/clients/httpclient.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
show_root_heading: false
heading_level: 2
members_order: source
members: ['__init__', 'account', 'active_subaccount', 'bridge', 'cached_subaccounts', 'collateral', 'connect', 'disconnect', 'fetch_subaccount', 'fetch_subaccounts', 'from_env', 'markets', 'mmp', 'orders', 'positions', 'rfq', 'timeout', 'trades', 'transactions']
members: ['__init__', 'account', 'active_subaccount', 'bridge', 'cached_subaccounts', 'collateral', 'connect', 'disconnect', 'fetch_subaccount', 'fetch_subaccounts', 'from_env', 'logger', 'markets', 'mmp', 'orders', 'positions', 'rfq', 'timeout', 'trades', 'transactions']
show_bases: false
show_source: false
inherited_members: false
Expand Down