Align public token settings routes and missing-asset errors
This commit is contained in:
@@ -200,9 +200,17 @@ fn token_setting(
|
||||
.token_id
|
||||
.into(),
|
||||
};
|
||||
if token.trim().is_empty() {
|
||||
return Err(invalid);
|
||||
}
|
||||
let missing = if name == "fee-rate" {
|
||||
(404, "fee rate not found for market")
|
||||
} else {
|
||||
(404, "market not found")
|
||||
};
|
||||
let exchange = engine.lock().map_err(|_| (500, "Internal server error"))?;
|
||||
let unavailable = |e| match e {
|
||||
exchange::MarketDataError::Invalid(_) => invalid,
|
||||
exchange::MarketDataError::Invalid(_) => missing,
|
||||
exchange::MarketDataError::Unavailable => (500, "Internal server error"),
|
||||
};
|
||||
match name {
|
||||
@@ -210,21 +218,21 @@ fn token_setting(
|
||||
let flag = exchange
|
||||
.token_neg_risk(&token)
|
||||
.map_err(unavailable)?
|
||||
.ok_or((404, "market not found"))?;
|
||||
.ok_or(missing)?;
|
||||
Ok(json!({"neg_risk":flag}))
|
||||
}
|
||||
"fee-rate" => {
|
||||
let fee = exchange
|
||||
.base_fee_bps(&token)
|
||||
.map_err(unavailable)?
|
||||
.ok_or((404, "fee rate not found for market"))?;
|
||||
.ok_or(missing)?;
|
||||
Ok(json!({"base_fee":fee}))
|
||||
}
|
||||
_ => {
|
||||
let tick = exchange
|
||||
.minimum_tick_size(&token)
|
||||
.map_err(unavailable)?
|
||||
.ok_or((404, "market not found"))?;
|
||||
.ok_or(missing)?;
|
||||
Ok(json!({"minimum_tick_size":tick}))
|
||||
}
|
||||
}
|
||||
@@ -339,9 +347,8 @@ fn respond(mut req: Request, engine: &Mutex<Exchange>) -> std::io::Result<()> {
|
||||
let (name, segment) = route
|
||||
.split_once('/')
|
||||
.map_or((route, None), |(name, id)| (name, Some(id)));
|
||||
let is_setting = path == "/neg-risk"
|
||||
|| (matches!(name, "tick-size" | "fee-rate")
|
||||
&& !segment.is_some_and(|id| id.contains('/')));
|
||||
let is_setting = matches!(name, "neg-risk" | "tick-size" | "fee-rate")
|
||||
&& !segment.is_some_and(|id| id.contains('/'));
|
||||
let lookup = path
|
||||
.strip_prefix('/')
|
||||
.and_then(|p| p.split_once('/'))
|
||||
@@ -617,6 +624,9 @@ mod tests {
|
||||
let lookup_info = json!({"mbf":0,"tbf":30,"fd":{"r":0.05,"e":1,"to":true},"gst":null,"nr":false,"rfqe":false,"ibce":false,"oas":0,"mos":0.01,"mts":0.0025,
|
||||
"t":[{"o":"YES","t":"eb:YES:map+2/1"},{"o":"NO","t":"eb:NO:map+2/1"}]});
|
||||
for command in [
|
||||
json!({"op":"list","id":"rp-list","market":"resolved-params","rules":"resolved parameters","tick_size":"0.001","base_fees":{"maker_bps":0,"taker_bps":1000}}),
|
||||
json!({"op":"close","id":"rp-close","market":"resolved-params"}),
|
||||
json!({"op":"finalize","id":"rp-final","market":"resolved-params","winner":"YES"}),
|
||||
json!({"op":"fund","id":"v-fund","account":"unpriced-owner","cents":100}),
|
||||
json!({"op":"list","id":"v-list","market":"unpriced","rules":"valuation fixture"}),
|
||||
json!({"op":"split","id":"v-split","account":"unpriced-owner","market":"unpriced","qty":1}),
|
||||
@@ -779,9 +789,17 @@ mod tests {
|
||||
("GET","/clob-markets/missing",String::new(),400,None),
|
||||
("POST","/clob-markets/map+2%2F1","{}".into(),405,None),
|
||||
("GET",tick_query.as_str(),String::new(),200,Some(json!({"minimum_tick_size":0.01}))),
|
||||
("GET","/neg-risk/eb:NO:map+2%2F1",String::new(),200,Some(json!({"neg_risk":false}))),
|
||||
("GET","/neg-risk/",String::new(),400,Some(json!({"error":"Invalid token id"}))),
|
||||
("GET","/neg-risk/garbage",String::new(),404,Some(json!({"error":"market not found"}))),
|
||||
("GET","/fee-rate?token_id=garbage",String::new(),404,Some(json!({"error":"fee rate not found for market"}))),
|
||||
("GET","/tick-size/garbage",String::new(),404,Some(json!({"error":"market not found"}))),
|
||||
("GET","/neg-risk/eb:NO:resolved-params",String::new(),200,Some(json!({"neg_risk":false}))),
|
||||
("GET","/fee-rate/eb:NO:resolved-params",String::new(),200,Some(json!({"base_fee":1000}))),
|
||||
("GET","/tick-size/eb:NO:resolved-params",String::new(),200,Some(json!({"minimum_tick_size":0.001}))),
|
||||
("GET","/neg-risk?token_id=eb%3AYES%3Amap%2B2%2F1",String::new(),200,Some(json!({"neg_risk":false}))),
|
||||
("GET","/neg-risk?token_id=eb%3ANO%3Amissing",String::new(),404,None),
|
||||
("GET","/neg-risk?token_id=bad",String::new(),400,None),
|
||||
("GET","/neg-risk?token_id=bad",String::new(),404,Some(json!({"error":"market not found"}))),
|
||||
("GET","/neg-risk",String::new(),400,None),
|
||||
("POST","/neg-risk",String::new(),405,None),
|
||||
("GET","/fee-rate?token_id=eb%3AYES%3Amap%2B2%2F1",String::new(),200,Some(json!({"base_fee":30}))),
|
||||
|
||||
Reference in New Issue
Block a user