-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
107 additions
and
118 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,26 @@ | ||
[package] | ||
name = "hexstody-ticker-provider" | ||
name = "hexstody-ticker" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
hexstody-api = { path = "../hexstody-api" } | ||
hexstody-ticker-provider = { path = "../hexstody-ticker-provider" } | ||
hexstody-runtime-db = { path = "../hexstody-runtime-db" } | ||
schemars = { version = "0.8.8", features = ["chrono", "uuid"] } | ||
reqwest = { version = "0.11", features = [ "json" ] } | ||
serde = { version = "1.0", features = ["derive"] } | ||
serde_json = "1.0" | ||
thiserror = "1.0" | ||
log = "0.4.14" | ||
log = "0.4.14" | ||
rocket = { version = "=0.5.0-rc.2", default-features = false, features = [ | ||
"json", | ||
"uuid", | ||
] } | ||
rocket_okapi = { git = "https://github.com/GREsau/okapi", rev = "ddb07a709129b24ed8e106b0fbf576b6ded615ac", features = [ | ||
"rapidoc", | ||
"swagger", | ||
] } | ||
tokio = { version = "1", features = ["full"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
use std::sync::Arc; | ||
|
||
use hexstody_api::{ | ||
types::TickerETH, | ||
domain::{Currency, Fiat}}; | ||
use hexstody_api::error; | ||
use hexstody_runtime_db::RuntimeState; | ||
use hexstody_ticker_provider::client::TickerClient; | ||
use rocket::{post, State, Route, serde::json::Json}; | ||
use rocket_okapi::{openapi, openapi_get_routes, JsonSchema}; | ||
use serde::{Serialize, Deserialize}; | ||
use tokio::sync::Mutex; | ||
|
||
pub fn ticker_api() -> Vec<Route> { | ||
openapi_get_routes![ | ||
ticker, | ||
ticker_pair | ||
] | ||
} | ||
|
||
#[openapi(tag = "wallet")] | ||
#[post("/ticker", data = "<currency>")] | ||
pub async fn ticker( | ||
rstate: &State<Arc<Mutex<RuntimeState>>>, | ||
ticker_client: &State<TickerClient>, | ||
currency: Json<Currency>, | ||
) -> error::Result<Json<TickerETH>> { | ||
let currency = currency.into_inner(); | ||
let mut rstate = rstate.lock().await; | ||
let ticker: TickerETH = rstate | ||
.get_multifiat_ticker(ticker_client, currency, vec![Fiat::USD, Fiat::RUB]) | ||
.await | ||
.map_err(|e| error::Error::GenericError(e.to_string()))?; | ||
Ok(Json(ticker)) | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize, JsonSchema)] | ||
pub struct CurrencyPair { | ||
from: Currency, | ||
to: Currency | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize, JsonSchema)] | ||
pub struct CurrencyPairResponse{ | ||
from: Currency, | ||
to: Currency, | ||
rate: f64 | ||
} | ||
|
||
#[openapi(tag = "wallet")] | ||
#[post("/pair", data = "<currency_pair>")] | ||
pub async fn ticker_pair( | ||
rstate: &State<Arc<Mutex<RuntimeState>>>, | ||
ticker_client: &State<TickerClient>, | ||
currency_pair: Json<CurrencyPair>, | ||
) -> error::Result<Json<CurrencyPairResponse>> { | ||
let CurrencyPair{ from, to } = currency_pair.into_inner(); | ||
let mut rstate = rstate.lock().await; | ||
let rate = rstate | ||
.get_pair_ticker(ticker_client, from.clone(), to.clone()) | ||
.await | ||
.map_err(|e| error::Error::GenericError(e.to_string()))?; | ||
Ok(Json(CurrencyPairResponse{ from, to, rate })) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pub mod client; | ||
pub mod worker; | ||
pub mod api; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
pub async fn run_ticker_worker(){ | ||
} |