mirror of
https://github.com/payden/libwsclient
synced 2026-03-02 04:09:18 +00:00
feat : add strategy
This commit is contained in:
26
api/flipside.rs
Normal file
26
api/flipside.rs
Normal file
@@ -0,0 +1,26 @@
|
||||
pub struct FlipsideApi {
|
||||
pub api_key: String,
|
||||
pub api_url: String,
|
||||
}
|
||||
|
||||
impl FlipsideApi {
|
||||
pub fn new(api_key: String, api_url: String) -> Self {
|
||||
FlipsideApi {
|
||||
api_key,
|
||||
api_url,
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn get_token_volume(&self, token_mint: &str) -> Result<f64, reqwest::Error> {
|
||||
let url = format!("{}/volume?token_mint={}", self.api_url, token_mint);
|
||||
let client = reqwest::Client::new();
|
||||
let response = client
|
||||
.get(&url)
|
||||
.header("Authorization", &self.api_key)
|
||||
.send()
|
||||
.await?;
|
||||
|
||||
let volume: f64 = response.json().await?;
|
||||
Ok(volume)
|
||||
}
|
||||
}
|
||||
3
api/mod.rs
Normal file
3
api/mod.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
pub mod parsec;
|
||||
pub mod flipside;
|
||||
pub mod thegraph;
|
||||
26
api/parsec.rs
Normal file
26
api/parsec.rs
Normal file
@@ -0,0 +1,26 @@
|
||||
pub struct ParsecApi {
|
||||
pub api_key: String,
|
||||
pub api_url: String,
|
||||
}
|
||||
|
||||
impl ParsecApi {
|
||||
pub fn new(api_key: String, api_url: String) -> Self {
|
||||
ParsecApi {
|
||||
api_key,
|
||||
api_url,
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn get_token_prices(&self) -> Result<HashMap<String, f64>, reqwest::Error> {
|
||||
let url = format!("{}/prices", self.api_url);
|
||||
let client = reqwest::Client::new();
|
||||
let response = client
|
||||
.get(&url)
|
||||
.header("Authorization", &self.api_key)
|
||||
.send()
|
||||
.await?;
|
||||
|
||||
let prices: HashMap<String, f64> = response.json().await?;
|
||||
Ok(prices)
|
||||
}
|
||||
}
|
||||
35
api/telegraph.rs
Normal file
35
api/telegraph.rs
Normal file
@@ -0,0 +1,35 @@
|
||||
pub struct TheGraphApi {
|
||||
pub api_url: String,
|
||||
}
|
||||
|
||||
impl TheGraphApi {
|
||||
pub fn new(api_url: String) -> Self {
|
||||
TheGraphApi {
|
||||
api_url,
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn get_trader_transactions(&self, trader_account: &str) -> Result<Vec<crate::models::trade::Trade>, reqwest::Error> {
|
||||
let query = format!("{{ traderTransactions(trader: \"{}\") {{ id tokenAmount tokenMint }} }}", trader_account);
|
||||
let client = reqwest::Client::new();
|
||||
let response = client
|
||||
.post(&self.api_url)
|
||||
.json(&serde_json::json!({ "query": query }))
|
||||
.send()
|
||||
.await?;
|
||||
|
||||
let result: serde_json::Value = response.json().await?;
|
||||
let transactions = result["data"]["traderTransactions"]
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.map(|trade| crate::models::trade::Trade {
|
||||
id: trade["id"].as_str().unwrap().to_string(),
|
||||
token_amount: trade["tokenAmount"].as_f64().unwrap(),
|
||||
token_mint: trade["tokenMint"].as_str().unwrap().to_string(),
|
||||
})
|
||||
.collect();
|
||||
|
||||
Ok(transactions)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user