Skip to content

Commit

Permalink
better logging when connecting
Browse files Browse the repository at this point in the history
  • Loading branch information
woody committed Dec 21, 2023
1 parent 3c0f5d4 commit 36c0cd8
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/rithmic/config/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ class RithmicEnvironment(enum.Enum):
RITHMIC_PAPER_TRADING = 'RITHMIC_PAPER_TRADING'
RITHMIC_LIVE = 'RITHMIC_LIVE'

def __repr__(self):
return self.value


def _get_config_file(environment: RithmicEnvironment):
try:
Expand Down
8 changes: 7 additions & 1 deletion src/rithmic/interfaces/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ def _setup_ssl_context():

class RithmicBaseApi(metaclass=ABCMeta):
infra_type = None
api_type = None

def __init__(self, env: RithmicEnvironment = None, callback_manager: CallbackManager = None,
auto_connect: bool = True, loop: AbstractEventLoop = None):
self.ws = None
credentials = get_rithmic_credentials(env)
self.env = env
self.uri = credentials['uri']
self.user = credentials['user']
self.pw = credentials['pw']
Expand Down Expand Up @@ -145,7 +147,11 @@ def setup_ssl_context(self):
def connect_and_login(self):
ws = self._get_websocket_connection()
self.ws = ws
return self._log_into_rithmic()
log_in_details = self._log_into_rithmic()
logger.info('Connected to {0} as User {1} on {2} ({3})'.format(
self.api_type, self.user, self.system_name, self.env
))
return log_in_details

def _get_websocket_connection(self):
future = asyncio.run_coroutine_threadsafe(self.get_websocket_connection(), self.loop)
Expand Down
2 changes: 2 additions & 0 deletions src/rithmic/interfaces/history/history_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from rithmic.interfaces.base import RithmicBaseApi
from rithmic.protocol_buffers import request_login_pb2, request_tick_bar_replay_pb2, response_tick_bar_replay_pb2
from rithmic.tools.general import set_index_no_name, is_datetime_utc
from rithmic.tools.meta import ApiType
from rithmic.tools.pyrithmic_exceptions import ReferenceDataUnavailableException, DownloadErrorException
from rithmic.tools.pyrithmic_logger import logger, configure_logging

Expand Down Expand Up @@ -101,6 +102,7 @@ class RithmicHistoryApi(RithmicBaseApi):
Rithmic History API For the HISTORY PLANT to download historical tick data for security/exchange combinations
"""
infra_type = request_login_pb2.RequestLogin.SysInfraType.HISTORY_PLANT
api_type = ApiType.HISTORY

def __init__(self, env: RithmicEnvironment = None, callback_manager: CallbackManager = None,
auto_connect: bool = True, loop=None):
Expand Down
3 changes: 3 additions & 0 deletions src/rithmic/interfaces/order/order_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
request_modify_order_pb2, request_update_target_bracket_level_pb2,
)
from rithmic.tools.general import dict_destructure, get_utc_now
from rithmic.tools.meta import ApiType
from rithmic.tools.pyrithmic_exceptions import (
NoValidTradingAccountException, NoValidTradeRouteException, NoTradingConfigException, WebsocketClosedException,
)
Expand Down Expand Up @@ -53,6 +54,7 @@ class RithmicOrderApi(RithmicBaseApi):
Rithmic Order API For the ORDER PLANT to submit orders, cancel orders, modify orders and receive fills
"""
infra_type = request_login_pb2.RequestLogin.SysInfraType.ORDER_PLANT
api_type = ApiType.ORDER

def __init__(self, env: RithmicEnvironment = None, callback_manager: CallbackManager = None, loop=None,
auto_connect: bool = True, recovered_status_manager: StatusManager = None):
Expand Down Expand Up @@ -108,6 +110,7 @@ def connect_and_login(self) -> None:
logged_in = super(RithmicOrderApi, self).connect_and_login()
future = asyncio.run_coroutine_threadsafe(self._get_login_info(), loop=self.loop)
log_in_details = future.result()
logger.info('Order API Extended Login Details => {0}'.format(log_in_details))
self._set_log_in_details(log_in_details)
self._run_update_subscription()

Expand Down
2 changes: 2 additions & 0 deletions src/rithmic/interfaces/ticker/ticker_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from rithmic.protocol_buffers.last_trade_pb2 import LastTrade
from rithmic.protocol_buffers.response_front_month_contract_pb2 import ResponseFrontMonthContract
from rithmic.tools.general import dict_destructure, set_index_no_name
from rithmic.tools.meta import ApiType
from rithmic.tools.pyrithmic_exceptions import WebsocketClosedException, MissingCustomCallback
from rithmic.tools.pyrithmic_logger import logger, configure_logging

Expand Down Expand Up @@ -113,6 +114,7 @@ class RithmicTickerApi(RithmicBaseApi):
Rithmic Ticker API For the TICKER PLANT to stream live tick data
"""
infra_type = request_login_pb2.RequestLogin.SysInfraType.TICKER_PLANT
api_type = ApiType.TICKER

def __init__(self, env: RithmicEnvironment = None, callback_manager: CallbackManager = None,
auto_connect: bool = True, loop=None, periodic_sync_interval_seconds: float = 0.1):
Expand Down
10 changes: 10 additions & 0 deletions src/rithmic/tools/meta.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import enum


class ApiType(enum.Enum):
ORDER = 'ORDER'
TICKER = 'TICKER'
HISTORY = 'HISTORY'

def __repr__(self):
return self.value

0 comments on commit 36c0cd8

Please sign in to comment.