futu_rest/routes/qot/reference/
unusual.rs1use super::*;
2
3async fn skill_wrap_proto_request<Req, Rsp>(
4 state: &RestState,
5 proto_id: u32,
6 body: Value,
7) -> RawApiResult
8where
9 Req: prost::Message + Default + serde::de::DeserializeOwned,
10 Rsp: prost::Message + Default + serde::Serialize,
11{
12 let req_msg: Req = decode_json_request(proto_id, Some(body), JsonRequestMode::RawSpecBody)?;
13 let body = Bytes::from(req_msg.encode_to_vec());
14 let incoming = IncomingRequest::builder(
15 state.next_conn_id(),
16 proto_id,
17 state.next_serial(),
18 ProtoFmtType::Protobuf,
19 body,
20 )
21 .build();
22 let resp_bytes = state
23 .router
24 .dispatch(incoming.conn_id, &incoming)
25 .await
26 .ok_or_else(|| {
27 (
28 StatusCode::INTERNAL_SERVER_ERROR,
29 Json(serde_json::json!({
30 "error": "handler returned no response"
31 })),
32 )
33 })?;
34 let rsp_msg = Rsp::decode(Bytes::from(resp_bytes)).map_err(|e| {
35 (
36 StatusCode::INTERNAL_SERVER_ERROR,
37 Json(serde_json::json!({
38 "error": format!("failed to decode response: {e}")
39 })),
40 )
41 })?;
42 adapter::raw_json_from_proto_response(&rsp_msg)
43}
44
45pub async fn get_technical_unusual(
47 State(state): State<RestState>,
48 Json(body): Json<Value>,
49) -> RawApiResult {
50 skill_wrap_proto_request::<
51 skill_wrap_api::TechnicalUnusualReq,
52 skill_wrap_api::TechnicalUnusualRsp,
53 >(&state, proto_id::QOT_GET_TECHNICAL_UNUSUAL, body)
54 .await
55}
56
57pub async fn get_financial_unusual(
59 State(state): State<RestState>,
60 Json(body): Json<Value>,
61) -> RawApiResult {
62 skill_wrap_proto_request::<
63 skill_wrap_api::FinancialUnusualReq,
64 skill_wrap_api::FinancialUnusualRsp,
65 >(&state, proto_id::QOT_GET_FINANCIAL_UNUSUAL, body)
66 .await
67}
68
69pub async fn get_derivative_unusual(
71 State(state): State<RestState>,
72 Json(body): Json<Value>,
73) -> RawApiResult {
74 skill_wrap_proto_request::<
75 skill_wrap_api::DerivativeUnusualReq,
76 skill_wrap_api::DerivativeUnusualRsp,
77 >(&state, proto_id::QOT_GET_DERIVATIVE_UNUSUAL, body)
78 .await
79}