-
Notifications
You must be signed in to change notification settings - Fork 188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tradier: new broker and data_source skeleton code added along with in… #325
Conversation
…itial unit tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Korbit AI Mentor has reviewed your code. To discuss an issue, reply using the tag @korbit-ai-mentor.
Please leave a 👍 if this is helpful and 👎 if it is irrelevant.
def validate_credentials(self): | ||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The validate_credentials
method is currently empty. It's important to implement this method to ensure that the provided API token and account ID are valid before making any API calls.
def validate_credentials(self): | |
pass | |
def validate_credentials(self): | |
response = requests.get(self._tradier_base_url + '/v1/user/profile', headers={'Authorization': 'Bearer ' + self._tradier_api_key}) | |
if response.status_code != 200: | |
raise TradierAPIError('Invalid Tradier Credentials') |
def __init__(self, account_id, api_key, paper=True, max_workers=20): | ||
super().__init__(api_key=api_key) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The class 'TradierData' inherits from 'DataSource' but does not call the parent constructor with all the necessary arguments. The parent constructor requires 'name' and 'config' arguments which are not provided in the child class constructor.
def __init__(self, account_id, api_key, paper=True, max_workers=20): | |
super().__init__(api_key=api_key) | |
def __init__(self, account_id, api_key, paper=True, max_workers=20): | |
name = 'TradierData' | |
config = {'account_id': account_id, 'api_key': api_key, 'paper': paper, 'max_workers': max_workers} | |
super().__init__(name=name, config=config) |
def cancel_order(self, order: Order): | ||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cancel_order
method is currently empty. This method should be implemented to allow users to cancel orders.
def cancel_order(self, order: Order): | |
pass | |
def cancel_order(self, order: Order): | |
response = requests.delete(self._tradier_base_url + '/v1/accounts/' + self._tradier_account_id + '/orders/' + order.id, headers={'Authorization': 'Bearer ' + self._tradier_api_key}) | |
if response.status_code != 200: | |
raise TradierAPIError('Failed to cancel order') |
def _submit_order(self, order: Order): | ||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The _submit_order
method is currently empty. This method should be implemented to allow users to submit orders.
def _submit_order(self, order: Order): | |
pass | |
def _submit_order(self, order: Order): | |
data = {'class': order.order_class, 'symbol': order.symbol, 'side': order.side, 'quantity': order.quantity, 'type': order.order_type} | |
response = requests.post(self._tradier_base_url + '/v1/accounts/' + self._tradier_account_id + '/orders', headers={'Authorization': 'Bearer ' + self._tradier_api_key}, data=data) | |
if response.status_code != 201: | |
raise TradierAPIError('Failed to submit order') |
def _get_balances_at_broker(self, quote_asset: Asset) -> float: | ||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The _get_balances_at_broker
method is currently empty. This method should be implemented to allow users to retrieve their account balance.
def _get_balances_at_broker(self, quote_asset: Asset) -> float: | |
pass | |
def _get_balances_at_broker(self, quote_asset: Asset) -> float: | |
response = requests.get(self._tradier_base_url + '/v1/accounts/' + self._tradier_account_id + '/balances', headers={'Authorization': 'Bearer ' + self._tradier_api_key}) | |
if response.status_code != 200: | |
raise TradierAPIError('Failed to get account balance') | |
return float(response.json()['equity']) |
def get_historical_account_value(self): | ||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The get_historical_account_value
method is currently empty. This method should be implemented to allow users to retrieve their historical account value.
def get_historical_account_value(self): | |
pass | |
def get_historical_account_value(self): | |
response = requests.get(self._tradier_base_url + '/v1/accounts/' + self._tradier_account_id + '/history', headers={'Authorization': 'Bearer ' + self._tradier_api_key}) | |
if response.status_code != 200: | |
raise TradierAPIError('Failed to get historical account value') | |
return response.json()['history'] |
class TestTradierData: | ||
def test_basics(self): | ||
tdata = TradierData(account_id="1234", api_key="a1b2c3", paper=True) | ||
assert tdata._account_id == "1234" | ||
|
||
|
||
class TestTradierBroker: | ||
def test_basics(self): | ||
broker = Tradier(account_id="1234", api_token="a1b2c3", paper=True) | ||
assert broker.name == "Tradier" | ||
assert broker._tradier_account_id == "1234" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
class TestTradierData: | ||
def test_basics(self): | ||
tdata = TradierData(account_id="1234", api_key="a1b2c3", paper=True) | ||
assert tdata._account_id == "1234" | ||
|
||
|
||
class TestTradierBroker: | ||
def test_basics(self): | ||
broker = Tradier(account_id="1234", api_token="a1b2c3", paper=True) | ||
assert broker.name == "Tradier" | ||
assert broker._tradier_account_id == "1234" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
""" | ||
Broker that connects to Tradier API to place orders and retrieve data | ||
""" | ||
def __init__(self, account_id=None, api_token=None, paper=True, config=None, max_workers=20, connect_stream=True, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert tdata._account_id == "1234" | ||
|
||
|
||
class TestTradierBroker: | ||
def test_basics(self): | ||
broker = Tradier(account_id="1234", api_token="a1b2c3", paper=True) | ||
assert broker.name == "Tradier" | ||
assert broker._tradier_account_id == "1234" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from .tradier_data import ( | ||
TRADIER_LIVE_API_URL, | ||
TRADIER_PAPER_API_URL, | ||
TRADIER_STREAM_API_URL, | ||
TradierAPIError, | ||
TradierData, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The import statements for the Tradier API URLs (TRADIER_LIVE_API_URL, TRADIER_PAPER_API_URL, TRADIER_STREAM_API_URL) might not be necessary in this file. If these constants are only used in the TradierData class, they should be imported there instead. This would keep the __init__.py
file cleaner and more focused on its main purpose of making the necessary classes and functions available for import from the lumibot.data_sources
package.
from .tradier_data import ( | |
TRADIER_LIVE_API_URL, | |
TRADIER_PAPER_API_URL, | |
TRADIER_STREAM_API_URL, | |
TradierAPIError, | |
TradierData, | |
) | |
from .tradier_data import ( | |
TradierAPIError, | |
TradierData | |
) |
from .tradier_data import ( | ||
TRADIER_LIVE_API_URL, | ||
TRADIER_PAPER_API_URL, | ||
TRADIER_STREAM_API_URL, | ||
TradierAPIError, | ||
TradierData, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from .tradier_data import ( | ||
TRADIER_LIVE_API_URL, | ||
TRADIER_PAPER_API_URL, | ||
TRADIER_STREAM_API_URL, | ||
TradierAPIError, | ||
TradierData, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
…itial unit tests.