-
Notifications
You must be signed in to change notification settings - Fork 0
Sourcery refactored main branch #1
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines
|
||
|
|
||
| # Market parms | ||
| # min / max / std | ||
|
|
@@ -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): | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| sell = new_book[1] | ||
| buy = buy[1:] | ||
| else: | ||
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| def run(routes, host = '0.0.0.0', port = 8080): | ||
| """ Runs a class as a server whose methods have been decorated with | ||
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| 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() | ||
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| return [{ | ||
| 'id': x and x.get('id', None), | ||
| 'stock': 'ABC', | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines
|
||
|
|
||
| # Market parms | ||
| # min / max / std | ||
|
|
@@ -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): | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| sell = new_book[1] | ||
| buy = buy[1:] | ||
| else: | ||
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| def run(routes, host = '0.0.0.0', port = 8080): | ||
| """ Runs a class as a server whose methods have been decorated with | ||
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| 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() | ||
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| return [{ | ||
| 'id': x and x.get('id', None), | ||
| 'stock': 'ABC', | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines
|
||
|
|
||
| # Market parms | ||
| # min / max / std | ||
|
|
@@ -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): | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| sell = new_book[1] | ||
| buy = buy[1:] | ||
| else: | ||
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| def run(routes, host = '0.0.0.0', port = 8080): | ||
| """ Runs a class as a server whose methods have been decorated with | ||
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| 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() | ||
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| return [{ | ||
| 'id': x and x.get('id', None), | ||
| 'stock': 'ABC', | ||
|
|
||
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.
Lines
62-64refactored with the following changes:replace-interpolation-with-fstring)