-
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
feat: Automatically rollover in rollover weekend #1287
Conversation
c6facee
to
c8471c5
Compare
b3e651e
to
55ba6e5
Compare
55ba6e5
to
ccccf3b
Compare
c8471c5
to
27b3cc3
Compare
e300836
to
501372e
Compare
325e32f
to
08ce864
Compare
93fe42c
to
1fc5e84
Compare
08ce864
to
f21358c
Compare
9658824
to
d90d44e
Compare
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.
I'm confused about rollovers being driven by the orderbook.
Even though the coordinator circumstantially contains the orderbook, I don't think the orderbook has anything to do with rollovers. This is the flow that I see:
- Trader creates market order.
- Orderbook matches against limit order.
- Coordinator executes order with trader (and maker), creating a position with expiry (because of technical limitations).
- As the position expiry approaches, the trader has a chance to extend the lifetime of the position by rolling over. If they don't, the coordinator places an order on their behalf. If they do opt to roll over, nothing happens on the orderbook.
7fbb639
to
bc18260
Compare
b6cd302
to
bbd5ca2
Compare
@luckysori I've split up the responsibilities of the trading module in to separate modules. Please have a look at b6cd302 and let me know what you think! |
Without that fix we were updating all positions of the user!
Before everything was handled by the trading module. Now the following responsibilities have been split up. - Rollover: Moved to the coordinator component and responsible for proposing a rollover. - Async Match: Moved into a dedicated component to check if an async match needs to be executed by the app. - Notification: Responsible for the users and sending messages to them. Note 1, the websocket communication is still in one component and not separated between coordinator and orderbook. It would have been correct to split that up as well, but the effort and additional complexity was IMHO not worth it. Note 2, we have multiple commons crates, which are very much related to each ohter. I think we should combine all of those into a single one, to simplify things.
bbd5ca2
to
f3fa8db
Compare
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.
I appreciate the refactor!
let (_handle, notifier) = notification::start(tx_user_feed.clone()); | ||
|
||
let (_handle, trading_sender) = | ||
trading::start(pool.clone(), tx_price_feed.clone(), notifier.clone()); | ||
|
||
let _handle = async_match::monitor(pool.clone(), tx_user_feed.clone(), notifier.clone()); | ||
let _handle = rollover::monitor(pool.clone(), tx_user_feed.clone(), notifier); |
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.
❓ Doesn't the fact that you shadow _handle
cause the previous RemoteHandle
s to be dropped stopping the corresponding tasks?
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.
Btw, I think there is not much benefit to just returning the RemoteHandle
to "ignore" it. What you usually do with a RemoteHandle
is store in some other struct so that when you drop that one the corresponding task is cancelled.
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.
❓ Doesn't the fact that you shadow _handle cause the previous RemoteHandles to be dropped stopping the corresponding tasks?
Doesn't look like it. At least it worked during testing.
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.
Btw, I think there is not much benefit to just returning the RemoteHandle to "ignore" it. What you usually do with a RemoteHandle is store in some other struct so that when you drop that one the corresponding task is cancelled.
Well the reason I return it to the top level is so that the tasks live as long as the coordinator. That's why I am doing this, do you think that is not needed? Happy to remove it, but I think when I did, the compiler warned me about it.
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.
❓ Doesn't the fact that you shadow _handle cause the previous RemoteHandles to be dropped stopping the corresponding tasks?
Doesn't look like it. At least it worked during testing.
Confirmed it does not drop it: https://www.reddit.com/r/rust/comments/qpekne/what_actually_happens_when_ypu_shadow_a_variable/.
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.
Btw, I think there is not much benefit to just returning the RemoteHandle to "ignore" it. What you usually do with a RemoteHandle is store in some other struct so that when you drop that one the corresponding task is cancelled.
Well the reason I return it to the top level is so that the tasks live as long as the coordinator. That's why I am doing this, do you think that is not needed?
I guess because the coordinator is the whole program it isn't actually useful. It would be handy if we could remake the coordinator in case of catastrophic failure (without restarting the binary). Then you would want to cancel all the old tasks and restart them with a fresh coordinator struct.
Happy to remove it, but I think when I did, the compiler warned me about it.
That's probably because you called remote_handle
on the future and returned the RemoteHandle
which is marked as must_use
. You can obviously just spawn the future without doing any of that, but I don't mind if you wanna keep the current version.
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.
got ya. Since this PR is now open for quite some time. I prefer to go ahead with the current change, and adapt the remote_handle
stuff in a follow up PR.
We need to provide the current timestamp instead of the position expiry, as it would have been otherwise never eligible for rollover.
This change will automatically push the users dlc expiry to the next Sunday 15pm UTC if the user comes online within the rollover weekend (Friday, 15pm UTC - Sunday, 15pm UTC).
The video was taken with an adapted
get_expiry_timestamp
andis_in_rollover_weekend
logic to provoke the rollover.Simulator.Screen.Recording.-.iPhone.14.Pro.-.2023-09-12.at.14.27.54.mp4
resolves #1123