Skip to content
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

Adding protection when accessing order_id #7

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
36 changes: 22 additions & 14 deletions tick_taker.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,31 @@ def update_pending_sell_shares(self, quantity):
self.pending_sell_shares += quantity

def update_filled_amount(self, order_id, new_amount, side):
old_amount = self.orders_filled_amount[order_id]
if new_amount > old_amount:
if side == 'buy':
self.update_pending_buy_shares(old_amount - new_amount)
self.update_total_shares(new_amount - old_amount)
else:
self.update_pending_sell_shares(old_amount - new_amount)
self.update_total_shares(old_amount - new_amount)
self.orders_filled_amount[order_id] = new_amount
old_amount = self.orders_filled_amount.get(order_id)
if old_amount:
if new_amount > old_amount:
if side == 'buy':
self.update_pending_buy_shares(old_amount - new_amount)
self.update_total_shares(new_amount - old_amount)
else:
self.update_pending_sell_shares(old_amount - new_amount)
self.update_total_shares(old_amount - new_amount)
self.orders_filled_amount[order_id] = new_amount
else:
print(
f'Order ID: {order_id} not present on current orders.')

def remove_pending_order(self, order_id, side):
old_amount = self.orders_filled_amount[order_id]
if side == 'buy':
self.update_pending_buy_shares(old_amount - 100)
old_amount = self.orders_filled_amount.get(order_id)
if old_amount:
if side == 'buy':
self.update_pending_buy_shares(old_amount - 100)
else:
self.update_pending_sell_shares(old_amount - 100)
del self.orders_filled_amount[order_id]
else:
self.update_pending_sell_shares(old_amount - 100)
del self.orders_filled_amount[order_id]
print(
f'Order ID: {order_id} not present on current orders.')

def update_total_shares(self, quantity):
self.total_shares += quantity
Expand Down