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

[Futures] update API and fix simulator #1126

Merged
merged 10 commits into from
Dec 4, 2024
Merged

[Futures] update API and fix simulator #1126

merged 10 commits into from
Dec 4, 2024

Conversation

GuillaumeDSM
Copy link
Member

No description provided.

@GuillaumeDSM GuillaumeDSM requested a review from Herklos November 16, 2024 22:05
@GuillaumeDSM GuillaumeDSM self-assigned this Nov 16, 2024
@GuillaumeDSM GuillaumeDSM force-pushed the futures branch 4 times, most recently from d16d9b6 to 3ab2064 Compare November 23, 2024 09:15
@GuillaumeDSM GuillaumeDSM force-pushed the futures branch 4 times, most recently from 4abe237 to 893f561 Compare November 28, 2024 23:36
@GuillaumeDSM GuillaumeDSM changed the title WIP [Futures] add contract dict [Futures] add contract dict Nov 30, 2024
@GuillaumeDSM GuillaumeDSM changed the title [Futures] add contract dict [Futures] update API and fix simulator Nov 30, 2024
@GuillaumeDSM GuillaumeDSM marked this pull request as ready for review November 30, 2024 18:38
else enums.PositionMode.ONE_WAY
)
if position_mode is enums.PositionMode.HEDGE:
# todo when handling helge positions
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
# todo when handling helge positions
# todo when handling hedge positions

😉

Copy link
Member Author

Choose a reason for hiding this comment

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

😮 indeed, thanks

raise NotImplementedError(amount_type)
if context.exchange_manager.is_future:
if position_kw.is_in_one_way_position_mode(context):
# use abs() since short positions have negative size
Copy link
Member

Choose a reason for hiding this comment

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

👍

Comment on lines -251 to +249
decimal.Decimal("16.66666666666666666666666667")
decimal.Decimal("116.6666666666666666666666667")
Copy link
Member

Choose a reason for hiding this comment

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

Can you please explain this change? A price change has no impact in the bankruptcy price? (this test seems to have a 20 price and the second one has a 100 price and the bankruptcy price does not change)

Copy link
Member Author

@GuillaumeDSM GuillaumeDSM Dec 1, 2024

Choose a reason for hiding this comment

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

Right it does not change compared the the next line because with_mark_price=True so we use the position mark_price and not the given price arguement.
The previous value was due to a mistake in the ternary operator in get_bankruptcy_price impl

Comment on lines -251 to +249
decimal.Decimal("16.66666666666666666666666667")
decimal.Decimal("116.6666666666666666666666667")
Copy link
Member Author

@GuillaumeDSM GuillaumeDSM Dec 1, 2024

Choose a reason for hiding this comment

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

Right it does not change compared the the next line because with_mark_price=True so we use the position mark_price and not the given price arguement.
The previous value was due to a mistake in the ternary operator in get_bankruptcy_price impl

@@ -217,13 +217,11 @@ async def test_get_bankruptcy_price_with_long(future_trader_simulator_with_defau
assert position_inst.get_bankruptcy_price(position_inst.entry_price, position_inst.side, with_mark_price=True) == decimal.Decimal(50)
default_contract.set_current_leverage(constants.ONE_HUNDRED)
assert position_inst.get_bankruptcy_price(position_inst.entry_price, position_inst.side) == decimal.Decimal("99.00990099009900990099009901")
assert position_inst.get_bankruptcy_price(position_inst.entry_price, position_inst.side, with_mark_price=True) == decimal.Decimal("0.9900990099009900990099009901")
assert position_inst.get_bankruptcy_price(position_inst.entry_price, position_inst.side, with_mark_price=True) == decimal.Decimal('99.00990099009900990099009901')
await position_inst.update(update_size=constants.ONE_HUNDRED,
mark_price=decimal.Decimal(2) * constants.ONE_HUNDRED)
assert position_inst.get_bankruptcy_price(position_inst.entry_price, position_inst.side) == decimal.Decimal("99.00990099009900990099009901")
Copy link
Member Author

Choose a reason for hiding this comment

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

here is an example of a bankruptcy_price that changes according to the given price (with_mark_price is unset and therefore false by default, we get a different price from the next line)

Copy link
Member

@Herklos Herklos left a comment

Choose a reason for hiding this comment

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

👍

@GuillaumeDSM GuillaumeDSM merged commit b288de2 into master Dec 4, 2024
6 checks passed
@GuillaumeDSM GuillaumeDSM deleted the futures branch December 4, 2024 09:33
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.

2 participants