|
|
@@ -1,4 +1,4 @@
|
|
|
-use std::io::{ Error, ErrorKind};
|
|
|
+use std::io::{BufRead, Error, ErrorKind};
|
|
|
use std::collections::{BTreeMap};
|
|
|
use serde_json::json;
|
|
|
use crate::exchange_libs::{BinanceExc, OkxExc, ReqData, SocketTool};
|
|
|
@@ -119,7 +119,7 @@ impl Exchange {
|
|
|
// 获取币安深度信息
|
|
|
// symbol: 交易币对, "BTC_USDT"
|
|
|
// limit: 返回条数, 最大 5000. 可选值:[5, 10, 20, 50, 100, 500, 1000, 5000]
|
|
|
- pub async fn get_binance_depth(&self, symbol: &String, limit: i32, callback: fn(Depth)) {
|
|
|
+ pub async fn get_binance_depth<F: FnMut(Depth)>(&self, symbol: &String, limit: i32, mut callback: F) {
|
|
|
let real_symbol = self.get_real_symbol(symbol, "".to_string());
|
|
|
let get_res_data =|res_data:ReqData|{
|
|
|
if res_data.code == "0" {
|
|
|
@@ -257,38 +257,40 @@ impl Exchange {
|
|
|
// 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(res_data) => {
|
|
|
- let symbol_array: Vec<&str> = symbol.split("_").collect();
|
|
|
- let res_data_str = res_data.data;
|
|
|
- let res_data_json: serde_json::Value = serde_json::from_str(&*res_data_str).unwrap();
|
|
|
- let order_info = res_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 = res_data_json;
|
|
|
- }
|
|
|
- Err(err) => {}
|
|
|
- }
|
|
|
+ // 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(res_data) => {
|
|
|
+ // let symbol_array: Vec<&str> = symbol.split("_").collect();
|
|
|
+ // let res_data_str = res_data.data;
|
|
|
+ // let res_data_json: serde_json::Value = serde_json::from_str(&*res_data_str).unwrap();
|
|
|
+ // let order_info = res_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 min_qty = info["minSz"].as_str().unwrap_or("0").parse().unwrap_or(0.0);
|
|
|
+ // let amount_size = info["lotSz"].as_str().unwrap_or("0").parse().unwrap_or(0.0);
|
|
|
+ // 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: info["tickSz"].as_str().unwrap_or("0").parse().unwrap_or(0.0),
|
|
|
+ // amount_size,
|
|
|
+ // price_precision: info["tickSz"].as_str().unwrap().parse().to_string().split(".").collect()[1],
|
|
|
+ // amount_precision:info["lotSz"].as_str().unwrap().parse().to_string().split(".").collect()[1],
|
|
|
+ // min_qty,
|
|
|
+ // max_qty: info["minSz"].as_str().unwrap_or("0").parse().unwrap_or(0.0),
|
|
|
+ // min_notional: amount_size * min_qty,
|
|
|
+ // max_notional: 0.01,
|
|
|
+ // ct_val: info["ctVal"].as_str().unwrap_or("0").parse().unwrap_or(0.0),
|
|
|
+ // };
|
|
|
+ // println!("\n\n{:?}", result);
|
|
|
+ // // let order_info = res_data_json;
|
|
|
+ // }
|
|
|
+ // Err(err) => {}
|
|
|
+ // }
|
|
|
// let real_symbol = self.get_real_symbol(symbol, "-".to_string());
|
|
|
// let res_data = self.okx_exc.get_v("/api/v5/public/instruments", order_id).await;
|
|
|
// if res_data.code == "0" {
|