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

Feature/BREAKING(app): introduce margin orders #2282

Closed
wants to merge 6 commits into from
Closed

Conversation

bonomat
Copy link
Contributor

@bonomat bonomat commented Mar 19, 2024

This patch introduces margin orders, i.e. a trader can define the margin they want to use for opening a order instead of defining the quantity.

Check commit messages for more details.

Overall I'm happy that it works but our code based really didn't make it easy to add this feature.

Let me know what you think, if deemed to brittle, I'm happy to drop this PR.

Simulator.Screen.Recording.-.iPhone.15.-.2024-03-19.at.21.05.44.mp4

We move the differentiation of the order type one level up by changing the api to handle an enum.

This way we can have different fields for different types of orders without having to have lots of nullable values, e.g. Market, Limit but also others such as Margin (which tells how much margin to use), StopLoss, TakeProfit, etc.
@holzeis
Copy link
Contributor

holzeis commented Mar 19, 2024

@bonomat is it necessary for the user to enter the margin? We had that in the past and it was very cumbersome to keep the quantity and the margin updated at the same time with the price updates.

Instead I was thinking of a simple max button that would (given the current leverage) max out the margin and update the quantity correspondingly. I guess we will not be able to do a complete max as the quantity will have to remain a full number, but its a simplification of the users process which is try and error with the input validation.

The original idea of #2139 was to help the user to do the biggest trade possible. I feel like adding the possibility to change the margin now, makes the UI again a bit more complex.

Maybe its not needed to be 100% correct, but only as close as our input validation.

@bonomat
Copy link
Contributor Author

bonomat commented Mar 20, 2024

@bonomat is it necessary for the user to enter the margin?

Not at all. We don't need to make it editable but the flow will be the same: instead of entering an amount into the margin field you click max. Same thing, just different color.

The original idea of #2139 was to help the user to do the biggest trade possible. I feel like adding the possibility to change the margin now, makes the UI again a bit more complex.

Let's discuss the UI changes at last please.

If we want this change I'd like to get it in fast because of all the files I had to touch.

We should probably introduce a `Quantity` type if we want to support different contracts. For now, a contract equals $1, hence, USD is correct.
This patch introduces margin orders, i.e. the mean to define a _market_ order based on the margin to be used and not the quantity as usual. The quantity is then being calculated once it's matched against one or more limit orders.

This patch also introduces fractional quantities. The better solution would have been to make the leverage a function of quantity and margin but that seemed to be a bigger task. Hence, fractional quantities it is.

The biggest challenge is that coordinator and trader agree on the rounding of the quantity if it can be fractional. I've defined it as 2 decimal places. If they are not aligned, we will at closing the position because the coordinator believe we want to resize the position.
@holzeis
Copy link
Contributor

holzeis commented Mar 20, 2024

Let's discuss the UI changes at last please.

If we want this change I'd like to get it in fast because of all the files I had to touch.

I am not referring solely to a UI change, I am questioning if we need a margin order. Can't we just max out the quantity in the same way we do the input validation. That might not be 100% correct (not the full possible margin) but will solve the users issue of going back and forth.

@bonomat
Copy link
Contributor Author

bonomat commented Mar 20, 2024

I am not referring solely to a UI change, I am questioning if we need a margin order. Can't we just max out the quantity in the same way we do the input validation. That might not be 100% correct (not the full possible margin) but will solve the users issue of going back and forth.

Right. I think a margin trade is a nice feature to have. Sometimes I just want to trade in sats and not USD terms.
If you max out the quantity you will always have some sats left in your channel.

@bonomat
Copy link
Contributor Author

bonomat commented Mar 21, 2024

@luckysori : what are your thoughts?

I'm slightly leaning towards letting this one go again (even though it did cost me a few hours to write).

Copy link
Contributor

@luckysori luckysori left a comment

Choose a reason for hiding this comment

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

@luckysori : what are your thoughts?

I'm slightly leaning towards letting this one go again (even though it did cost me a few hours to write).

I would say I am against margin orders now, given that the implementation is not that simple and that they don't seem all that reliable judging from your commit description. Also, I don't think it's a very important feature, because a user can relatively easily play around with the quantity to get reasonably close to their desired margin.

But I like the first 5 patches! Can we keep those?

@bonomat
Copy link
Contributor Author

bonomat commented Mar 25, 2024

closed in favor of #2316

@bonomat bonomat closed this Mar 25, 2024
@bonomat bonomat mentioned this pull request Mar 25, 2024
2 tasks
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