|
|
@@ -1,8 +1,5 @@
|
|
|
use std::collections::BTreeMap;
|
|
|
-use std::ops::Index;
|
|
|
use reqwest::header::HeaderMap;
|
|
|
-use ring::{digest};
|
|
|
-use hex;
|
|
|
use hmac::{Hmac, Mac, NewMac};
|
|
|
use reqwest::{Client};
|
|
|
use sha2::Sha256;
|
|
|
@@ -14,7 +11,6 @@ pub struct KucoinSwapRest {
|
|
|
client: reqwest::Client,
|
|
|
/*******参数*/
|
|
|
//是否需要登陆
|
|
|
- is_login: bool,
|
|
|
//登陆所需参数
|
|
|
login_param: BTreeMap<String, String>,
|
|
|
|
|
|
@@ -24,21 +20,20 @@ impl KucoinSwapRest {
|
|
|
/*******************************************************************************************************/
|
|
|
/*****************************************获取一个对象****************************************************/
|
|
|
/*******************************************************************************************************/
|
|
|
- pub fn new(is_colo: bool, is_login: bool, login_param: BTreeMap<String, String>) -> KucoinSwapRest
|
|
|
+
|
|
|
+ pub fn new(is_colo: bool, login_param: BTreeMap<String, String>) -> KucoinSwapRest
|
|
|
{
|
|
|
- let mut base_url = String::from("");
|
|
|
- if is_colo {
|
|
|
+ let base_url = if is_colo {
|
|
|
println!("不支持colo高速线路");
|
|
|
- base_url = "https://api-futures.kucoin.com".to_string()
|
|
|
+ "https://api-futures.kucoin.com".to_string()
|
|
|
} else {
|
|
|
- base_url = "https://api-futures.kucoin.com".to_string()
|
|
|
- }
|
|
|
+ "https://api-futures.kucoin.com".to_string()
|
|
|
+ };
|
|
|
|
|
|
/*****返回结构体*******/
|
|
|
KucoinSwapRest {
|
|
|
- base_url: base_url.to_string(),
|
|
|
+ base_url,
|
|
|
client: Client::new(),
|
|
|
- is_login,
|
|
|
login_param,
|
|
|
}
|
|
|
}
|
|
|
@@ -85,7 +80,7 @@ impl KucoinSwapRest {
|
|
|
}
|
|
|
//查询所有的合约信息
|
|
|
pub async fn get_market_details(&self) -> ResponseData {
|
|
|
- let mut params = serde_json::json!({});
|
|
|
+ let params = serde_json::json!({});
|
|
|
|
|
|
let data = self.request("GET".to_string(),
|
|
|
"/api/v1".to_string(),
|
|
|
@@ -256,8 +251,7 @@ impl KucoinSwapRest {
|
|
|
|
|
|
//请求头配置-如果需要登陆则存在额外配置
|
|
|
let mut body = "".to_string();
|
|
|
- let mut sing = "".to_string();
|
|
|
- let mut passphrase = "".to_string();
|
|
|
+
|
|
|
let timestamp = chrono::Utc::now().timestamp_millis().to_string();
|
|
|
|
|
|
let mut headers = HeaderMap::new();
|
|
|
@@ -275,16 +269,16 @@ impl KucoinSwapRest {
|
|
|
println!("param:{}", params);
|
|
|
println!("body:{}", body);
|
|
|
//组装sing
|
|
|
- sing = Self::sign(secret_key.clone(),
|
|
|
- method.clone(),
|
|
|
- prefix_url.clone(),
|
|
|
- request_url.clone(),
|
|
|
- params.clone(),
|
|
|
- body.clone(),
|
|
|
- timestamp.clone(),
|
|
|
+ let sing = Self::sign(secret_key.clone(),
|
|
|
+ method.clone(),
|
|
|
+ prefix_url.clone(),
|
|
|
+ request_url.clone(),
|
|
|
+ params.clone(),
|
|
|
+ body.clone(),
|
|
|
+ timestamp.clone(),
|
|
|
);
|
|
|
println!("sing:{}", sing);
|
|
|
- passphrase = Self::passphrase(secret_key, pass_key);
|
|
|
+ let passphrase = Self::passphrase(secret_key, pass_key);
|
|
|
println!("passphrase:{}", passphrase);
|
|
|
//组装header
|
|
|
headers.extend(Self::headers(sing, timestamp, passphrase, access_key));
|
|
|
@@ -293,14 +287,14 @@ impl KucoinSwapRest {
|
|
|
|
|
|
|
|
|
// println!("headers:{:?}", headers);
|
|
|
- let mut get_response = self.http_toll(
|
|
|
+ let get_response = self.http_toll(
|
|
|
format!("{}{}", prefix_url.clone(), request_url.clone()),
|
|
|
method.to_string(),
|
|
|
params,
|
|
|
headers,
|
|
|
).await;
|
|
|
|
|
|
- let mut req_data = Self::req_data_analysis(get_response);
|
|
|
+ let req_data = Self::req_data_analysis(get_response);
|
|
|
req_data
|
|
|
}
|
|
|
|
|
|
@@ -383,11 +377,11 @@ impl KucoinSwapRest {
|
|
|
if response.status().is_success() {
|
|
|
// 读取响应的内容
|
|
|
let body = response.text().await?;
|
|
|
- println!("ok-----{}", body);
|
|
|
+ // println!("ok-----{}", body);
|
|
|
req_data = ResponseData::new("200".to_string(), "success".to_string(), body);
|
|
|
} else {
|
|
|
let body = response.text().await?;
|
|
|
- println!("error-----{}", body);
|
|
|
+ // println!("error-----{}", body);
|
|
|
req_data = ResponseData::error(body.to_string())
|
|
|
}
|
|
|
Ok(req_data)
|