8000 Added more information for a orderbook by Unt3r · Pull Request #136 · Qluxzz/avanza · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

Unt3r
Copy link
Contributor
@Unt3r Unt3r commented Mar 13, 2025

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)

return value  # return original price if no tick size is found

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)

Unt3r added 2 commits March 13, 2025 19:46
Added route to ORDERBOOK_PATH
Added get_orderbook
Copy link
Contributor
@wenrir wenrir left a 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 ):

Copy link
Contributor

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 ):
Copy link
Contributor

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

Copy link
Owner

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 ):
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
def get_orderbook(self, order_book_id: str ):
def get_orderbook(self, order_book_id: str):

Copy link
Contributor

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]:

Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0