-
Notifications
You must be signed in to change notification settings - Fork 50
Added more information for a orderbook #136
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: master
Are you sure you want to change the base?
Conversation
Added route to ORDERBOOK_PATH
Added get_orderbook
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.
Some comments, please only consider the ones you find relevant. Thank you for your consideration.
@@ -451,6 +451,13 @@ def get_order_books(self, order_book_ids: Sequence[str]) -> List[OrderBook]: | |||
HttpMethod.GET, | |||
Route.ORDERBOOK_LIST_PATH.value.format(",".join(order_book_ids)), | |||
) | |||
|
|||
def get_orderbook(self, order_book_id: str ): | |||
|
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.
Could you please add a function description? Similar to on line 448
@@ -451,6 +451,13 @@ def get_order_books(self, order_book_ids: Sequence[str]) -> List[OrderBook]: | |||
HttpMethod.GET, | |||
Route.ORDERBOOK_LIST_PATH.value.format(",".join(order_book_ids)), | |||
) | |||
|
|||
def get_orderbook(self, order_book_id: str ): |
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.
Additionally this might be a question for @Qluxzz, do we want to name it get_orderbook
or get_order_book
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.
Since order book is two words it should be get_order_book
@@ -451,6 +451,13 @@ def get_order_books(self, order_book_ids: Sequence[str]) -> List[OrderBook]: | |||
HttpMethod.GET, | |||
Route.ORDERBOOK_LIST_PATH.value.format(",".join(order_book_ids)), | |||
) | |||
|
|||
def get_orderbook(self, order_book_id: str ): |
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.
def get_orderbook(self, order_book_id: str ): | |
def get_orderbook(self, order_book_id: str): |
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.
Also please consider adding return type as in other functions e.g. -> List[OrderBook]:
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.
You (@Unt3r) mentioned that among other things the tick size is also returned. Does the other things in the response correspond to the existing Orderbook model?
Easiest way to validate that is to write a test for the method, it will then say what fields (if any) are missing or has invalid values.
Added more information about an orderbook.
Among some other things a tickSizeList is returned.
'tickSizeList': {
'tickSizeEntries': [
{'min': 0.0, 'max': 0.0998, 'tick': 0.0002},
...
{'min': 0.1, 'max': 0.1995, 'tick': 0.0005},
]
}
It can be used to make sure a correct price is set for an order.
If made a function (round_price_to_tick_size) for that.
def round_price_to_tick_size(tick_size_list, price, round_type="nearest"):
for entry in tick_size_list['tickSizeEntries']:
if entry['min'] <= price <= entry['max'] + entry['tick']:
tick = entry['tick']
decimal_places = len(str(tick).split('.')[1])
if round_type == 'up':
rounded_value = math.ceil(price / tick) * tick # round up to tick size
elif round_type == 'down':
rounded_value = math.floor(price / tick) * tick # round down to tick size
else:
rounded_value = round(price / tick) * tick # default round to the nearest tick size
return round(rounded_value, decimal_places)
I don't know if it should be added to the project?
In that case where?
With the function the following can be done:
ob = avanza.get_orderbook(861076)
tsl = ob["tickSizeList"]
round_price_to_tick_size(tsl, 13.16512345)
The function will return 13.15 (since it is traded in 0.05 ticks between 10 and 20)