-
Notifications
You must be signed in to change notification settings - Fork 23
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
Conversation
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.
0f97fdc
to
47b7079
Compare
@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. |
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
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. |
47b7079
to
b869ed0
Compare
We should probably introduce a `Quantity` type if we want to support different contracts. For now, a contract equals $1, hence, USD is correct.
b869ed0
to
3b01f7d
Compare
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.
3b01f7d
to
6f062b5
Compare
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. |
@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). |
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.
@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?
closed in favor of #2316 |
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