Let's go through a series of #Rust pop-quizforszexen to build an application that reads an order book, and given the exchange rate of the token, computes burn arbitrage ROI and APR, shall we?
1. Read from a REST endpoint
Query
#Rust ./burn pop-quiz #1:
Write a Rust program that reads from a REST endpoint and simply writes out what it read.
An example endpoint is, oh, say, ... https://api.kujira.app/api/coingecko/orderbook?ticker_id=stATOM_ATOM&depth=10
Response
#Rust ./burn pop-answer #1:
Here's the code that reads from a REST endpoint.
Unfortunately, for me, all I get is a façade HTML-response, when I'm expecting JSON,
...so I'm going to go with a file-based approach going forward. Oh, well.
I'm doin' me.
2. read a file
Query
#Rust ./burn pop-quiz #2:
From a file, read the file, and like, print it, ... and stuff.
You can use ./data/ampLUNA_USK.json as the sample file, if you'd like.
Pass in the order book name as an argument. Use whichever libraries you like.
That's it. That's the quiz.
Response
#Rust ./burn pop-answer #2:
Here's how to read from a file in Rust.
I use the libraries I've created for my Rust book.
I find these useful for my day-to-day Rust-programming. Check them out!
3. Parse JSON
Query
#Rust ./burn pop-quiz #3:
Okay, let's get BIZY!
Study the JSON. Come up with a data structure, or data structures, that represent quotes and amounts that is the asks and bids of an order book.
THEN
Study JSON-converstion tools in Rust. Read in an order book JSON and print it.
Response
#Rust pop-answer #3:
entries.rs is the data structure and JSON-parser.
parse_json.rs runs the program.
There quite a bit going on here. Look over the code. Feel free to ask questions.
But here is it! Order Book!
4. computation
Query
#Rust pop-quiz #4: some maths
Now that we have the order book, let's do something with it, eh?
Given the order book and the amount to buy with, return the amount bought and the price computed per token.
Something like:
- From 10 USK, I bought 5.2248 ampLUNA, quote: 1.9140
Side note: I make one little change to my repository and all Hell breaks loose!
Admittedly, it's a change to my list_utils-module, that I use everywhere, but still! 😤
Response
The solution come about in entry.rs, primarily in the buy-function.
./buy runs the program, thus we have a program that computes buys on @TeamKujira FIN order books.
5. sine qua non: burn ROI and APR
Query
Rust ./burn pop-quiz #5
For the pièce de resistance, the sine qua non:
Given the above, AND given the exchange rate and burn rate of a token (usually an LSD ('Liquid Staking Derivative')), compute the ROI AND the APR from buying the LSD off FIN then burning it on the protocol.
Response
Rust ./burn pop-answer #5
You input the order book JSON and the LSD-data, and you get back an ROI and APR to buy-then-burn the LSD
LSD: liquid staking derivative.
No comments:
Post a Comment