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
4 changes: 2 additions & 2 deletions JPMC-tech-task-1-py3/client3.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ def getRatio(price_a, price_b):
for quote in quotes:
stock, bid_price, ask_price, price = getDataPoint(quote)
prices[stock] = price
print ("Quoted %s at (bid:%s, ask:%s, price:%s)" % (stock, bid_price, ask_price, price))
print(f"Quoted {stock} at (bid:{bid_price}, ask:{ask_price}, price:{price})")

print ("Ratio %s" % getRatio(prices['ABC'], prices['DEF']))
print(f"Ratio {getRatio(prices['ABC'], prices['DEF'])}")
Comment on lines -62 to +64
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 62-64 refactored with the following changes:

33 changes: 17 additions & 16 deletions JPMC-tech-task-1-py3/server3.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

REALTIME = True
SIM_LENGTH = timedelta(days = 365 * 5)
MARKET_OPEN = datetime.today().replace(hour = 0, minute = 30, second = 0)
MARKET_OPEN = datetime.now().replace(hour = 0, minute = 30, second = 0)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 46-46 refactored with the following changes:


# Market parms
# min / max / std
Expand Down Expand Up @@ -117,8 +117,7 @@ def clear_book(buy = None, sell = None):
"""
while buy and sell:
order, size, _ = buy[0]
new_book = clear_order(order, size, sell)
if new_book:
if new_book := clear_order(order, size, sell):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function clear_book refactored with the following changes:

sell = new_book[1]
buy = buy[1:]
else:
Expand Down Expand Up @@ -191,16 +190,18 @@ def read_params(path):
def get(req_handler, routes):
""" Map a request to the appropriate route of a routes instance. """
for name, handler in routes.__class__.__dict__.items():
if hasattr(handler, "__route__"):
if None != re.search(handler.__route__, req_handler.path):
req_handler.send_response(200)
req_handler.send_header('Content-Type', 'application/json')
req_handler.send_header('Access-Control-Allow-Origin', '*')
req_handler.end_headers()
params = read_params(req_handler.path)
data = json.dumps(handler(routes, params)) + '\n'
req_handler.wfile.write(bytes(data, encoding = 'utf-8'))
return
if (
hasattr(handler, "__route__")
and re.search(handler.__route__, req_handler.path) != None
):
req_handler.send_response(200)
req_handler.send_header('Content-Type', 'application/json')
req_handler.send_header('Access-Control-Allow-Origin', '*')
req_handler.end_headers()
params = read_params(req_handler.path)
data = json.dumps(handler(routes, params)) + '\n'
req_handler.wfile.write(bytes(data, encoding = 'utf-8'))
return
Comment on lines -194 to +204
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get refactored with the following changes:


def run(routes, host = '0.0.0.0', port = 8080):
""" Runs a class as a server whose methods have been decorated with
Expand Down Expand Up @@ -236,8 +237,8 @@ class App(object):
""" The trading game server application. """

def __init__(self):
self._book_1 = dict()
self._book_2 = dict()
self._book_1 = {}
self._book_2 = {}
Comment on lines -239 to +241
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function App.__init__ refactored with the following changes:

self._data_1 = order_book(read_csv(), self._book_1, 'ABC')
self._data_2 = order_book(read_csv(), self._book_2, 'DEF')
self._rt_start = datetime.now()
Expand Down Expand Up @@ -281,7 +282,7 @@ def handle_query(self, x):
t1, bids1, asks1 = next(self._current_book_1)
t2, bids2, asks2 = next(self._current_book_2)
t = t1 if t1 > t2 else t2
print ('Query received @ t%s' % t)
print(f'Query received @ t{t}')
Comment on lines -284 to +285
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function App.handle_query refactored with the following changes:

return [{
'id': x and x.get('id', None),
'stock': 'ABC',
Expand Down
33 changes: 17 additions & 16 deletions JPMC-tech-task-2-PY3/datafeed/server3.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

REALTIME = True
SIM_LENGTH = timedelta(days = 365 * 5)
MARKET_OPEN = datetime.today().replace(hour = 0, minute = 30, second = 0)
MARKET_OPEN = datetime.now().replace(hour = 0, minute = 30, second = 0)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 46-46 refactored with the following changes:


# Market parms
# min / max / std
Expand Down Expand Up @@ -117,8 +117,7 @@ def clear_book(buy = None, sell = None):
"""
while buy and sell:
order, size, _ = buy[0]
new_book = clear_order(order, size, sell)
if new_book:
if new_book := clear_order(order, size, sell):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function clear_book refactored with the following changes:

sell = new_book[1]
buy = buy[1:]
else:
Expand Down Expand Up @@ -191,16 +190,18 @@ def read_params(path):
def get(req_handler, routes):
""" Map a request to the appropriate route of a routes instance. """
for name, handler in routes.__class__.__dict__.items():
if hasattr(handler, "__route__"):
if None != re.search(handler.__route__, req_handler.path):
req_handler.send_response(200)
req_handler.send_header('Content-Type', 'application/json')
req_handler.send_header('Access-Control-Allow-Origin', '*')
req_handler.end_headers()
params = read_params(req_handler.path)
data = json.dumps(handler(routes, params)) + '\n'
req_handler.wfile.write(bytes(data, encoding = 'utf-8'))
return
if (
hasattr(handler, "__route__")
and re.search(handler.__route__, req_handler.path) != None
):
req_handler.send_response(200)
req_handler.send_header('Content-Type', 'application/json')
req_handler.send_header('Access-Control-Allow-Origin', '*')
req_handler.end_headers()
params = read_params(req_handler.path)
data = json.dumps(handler(routes, params)) + '\n'
req_handler.wfile.write(bytes(data, encoding = 'utf-8'))
return
Comment on lines -194 to +204
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get refactored with the following changes:


def run(routes, host = '0.0.0.0', port = 8080):
""" Runs a class as a server whose methods have been decorated with
Expand Down Expand Up @@ -236,8 +237,8 @@ class App(object):
""" The trading game server application. """

def __init__(self):
self._book_1 = dict()
self._book_2 = dict()
self._book_1 = {}
self._book_2 = {}
Comment on lines -239 to +241
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function App.__init__ refactored with the following changes:

self._data_1 = order_book(read_csv(), self._book_1, 'ABC')
self._data_2 = order_book(read_csv(), self._book_2, 'DEF')
self._rt_start = datetime.now()
Expand Down Expand Up @@ -281,7 +282,7 @@ def handle_query(self, x):
t1, bids1, asks1 = next(self._current_book_1)
t2, bids2, asks2 = next(self._current_book_2)
t = t1 if t1 > t2 else t2
print ('Query received @ t%s' % t)
print(f'Query received @ t{t}')
Comment on lines -284 to +285
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function App.handle_query refactored with the following changes:

return [{
'id': x and x.get('id', None),
'stock': 'ABC',
Expand Down
33 changes: 17 additions & 16 deletions JPMC-tech-task-3-PY3/datafeed/server3.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

REALTIME = True
SIM_LENGTH = timedelta(days = 365 * 5)
MARKET_OPEN = datetime.today().replace(hour = 0, minute = 30, second = 0)
MARKET_OPEN = datetime.now().replace(hour = 0, minute = 30, second = 0)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 46-46 refactored with the following changes:


# Market parms
# min / max / std
Expand Down Expand Up @@ -117,8 +117,7 @@ def clear_book(buy = None, sell = None):
"""
while buy and sell:
order, size, _ = buy[0]
new_book = clear_order(order, size, sell)
if new_book:
if new_book := clear_order(order, size, sell):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function clear_book refactored with the following changes:

sell = new_book[1]
buy = buy[1:]
else:
Expand Down Expand Up @@ -191,16 +190,18 @@ def read_params(path):
def get(req_handler, routes):
""" Map a request to the appropriate route of a routes instance. """
for name, handler in routes.__class__.__dict__.items():
if hasattr(handler, "__route__"):
if None != re.search(handler.__route__, req_handler.path):
req_handler.send_response(200)
req_handler.send_header('Content-Type', 'application/json')
req_handler.send_header('Access-Control-Allow-Origin', '*')
req_handler.end_headers()
params = read_params(req_handler.path)
data = json.dumps(handler(routes, params)) + '\n'
req_handler.wfile.write(bytes(data, encoding = 'utf-8'))
return
if (
hasattr(handler, "__route__")
and re.search(handler.__route__, req_handler.path) != None
):
req_handler.send_response(200)
req_handler.send_header('Content-Type', 'application/json')
req_handler.send_header('Access-Control-Allow-Origin', '*')
req_handler.end_headers()
params = read_params(req_handler.path)
data = json.dumps(handler(routes, params)) + '\n'
req_handler.wfile.write(bytes(data, encoding = 'utf-8'))
return
Comment on lines -194 to +204
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get refactored with the following changes:


def run(routes, host = '0.0.0.0', port = 8080):
""" Runs a class as a server whose methods have been decorated with
Expand Down Expand Up @@ -236,8 +237,8 @@ class App(object):
""" The trading game server application. """

def __init__(self):
self._book_1 = dict()
self._book_2 = dict()
self._book_1 = {}
self._book_2 = {}
Comment on lines -239 to +241
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function App.__init__ refactored with the following changes:

self._data_1 = order_book(read_csv(), self._book_1, 'ABC')
self._data_2 = order_book(read_csv(), self._book_2, 'DEF')
self._rt_start = datetime.now()
Expand Down Expand Up @@ -281,7 +282,7 @@ def handle_query(self, x):
t1, bids1, asks1 = next(self._current_book_1)
t2, bids2, asks2 = next(self._current_book_2)
t = t1 if t1 > t2 else t2
print ('Query received @ t%s' % t)
print(f'Query received @ t{t}')
Comment on lines -284 to +285
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function App.handle_query refactored with the following changes:

return [{
'id': x and x.get('id', None),
'stock': 'ABC',
Expand Down