Skip to content

Commit

Permalink
Merge pull request calumrussell#71 from calumrussell/56-define-http-i…
Browse files Browse the repository at this point in the history
…nterface

56 define http interface
  • Loading branch information
calumrussell authored May 4, 2024
2 parents 1f10fb7 + df03fa9 commit 1dce966
Show file tree
Hide file tree
Showing 9 changed files with 479 additions and 184 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ serde = { version = "1.0.193", features = ["derive"] }
serde_json = "1.0.108"
env_logger = "0.11.0"
tokio = { version = "1.35.1", features = ["full"] }
derive_more = "0.99.17"

[dev-dependencies]
criterion = { version="0.5.1", features= ["async_tokio"] }
Expand Down
24 changes: 14 additions & 10 deletions src/bin/jura_server_v1.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::collections::HashMap;
use std::env;
use std::sync::Mutex;

Expand All @@ -14,19 +15,22 @@ async fn main() -> std::io::Result<()> {
let address: String = args[1].clone();
let port: u16 = args[2].parse().unwrap();

let app_state = web::Data::new(AppState {
exchange: Mutex::new(random_jura_generator(3000).0),
});
let jura = random_jura_generator(3000);
let mut datasets = HashMap::new();
datasets.insert("RANDOM".to_string(), jura.0);

let app_state = Mutex::new(AppState::create(&mut datasets));
let jura_state = web::Data::new(app_state);

HttpServer::new(move || {
App::new()
.app_data(app_state.clone())
.route("/", web::get().to(info))
.route("/init", web::get().to(init))
.route("/fetch_quotes", web::get().to(fetch_quotes))
.route("/tick", web::get().to(tick))
.route("/insert_order", web::post().to(insert_order))
.route("/delete_order", web::post().to(delete_order))
.app_data(jura_state.clone())
.service(info)
.service(init)
.service(fetch_quotes)
.service(tick)
.service(insert_order)
.service(delete_order)
})
.bind((address, port))?
.run()
Expand Down
10 changes: 7 additions & 3 deletions src/bin/uist_client_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ use rotala::http::uist::uistv1_client::Client;
#[tokio::main]
async fn main() -> Result<()> {
let client = Client::new("http://127.0.0.1:8080".to_string());
let _ = client.init().await.unwrap();
if let Ok(check) = client.tick().await {
let resp = client.init("RANDOM".to_string()).await.unwrap();
let backtest_id = resp.backtest_id;

if let Ok(check) = client.tick(backtest_id).await {
if check.has_next {
let _ = client.insert_order(Order::market_buy("ABC", 100.0)).await;
let _ = client
.insert_order(Order::market_buy("ABC", 100.0), backtest_id)
.await;
}
}
Ok(())
Expand Down
24 changes: 14 additions & 10 deletions src/bin/uist_server_v1.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::collections::HashMap;
use std::env;
use std::sync::Mutex;

Expand All @@ -14,19 +15,22 @@ async fn main() -> std::io::Result<()> {
let address: String = args[1].clone();
let port: u16 = args[2].parse().unwrap();

let app_state = web::Data::new(AppState {
exchange: Mutex::new(random_uist_generator(3000).0),
});
let uist = random_uist_generator(3000);
let mut datasets = HashMap::new();
datasets.insert("RANDOM".to_string(), uist.0);

let app_state = Mutex::new(AppState::create(&mut datasets));
let uist_state = web::Data::new(app_state);

HttpServer::new(move || {
App::new()
.app_data(app_state.clone())
.route("/", web::get().to(info))
.route("/init", web::get().to(init))
.route("/fetch_quotes", web::get().to(fetch_quotes))
.route("/tick", web::get().to(tick))
.route("/insert_order", web::post().to(insert_order))
.route("/delete_order", web::post().to(delete_order))
.app_data(uist_state.clone())
.service(info)
.service(init)
.service(fetch_quotes)
.service(tick)
.service(insert_order)
.service(delete_order)
})
.bind((address, port))?
.run()
Expand Down
6 changes: 3 additions & 3 deletions src/exchange/jura_v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ impl Order {
}
}

#[derive(Debug)]
#[derive(Clone, Debug)]
struct InnerOrder {
pub order_id: OrderId,
pub order: Order,
Expand Down Expand Up @@ -345,7 +345,7 @@ impl InfoMessage {
}
}

#[derive(Debug)]
#[derive(Clone, Debug)]
pub struct JuraV1 {
dataset: String,
clock: Clock,
Expand Down Expand Up @@ -469,7 +469,7 @@ impl JuraV1 {
/// After a trade executes a fill is returned to the user, the data returned is substantially
/// different to the Hyperliquid API due to Hyperliquid performing functions like margin.
/// The differences are documented in [Fill].
#[derive(Debug)]
#[derive(Clone, Debug)]
pub struct OrderBook {
inner: VecDeque<InnerOrder>,
last_inserted: u64,
Expand Down
4 changes: 2 additions & 2 deletions src/exchange/uist_v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ impl InfoMessage {
}
}

#[derive(Debug)]
#[derive(Clone, Debug)]
pub struct UistV1 {
dataset: String,
clock: Clock,
Expand Down Expand Up @@ -309,7 +309,7 @@ pub fn random_uist_generator(length: i64) -> (UistV1, Clock) {
(UistV1::new(clock.clone(), penelope, "RANDOM"), clock)
}

#[derive(Debug)]
#[derive(Clone, Debug)]
pub struct OrderBook {
inner: VecDeque<Order>,
last_inserted: u64,
Expand Down
Loading

0 comments on commit 1dce966

Please sign in to comment.