|
|
@@ -1,7 +1,7 @@
|
|
|
-use std::io::{Error,ErrorKind};
|
|
|
+use std::io::{Error, ErrorKind};
|
|
|
use std::collections::{BTreeMap};
|
|
|
use serde_json::json;
|
|
|
-use crate::exchange_libs::{BinanceExc, OkxExc, ReqData};
|
|
|
+use crate::exchange_libs::{BinanceExc, OkxExc, SocketTool};
|
|
|
|
|
|
// 深度结构体
|
|
|
#[derive(Debug)]
|
|
|
@@ -69,9 +69,19 @@ pub struct Order {
|
|
|
}
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
-pub struct Market{
|
|
|
- symbol:String,
|
|
|
- base_asset: String
|
|
|
+pub struct Market {
|
|
|
+ symbol: String,
|
|
|
+ base_asset: String,
|
|
|
+ quote_asset: String,
|
|
|
+ tick_size: f64,
|
|
|
+ amount_size: f64,
|
|
|
+ price_precision: f64,
|
|
|
+ amount_precision: f64,
|
|
|
+ min_qty: f64,
|
|
|
+ max_qty: f64,
|
|
|
+ min_notional: f64,
|
|
|
+ max_notional: f64,
|
|
|
+ ct_val: f64,
|
|
|
}
|
|
|
|
|
|
pub struct Exchange {
|
|
|
@@ -111,6 +121,7 @@ impl Exchange {
|
|
|
// limit: 返回条数, 最大 5000. 可选值:[5, 10, 20, 50, 100, 500, 1000, 5000]
|
|
|
pub async fn get_binance_depth(&self, symbol: &String, limit: i32) -> Result<Depth, Error> {
|
|
|
let real_symbol = self.get_real_symbol(symbol, "".to_string());
|
|
|
+ // SocketTool::binance_run_depth(vec![symbol], limit.to_string(), aa);
|
|
|
let req_data = self.binance_exc.binance_depth(&real_symbol, &limit.to_string()).await;
|
|
|
if req_data.code == "0" {
|
|
|
let req_data_str = req_data.data;
|
|
|
@@ -127,6 +138,7 @@ impl Exchange {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
// 获取币安K线数据信息
|
|
|
// symbol: 交易币对, "BTC_USDT"
|
|
|
// interval: K线间隔, 可选值:[1s, 1m, 3m, 5m, 15m,30m,1h, 2h, 4h, 6h, 8h,12h, 1d, 3d, 1w, 1M]
|
|
|
@@ -240,7 +252,54 @@ impl Exchange {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // OKX撤销订单
|
|
|
+ // symbol: 交易币对, "BTC_USDT"
|
|
|
+ // order_id: 订单ID, "590910403358593111"
|
|
|
+ pub async fn get_okx_instruments(&self, symbol: &String) {
|
|
|
+ let real_symbol = self.get_real_symbol(symbol, "-".to_string());
|
|
|
+ let mut btree_map: BTreeMap<&str, &str> = BTreeMap::new();
|
|
|
+ btree_map.insert("instType", "SPOT");
|
|
|
+ let result = self.okx_exc.get_v("/api/v5/public/instruments".to_string(), btree_map).await;
|
|
|
+ match result {
|
|
|
+ Ok(req_data) => {
|
|
|
+ let symbol_array: Vec<&str> = symbol.split("_").collect();
|
|
|
+ let req_data_str = req_data.data;
|
|
|
+ let req_data_json: serde_json::Value = serde_json::from_str(&*req_data_str).unwrap();
|
|
|
+ let order_info = req_data_json["data"].as_array().unwrap();
|
|
|
+ let info = order_info.iter().find(|item| item["baseCcy"].as_str().unwrap() == symbol_array[0] && item["quoteCcy"].as_str().unwrap() == symbol_array[1]).unwrap();
|
|
|
+ println!("\n\n{:?}", info);
|
|
|
|
|
|
+ let result = Market {
|
|
|
+ symbol: info["instId"].as_str().unwrap().parse().unwrap(),
|
|
|
+ base_asset: info["baseCcy"].as_str().unwrap().parse().unwrap(),
|
|
|
+ quote_asset: info["quoteCcy"].as_str().unwrap().parse().unwrap(),
|
|
|
+ tick_size: 0.01,
|
|
|
+ amount_size: 0.01,
|
|
|
+ price_precision: 0.01,
|
|
|
+ amount_precision: 0.01,
|
|
|
+ min_qty: 0.01,
|
|
|
+ max_qty: 0.01,
|
|
|
+ min_notional: 0.01,
|
|
|
+ max_notional: 0.01,
|
|
|
+ ct_val: 0.01,
|
|
|
+ };
|
|
|
+ println!("\n\n{:?}", result);
|
|
|
+ // let order_info = req_data_json;
|
|
|
+ }
|
|
|
+ Err(err) => {}
|
|
|
+ }
|
|
|
+ // let real_symbol = self.get_real_symbol(symbol, "-".to_string());
|
|
|
+ // let req_data = self.okx_exc.get_v("/api/v5/public/instruments", order_id).await;
|
|
|
+ // if req_data.code == "0" {
|
|
|
+ // let req_data_str = req_data.data;
|
|
|
+ // let req_data_json: Vec<serde_json::Value> = serde_json::from_str(&*req_data_str).unwrap();
|
|
|
+ // let order_info = req_data_json[0]["sCode"].as_str().unwrap();
|
|
|
+ // let result = if order_info == "0" { true } else { false };
|
|
|
+ // Ok(result)
|
|
|
+ // } else {
|
|
|
+ // Err(Error::new(ErrorKind::Other, req_data.message))
|
|
|
+ // }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// 深度信息买单/卖单处理
|
|
|
@@ -256,7 +315,6 @@ fn parse_depth_items(value: &serde_json::Value) -> Vec<DepthItem> {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
// 单元测试集
|
|
|
#[cfg(test)]
|
|
|
mod tests {
|