-
Notifications
You must be signed in to change notification settings - Fork 69
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
introduce price feed server #10
Conversation
2ff5fdc
to
61203ce
Compare
61203ce
to
a685439
Compare
let asset_pair = (x, y); | ||
match prices.read().unwrap().get(&asset_pair) { | ||
Some(latest_price) => with_status(json(latest_price), StatusCode::OK), | ||
// TODO: how to 404 without content??? |
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.
yes, can respond 404 without content because oracle only has response.code != 200
check (https://github.com/ComposableFi/composable-node-beta/blob/main/pallets/oracle/src/lib.rs#L606)
.await | ||
.expect("connection to pyth-client failed"); | ||
|
||
// TODO: subscribe to all asset prices? cli configurable? |
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.
or can add subscription on a new asset by an oracle request
LGFM. |
Thanks! I merge this now and open a second PR for the integration with the oracle pallet! |
nice job! @hussein-aitlahcen |
# This is the 1st commit message: fetch depth # The commit message #2 will be skipped: # Update checkout action # The commit message #3 will be skipped: # Update checkout action # The commit message #4 will be skipped: # Update checkout action # The commit message #5 will be skipped: # Update checkout action # The commit message #6 will be skipped: # Update checkout action # The commit message #7 will be skipped: # Update checkout action # The commit message #8 will be skipped: # Update checkout action # The commit message #9 will be skipped: # Update checkout action # The commit message #10 will be skipped: # Update checkout action
# This is the 1st commit message: fetch depth # The commit message #2 will be skipped: # Update checkout action # The commit message #3 will be skipped: # Update checkout action # The commit message #4 will be skipped: # Update checkout action # The commit message #5 will be skipped: # Update checkout action # The commit message #6 will be skipped: # Update checkout action # The commit message #7 will be skipped: # Update checkout action # The commit message #8 will be skipped: # Update checkout action # The commit message #9 will be skipped: # Update checkout action # The commit message #10 will be skipped: # Update checkout action # The commit message #11 will be skipped: # Update checkout action # The commit message #12 will be skipped: # Update checkout action # The commit message #13 will be skipped: # Update checkout action # The commit message #14 will be skipped: # Update checkout action # The commit message #15 will be skipped: # Update checkout action # The commit message #16 will be skipped: # Update checkout action # The commit message #17 will be skipped: # Update checkout action
# This is the 1st commit message: lfs # This is the commit message #2: staging migration Signed-off-by: Dzmitry Lahoda <dzmitry@lahoda.pro> # This is the commit message #3: picasso # This is the commit message #4: yamlgit add .git add . # This is the commit message #5: fmt; reuse; clean Signed-off-by: Dzmitry Lahoda <dzmitry@lahoda.pro> # This is the commit message #6: trying replace nixops devnet # This is the commit message #7: fixed container # This is the commit message #8: zombies in compose # This is the commit message #9: getting routes # This is the commit message #10: ops mapping # This is the commit message #11: returned garbage for happy refactoring # This is the commit message #12: more # This is the commit message #13: revert
This PR will introduce the first draft of the price server we are going to use for the oracle pallet.
Assuming we have pairs of assets such as
BTC/USD
, we provide a HTTP endpointGET /price/BTC/USD
for the offchain worker.The returned object is of type
{ "timestamp": UNIXEPOCH, "value": price }
wheretimestamp
is the time at which the latest price notification has been received.Why not directly use the pythd websocket or any other source directly? The offchain worker are targeting WASM and pyth-client is written in C++. C++ FFI for Rust is not supported by WASM target. More than that, the offchain worker is only able to fire HTTP calls, not anything more sophisticated such as websocket...
The other side of the server is connected to
pyth-client
daemon and subscribe to price events for asset pairs. It only store the latest received (timestamped) price.Currently, the implementation handle only one feed, which is provided by the pyth daemon.
By default, I hardcoded the subscriptions because I don't know whether we want to make this thing more dynamic (perhaps cli option?).
When all the subscriptions are dropped, either because of network failure or because of pyth daemon, the server will gracefully exit; is this a desired behavior or should we make it crash?
If we want to handle multiple feeds, we will have to think about either merging the price directly at the server level (this involve some kind of synchronisation because for X feed, their latest price might be spaced by a bit of time?).
Finally, as you will notice, there is no tests yet... Because I don't really know how to test this kind of "networked" stuff (most of the code is synchronisation and networking stuff). Feel free to give me any advice :)!
NOTE:
If you want to test it out, you will have to use my patch of pyth-client, their JSONRPC implementation of subscription was... not common.
I provided a nix shell script inside the
price-feed
subdirectory that will make bothpythd
andpyth_tx
running locally.