|
@@ -4,7 +4,7 @@ use actix_web::{web, App, HttpResponse, HttpServer, Responder, get};
|
|
|
use serde::{Deserialize, Serialize};
|
|
use serde::{Deserialize, Serialize};
|
|
|
use serde_json::{json, Value};
|
|
use serde_json::{json, Value};
|
|
|
use tracing::{info};
|
|
use tracing::{info};
|
|
|
-use crate::gate_usdt_swap_data_listener;
|
|
|
|
|
|
|
+use crate::{gate_usdt_swap_data_listener, rank};
|
|
|
|
|
|
|
|
// 定义用于反序列化查询参数的结构体
|
|
// 定义用于反序列化查询参数的结构体
|
|
|
#[derive(Serialize, Deserialize, Clone)]
|
|
#[derive(Serialize, Deserialize, Clone)]
|
|
@@ -32,40 +32,8 @@ pub struct Response {
|
|
|
|
|
|
|
|
#[get("/rk/get_rank_list")]
|
|
#[get("/rk/get_rank_list")]
|
|
|
async fn get_rank_list(query: web::Query<RankQuery>) -> impl Responder {
|
|
async fn get_rank_list(query: web::Query<RankQuery>) -> impl Responder {
|
|
|
- if query.validate() {
|
|
|
|
|
- let exchange = query.exchange.clone().unwrap().clone();
|
|
|
|
|
- let indicators = match exchange.as_str() {
|
|
|
|
|
- "gate_usdt_swap" => {
|
|
|
|
|
- gate_usdt_swap_data_listener::INDICATOR_MAP.lock().await
|
|
|
|
|
- },
|
|
|
|
|
- _ => {
|
|
|
|
|
- let response = Response {
|
|
|
|
|
- query: serde_json::to_value(&query.into_inner()).unwrap(),
|
|
|
|
|
- msg: Some("查询内容有误,exchange当前仅支持:[gate_usdt_swap]".to_string()),
|
|
|
|
|
- code: 500,
|
|
|
|
|
- data: Value::Null,
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- let json_string = serde_json::to_string(&response).unwrap();
|
|
|
|
|
- return HttpResponse::Ok().content_type("application/json").body(json_string)
|
|
|
|
|
- }
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- let count = indicators.get("BTC_USDT").unwrap().total_size;
|
|
|
|
|
- let rst = json!({
|
|
|
|
|
- "count": count
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- let response = Response {
|
|
|
|
|
- query: serde_json::to_value(&query.into_inner()).unwrap(),
|
|
|
|
|
- msg: Some("查询成功".to_string()),
|
|
|
|
|
- code: 200,
|
|
|
|
|
- data: rst,
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- let json_string = serde_json::to_string(&response).unwrap();
|
|
|
|
|
- HttpResponse::Ok().content_type("application/json").body(json_string)
|
|
|
|
|
- } else {
|
|
|
|
|
|
|
+ // ============================= 参数校验部分 =========================================
|
|
|
|
|
+ if !query.validate() {
|
|
|
let response = Response {
|
|
let response = Response {
|
|
|
query: serde_json::to_value(&query.into_inner()).unwrap(),
|
|
query: serde_json::to_value(&query.into_inner()).unwrap(),
|
|
|
msg: Some("查询内容有误,必须传递的参数:[exchange]".to_string()),
|
|
msg: Some("查询内容有误,必须传递的参数:[exchange]".to_string()),
|
|
@@ -74,8 +42,38 @@ async fn get_rank_list(query: web::Query<RankQuery>) -> impl Responder {
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
let json_string = serde_json::to_string(&response).unwrap();
|
|
let json_string = serde_json::to_string(&response).unwrap();
|
|
|
- HttpResponse::Ok().content_type("application/json").body(json_string)
|
|
|
|
|
|
|
+ return HttpResponse::Ok().content_type("application/json").body(json_string);
|
|
|
}
|
|
}
|
|
|
|
|
+ let exchange = query.exchange.clone().unwrap().clone();
|
|
|
|
|
+ let indicators = match exchange.as_str() {
|
|
|
|
|
+ "gate_usdt_swap" => {
|
|
|
|
|
+ gate_usdt_swap_data_listener::INDICATOR_MAP.lock().await
|
|
|
|
|
+ },
|
|
|
|
|
+ _ => {
|
|
|
|
|
+ let response = Response {
|
|
|
|
|
+ query: serde_json::to_value(&query.into_inner()).unwrap(),
|
|
|
|
|
+ msg: Some("查询内容有误,exchange当前仅支持:[gate_usdt_swap]".to_string()),
|
|
|
|
|
+ code: 500,
|
|
|
|
|
+ data: Value::Null,
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ let json_string = serde_json::to_string(&response).unwrap();
|
|
|
|
|
+ return HttpResponse::Ok().content_type("application/json").body(json_string)
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ // 逻辑执行部分
|
|
|
|
|
+ let rst = rank::generate_rank_by_indicator_map(&indicators);
|
|
|
|
|
+
|
|
|
|
|
+ let response = Response {
|
|
|
|
|
+ query: serde_json::to_value(&query.into_inner()).unwrap(),
|
|
|
|
|
+ msg: Some("查询成功".to_string()),
|
|
|
|
|
+ code: 200,
|
|
|
|
|
+ data: rst,
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ let json_string = serde_json::to_string(&response).unwrap();
|
|
|
|
|
+ HttpResponse::Ok().content_type("application/json").body(json_string)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
#[get("/rk/get_exchanges")]
|
|
#[get("/rk/get_exchanges")]
|