mirror of
https://github.com/floor-licker/polyfill-rs.git
synced 2026-08-22 17:08:07 +00:00
fix: borrow batch request bodies
This commit is contained in:
+31
-30
@@ -35,6 +35,17 @@ struct MarketByTokenResponse {
|
|||||||
condition_id: String,
|
condition_id: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
struct TokenRequest<'a> {
|
||||||
|
token_id: &'a str,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
struct PriceRequest<'a> {
|
||||||
|
token_id: &'a str,
|
||||||
|
side: &'a str,
|
||||||
|
}
|
||||||
|
|
||||||
fn polymarket_default_headers() -> HeaderMap {
|
fn polymarket_default_headers() -> HeaderMap {
|
||||||
let mut headers = HeaderMap::new();
|
let mut headers = HeaderMap::new();
|
||||||
headers.insert(
|
headers.insert(
|
||||||
@@ -429,13 +440,9 @@ impl ClobClient {
|
|||||||
&self,
|
&self,
|
||||||
token_ids: &[String],
|
token_ids: &[String],
|
||||||
) -> Result<std::collections::HashMap<String, Decimal>> {
|
) -> Result<std::collections::HashMap<String, Decimal>> {
|
||||||
let request_data: Vec<std::collections::HashMap<&str, String>> = token_ids
|
let request_data: Vec<TokenRequest<'_>> = token_ids
|
||||||
.iter()
|
.iter()
|
||||||
.map(|id| {
|
.map(|id| TokenRequest { token_id: id })
|
||||||
let mut map = std::collections::HashMap::new();
|
|
||||||
map.insert("token_id", id.clone());
|
|
||||||
map
|
|
||||||
})
|
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let response = self
|
let response = self
|
||||||
@@ -1613,13 +1620,9 @@ impl ClobClient {
|
|||||||
&self,
|
&self,
|
||||||
token_ids: &[String],
|
token_ids: &[String],
|
||||||
) -> Result<std::collections::HashMap<String, Decimal>> {
|
) -> Result<std::collections::HashMap<String, Decimal>> {
|
||||||
let request_data: Vec<std::collections::HashMap<&str, String>> = token_ids
|
let request_data: Vec<TokenRequest<'_>> = token_ids
|
||||||
.iter()
|
.iter()
|
||||||
.map(|id| {
|
.map(|id| TokenRequest { token_id: id })
|
||||||
let mut map = std::collections::HashMap::new();
|
|
||||||
map.insert("token_id", id.clone());
|
|
||||||
map
|
|
||||||
})
|
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let response = self
|
let response = self
|
||||||
@@ -1651,13 +1654,11 @@ impl ClobClient {
|
|||||||
&self,
|
&self,
|
||||||
book_params: &[crate::types::BookParams],
|
book_params: &[crate::types::BookParams],
|
||||||
) -> Result<std::collections::HashMap<String, std::collections::HashMap<Side, Decimal>>> {
|
) -> Result<std::collections::HashMap<String, std::collections::HashMap<Side, Decimal>>> {
|
||||||
let request_data: Vec<std::collections::HashMap<&str, String>> = book_params
|
let request_data: Vec<PriceRequest<'_>> = book_params
|
||||||
.iter()
|
.iter()
|
||||||
.map(|params| {
|
.map(|params| PriceRequest {
|
||||||
let mut map = std::collections::HashMap::new();
|
token_id: ¶ms.token_id,
|
||||||
map.insert("token_id", params.token_id.clone());
|
side: params.side.as_str(),
|
||||||
map.insert("side", params.side.as_str().to_string());
|
|
||||||
map
|
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
@@ -1682,13 +1683,9 @@ impl ClobClient {
|
|||||||
|
|
||||||
/// Get order book for multiple tokens (batch) - reference implementation compatible
|
/// Get order book for multiple tokens (batch) - reference implementation compatible
|
||||||
pub async fn get_order_books(&self, token_ids: &[String]) -> Result<Vec<OrderBookSummary>> {
|
pub async fn get_order_books(&self, token_ids: &[String]) -> Result<Vec<OrderBookSummary>> {
|
||||||
let request_data: Vec<std::collections::HashMap<&str, String>> = token_ids
|
let request_data: Vec<TokenRequest<'_>> = token_ids
|
||||||
.iter()
|
.iter()
|
||||||
.map(|id| {
|
.map(|id| TokenRequest { token_id: id })
|
||||||
let mut map = std::collections::HashMap::new();
|
|
||||||
map.insert("token_id", id.clone());
|
|
||||||
map
|
|
||||||
})
|
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let response = self
|
let response = self
|
||||||
@@ -1758,13 +1755,9 @@ impl ClobClient {
|
|||||||
|
|
||||||
/// Get last trade prices for multiple tokens
|
/// Get last trade prices for multiple tokens
|
||||||
pub async fn get_last_trade_prices(&self, token_ids: &[String]) -> Result<Value> {
|
pub async fn get_last_trade_prices(&self, token_ids: &[String]) -> Result<Value> {
|
||||||
let request_data: Vec<std::collections::HashMap<&str, String>> = token_ids
|
let request_data: Vec<TokenRequest<'_>> = token_ids
|
||||||
.iter()
|
.iter()
|
||||||
.map(|id| {
|
.map(|id| TokenRequest { token_id: id })
|
||||||
let mut map = std::collections::HashMap::new();
|
|
||||||
map.insert("token_id", id.clone());
|
|
||||||
map
|
|
||||||
})
|
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let response = self
|
let response = self
|
||||||
@@ -3014,6 +3007,9 @@ mod tests {
|
|||||||
|
|
||||||
let mock = server
|
let mock = server
|
||||||
.mock("POST", "/midpoints")
|
.mock("POST", "/midpoints")
|
||||||
|
.match_body(Matcher::JsonString(
|
||||||
|
r#"[{"token_id":"0x123"},{"token_id":"0x456"}]"#.to_string(),
|
||||||
|
))
|
||||||
.with_header("content-type", "application/json")
|
.with_header("content-type", "application/json")
|
||||||
.with_status(200)
|
.with_status(200)
|
||||||
.with_header("content-type", "application/json")
|
.with_header("content-type", "application/json")
|
||||||
@@ -3089,6 +3085,10 @@ mod tests {
|
|||||||
|
|
||||||
let mock = server
|
let mock = server
|
||||||
.mock("POST", "/prices")
|
.mock("POST", "/prices")
|
||||||
|
.match_body(Matcher::JsonString(
|
||||||
|
r#"[{"token_id":"0x123","side":"BUY"},{"token_id":"0x456","side":"SELL"}]"#
|
||||||
|
.to_string(),
|
||||||
|
))
|
||||||
.with_header("content-type", "application/json")
|
.with_header("content-type", "application/json")
|
||||||
.with_status(200)
|
.with_status(200)
|
||||||
.with_body(mock_response)
|
.with_body(mock_response)
|
||||||
@@ -3248,6 +3248,7 @@ mod tests {
|
|||||||
|
|
||||||
let mock = server
|
let mock = server
|
||||||
.mock("POST", "/books")
|
.mock("POST", "/books")
|
||||||
|
.match_body(Matcher::JsonString(r#"[{"token_id":"0x123"}]"#.to_string()))
|
||||||
.with_header("content-type", "application/json")
|
.with_header("content-type", "application/json")
|
||||||
.with_status(200)
|
.with_status(200)
|
||||||
.with_body(mock_response)
|
.with_body(mock_response)
|
||||||
|
|||||||
Reference in New Issue
Block a user