Skip to content
Open
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
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ Steps to get started:

`account = Account(tradier_acct, tradier_token, live_trade=True)`

`equity_order = EquityOrder(tradier_acct, tradier_token, live_trade=True)`

`options_order = OptionsOrder(tradier_acct, tradier_token, live_trade=True)`

* If live trading is enabled, then you can utilize the `Stream` class to stream market events:

`stream = Stream(tradier_acct, tradier_token, live_trade=True)`
Expand Down Expand Up @@ -98,7 +102,19 @@ This section provides example functionality of the existing codebase. Additional

- Place Equity Order:

`order_response = equity_order.place_order('AAPL', 'buy', 1, 'limit', 150)`
`order_response = equity_order.order('QQQ', 'buy', 10, 'market', duration='gtc');`

- Check an Equity Order:

`order_status = equity_order.fetch(12345678)`

- Modify an Equity Order:

`mod_response = equity_order.modify(12345678, duration='gtc')`

- Delete an Equity Order:

`delete_response = equity_order.delete(1234567)`

- Place Options Order:

Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

setup(
name='uvatradier',
version='0.4.1',
version='0.4.2',
author='tom hammons',
description='wahoowa',
description='Ay Ziggy Zoomba',
long_description=long_description,
long_description_content_type='text/markdown',
url='https://github.com/thammo4/uvatradier',
Expand Down
2 changes: 1 addition & 1 deletion uvatradier/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
from .options_order import OptionsOrder
from .stream import Stream

print('wahoowa')
print('Ay Ziggy Zoomba')
100 changes: 95 additions & 5 deletions uvatradier/equity_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,115 @@


class EquityOrder (Tradier):
def __init__ (self, account_number, auth_token):
Tradier.__init__(self, account_number, auth_token);
def __init__ (self, account_number, auth_token, live_trade=False):
Tradier.__init__(self, account_number, auth_token, live_trade);

#
# Order endpoint
#

self.ORDER_ENDPOINT = "v1/accounts/{}/orders".format(self.ACCOUNT_NUMBER); # POST
def fetch(self, order_id):
'''
Arguments:
order_id = 12345678'

Example of how to run:
>>> eo = EquityOrder(ACCOUNT_NUMBER, AUTH_TOKEN)
>>> eo.fetch(12345678)
{'order': {
'id': 12345678,
'type': 'limit',
'symbol': 'QQQ',
'side': 'buy',
'quantity': 1.0,
'status': 'open',
'duration': 'post',
'price': 1.0,
'avg_fill_price': 0.0,
'exec_quantity': 0.0,
'last_fill_price': 0.0,
'last_fill_quantity': 0.0,
'remaining_quantity': 1.0,
'create_date': '2024-01-01T00:00:00.000Z',
'transaction_date': '2024-01-01T00:00:00.000Z',
'class': 'equity'
}
}
'''
r = requests.get(
url = '{}/{}/{}'.format(self.BASE_URL, self.ORDER_ENDPOINT, order_id),
headers = self.REQUESTS_HEADERS,
);
return r.json();

def order (self, symbol, side, quantity, order_type, duration='day', limit_price=False, stop_price=False):
def delete(self, order_id):
'''
Arguments:
order_id = 12345678'

Example of how to run:
>>> eo = EquityOrder(ACCOUNT_NUMBER, AUTH_TOKEN)
>>> eo.delete(12345678)
{'order': {'id': 12345678, 'status': 'ok'}}
'''
r = requests.delete(
url = '{}/{}/{}'.format(self.BASE_URL, self.ORDER_ENDPOINT, order_id),
headers = self.REQUESTS_HEADERS,
);
return r.json();

def modify(self, order_id, order_type=False, duration=False, limit_price=False, stop_price=False):
'''
Arguments:
order_id = 12345678'
order_type = ['market', 'limit', 'stop', 'stop_limit']
duration = ['day', 'gtc', 'pre', 'post']
limit_price = 1.0
stop_price = 1.0

Example of how to run:
>>> eo = EquityOrder(ACCOUNT_NUMBER, AUTH_TOKEN)
>>> eo.modify(12345678, limit_price=433.27)
{'order': {'id': 12345678, 'status': 'ok', 'partner_id': 'c4998eb7-06e8-4820-a7ab-55d9760065fb'}}
'''

#
# To modify an order user should only input fields that should be changed.
# Only send a field if it is reuqired and provided.
#

r_params = {};
if order_type is not False:
r_params['type'] = order_type
if duration is not False:
r_params['duration'] = duration
if limit_price is not False:
r_params['price'] = limit_price
if stop_price is not False:
r_params['stop'] = stop_price

r = requests.put(
url = '{}/{}/{}'.format(self.BASE_URL, self.ORDER_ENDPOINT, order_id),
headers = self.REQUESTS_HEADERS,
);
return r.json();

def order (self, symbol, side, quantity, order_type, duration='day', limit_price=False, stop_price=False, preview=False):
'''
Arguments:
symbol = Stock Ticker Symbol.
side = ['buy', 'buy_to_cover', 'sell', 'sell_short']
order_type = ['market', 'limit', 'stop', 'stop_limit']
duration = ['day', 'gtc', 'pre', 'post']
limit_price = 1.0
stop_price = 1.0
preview = True # https://documentation.tradier.com/brokerage-api/trading/preview-order

Example of how to run:
>>> eo = EquityOrder(ACCOUNT_NUMBER, AUTH_TOKEN)
>>> eo.order(symbol='QQQ', side='buy', quantity=10, order_type='market', duration='gtc');
{'order': {'id': 8256590, 'status': 'ok', 'partner_id': '3a8bbee1-5184-4ffe-8a0c-294fbad1aee9'}}
{'order': {'id': 8256590, 'status': 'ok', 'partner_id': 'c4998eb7-06e8-4820-a7ab-55d9760065fb'}}
'''

#
Expand All @@ -49,11 +137,13 @@ def order (self, symbol, side, quantity, order_type, duration='day', limit_price
r_params['price'] = limit_price;
if order_type.lower() in ['stop', 'stop_limit']:
r_params['stop'] = stop_price;
if preview:
r_params['preview'] = True

r = requests.post(
url = '{}/{}'.format(self.BASE_URL, self.ORDER_ENDPOINT),
params = r_params,
headers=self.REQUESTS_HEADERS
);

return r.json();
return r.json();
4 changes: 2 additions & 2 deletions uvatradier/quotes.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def get_quote_day (self, symbol, last_price=False):
print("YO! ... Second argument 'last_price' should be bool.");
if 'last' not in df_quote:
return f"No last price found: {symbol}.";
return float(df_quote['last']);
return float(df_quote['last'].iloc[0]);

return df_quote;

Expand Down Expand Up @@ -440,4 +440,4 @@ def search_companies (self, query):
if not r.json()['securities']:
return "Nothing found";

return pd.DataFrame(r.json()['securities']['security']);
return pd.DataFrame(r.json()['securities']['security']);
Loading