Add filtering delist trades (#5)
Co-authored-by: Sik Yoon <younxxxx@gmail.com> Reviewed-on: http://192.168.1.100:3000/Sik/tradingbot/pulls/5
This commit is contained in:
parent
e4d19b7d48
commit
4c4d947b99
|
|
@ -110,52 +110,56 @@ pub async fn collect_valid_usde_trade(
|
|||
condition_build.push_str(" AND askPrice > 0");
|
||||
condition_build.push_str(" AND askQty > 0");
|
||||
// condition_build.push_str(" AND symbol NOT IN (SELECT symbol FROM stop_usdt_trades)");
|
||||
// add fiat and unnessesary coins
|
||||
condition_build.push_str(" AND symbol NOT LIKE 'BUSDUSDT'");
|
||||
condition_build.push_str(" AND symbol NOT LIKE 'USTCUSDT'");
|
||||
condition_build.push_str(" AND symbol NOT LIKE 'FDUSDUSDT'");
|
||||
condition_build.push_str(" AND symbol NOT LIKE 'TUSDUSDT'");
|
||||
condition_build.push_str(" AND symbol NOT LIKE 'USDPUSDT'");
|
||||
condition_build.push_str(" AND symbol NOT LIKE 'SUSDUSDT'");
|
||||
condition_build.push_str(" AND symbol NOT LIKE 'AUDUSDT'");
|
||||
condition_build.push_str(" AND symbol NOT LIKE 'EURUSDT'");
|
||||
condition_build.push_str(" AND symbol NOT LIKE 'GBPUSDT'");
|
||||
condition_build.push_str(" AND symbol NOT LIKE 'USDCUSDT'");
|
||||
condition_build.push_str(" AND symbol NOT LIKE 'BZRXUSDT'");
|
||||
condition_build.push_str(" AND symbol NOT LIKE 'USTUSDT'");
|
||||
condition_build.push_str(" AND symbol NOT LIKE 'NBTUSDT'");
|
||||
condition_build.push_str(" AND symbol NOT LIKE 'VGXUSDT'");
|
||||
condition_build.push_str(" AND symbol NOT LIKE 'RAMPUSDT'");
|
||||
condition_build.push_str(" AND symbol NOT LIKE 'TORNUSDT'");
|
||||
condition_build.push_str(" AND symbol NOT LIKE 'BTTCUSDT'");
|
||||
condition_build.push_str(" AND symbol NOT LIKE 'BTCSTUSDT'");
|
||||
condition_build.push_str(" AND symbol NOT LIKE 'ACAUSDT'");
|
||||
condition_build.push_str(" AND symbol NOT LIKE 'ANCUSDT'");
|
||||
|
||||
let condition = Some(condition_build);
|
||||
|
||||
// get valid usdt trades
|
||||
let usdt_trades =
|
||||
select_record(&fetch_table_name, &column_name, &condition, &usdt_trades).await?;
|
||||
|
||||
// get banned usdt trades
|
||||
#[derive(Debug, FromRow)]
|
||||
struct Symbols {
|
||||
symbol: String,
|
||||
}
|
||||
|
||||
let table_name = String::from("banned_usdt_trades");
|
||||
let column_name = String::from("symbol");
|
||||
let condition = None;
|
||||
let mut symbols = Symbols {
|
||||
symbol: String::new(),
|
||||
};
|
||||
|
||||
let mut select_result = try_select_record(&table_name, &column_name, &condition, &symbols)
|
||||
.await
|
||||
.unwrap();
|
||||
let mut banned_usdt_trades_set: HashSet<String> = HashSet::new();
|
||||
for element in select_result {
|
||||
banned_usdt_trades_set.insert(element.symbol.clone());
|
||||
}
|
||||
|
||||
// filtering usdt trades
|
||||
let mut filtered_usdt_trades: HashSet<String> = HashSet::new();
|
||||
let mut excluded_usdt_trades: HashSet<String> = HashSet::new();
|
||||
for usdt_trade in usdt_trades {
|
||||
// build update values
|
||||
if let Some(value) = exchange_info_vec.get(&usdt_trade.symbol) {
|
||||
let avg_price: Decimal =
|
||||
rust_decimal::prelude::FromPrimitive::from_f64(usdt_trade.weightedavgprice)
|
||||
.unwrap();
|
||||
let step_size = value.stepsize;
|
||||
let step_price = decimal_mul(step_size, avg_price);
|
||||
let unit_trade_usdt = crate::coex::assets_managing_team::get_unit_trade_usdt().await;
|
||||
// filtering banned usdt trades
|
||||
if banned_usdt_trades_set.contains(&usdt_trade.symbol) {
|
||||
excluded_usdt_trades.insert(usdt_trade.symbol.clone());
|
||||
} else {
|
||||
// build update values
|
||||
if let Some(value) = exchange_info_vec.get(&usdt_trade.symbol) {
|
||||
let avg_price: Decimal =
|
||||
rust_decimal::prelude::FromPrimitive::from_f64(usdt_trade.weightedavgprice)
|
||||
.unwrap();
|
||||
let step_size = value.stepsize;
|
||||
let step_price = decimal_mul(step_size, avg_price);
|
||||
let unit_trade_usdt = crate::coex::assets_managing_team::get_unit_trade_usdt().await;
|
||||
|
||||
// exclude USDT trades whose step_price is over than 1% of unit_trade_usdt
|
||||
if step_price > decimal_mul(unit_trade_usdt, dec!(0.01)) {
|
||||
excluded_usdt_trades.insert(usdt_trade.symbol.clone());
|
||||
} else {
|
||||
filtered_usdt_trades.insert(usdt_trade.symbol.clone());
|
||||
// exclude USDT trades whose step_price is over than 1% of unit_trade_usdt
|
||||
if step_price > decimal_mul(unit_trade_usdt, dec!(0.01)) {
|
||||
excluded_usdt_trades.insert(usdt_trade.symbol.clone());
|
||||
} else {
|
||||
filtered_usdt_trades.insert(usdt_trade.symbol.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ use serde::Deserialize;
|
|||
use serde_json::Value;
|
||||
use sqlx::{Error, FromRow};
|
||||
use std::borrow::{Borrow, BorrowMut};
|
||||
use std::collections::HashSet;
|
||||
use std::sync::Arc;
|
||||
use std::collections::HashMap;
|
||||
use tokio::{join, sync::Mutex, time::*};
|
||||
|
|
@ -435,3 +436,137 @@ pub async fn request_exchange_infomation(
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn request_delist_symbols(
|
||||
api_key: &str,
|
||||
secret_key: &str,
|
||||
local_epoch: u128,
|
||||
difference_epoch: i64,
|
||||
client: &Client
|
||||
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||
let mut base_url = String::from("https://api.binance.com/sapi/v1/spot/delist-schedule?");
|
||||
|
||||
// local 시간이 server 시간보다 너무 앞서거나 뒤쳐지면 USER_DATA를 요청할 수 없으므로 local과 server 의 시간 차이만큼을 local에서 빼어 보정한 뒤
|
||||
// 이를 timestamp로 사용한다.
|
||||
let mut timestamp;
|
||||
if difference_epoch >= 0 {
|
||||
timestamp = (local_epoch - difference_epoch as u128).to_string();
|
||||
} else if difference_epoch < 0 {
|
||||
timestamp = (local_epoch - (difference_epoch * -1) as u128).to_string();
|
||||
} else {
|
||||
timestamp = local_epoch.to_string();
|
||||
}
|
||||
let recv_window_size = "20000".to_string(); // default: 5,000ms, Max: 60,000ms
|
||||
|
||||
let mut query_string = String::from("×tamp=");
|
||||
query_string.push_str(×tamp);
|
||||
query_string.push_str("&recvWindow=");
|
||||
query_string.push_str(&recv_window_size);
|
||||
|
||||
let signature = HMAC::mac(&query_string.as_bytes(), secret_key.as_bytes());
|
||||
|
||||
query_string.push_str("&signature=");
|
||||
base_url.push_str(&query_string);
|
||||
base_url.push_str(signature.encode_hex::<String>().as_str());
|
||||
|
||||
let mut response = client
|
||||
.get(&base_url)
|
||||
.header("X-MBX-APIKEY", api_key)
|
||||
.send()
|
||||
.await?;
|
||||
|
||||
while !response.status().is_success() {
|
||||
sleep(Duration::from_secs(5)).await;
|
||||
response = client
|
||||
.get(&base_url)
|
||||
.header("X-MBX-APIKEY", api_key)
|
||||
.send()
|
||||
.await?;
|
||||
}
|
||||
|
||||
let mut body = response.text_with_charset("utf-8").await;
|
||||
match body {
|
||||
Ok(T) => {
|
||||
de_deilst_symbol_json(&T).await?;
|
||||
}
|
||||
Err(E) => {
|
||||
log::warn!("request_delist_symbols body failed!: {:?}", E);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn de_deilst_symbol_json(
|
||||
body: &String,
|
||||
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||
let v: Value = serde_json::from_str(body.as_str())?;
|
||||
|
||||
let into_vec = v.as_array();
|
||||
if into_vec == None {
|
||||
return Err("Err")?;
|
||||
}
|
||||
let mut object_map = &serde_json::map::Map::new();
|
||||
let mut delist_hashset: HashSet<String> = HashSet::new();
|
||||
let mut symbol = String::new();
|
||||
for element in into_vec.unwrap() {
|
||||
object_map = element.as_object().unwrap();
|
||||
let mut object_map_iter = object_map.iter();
|
||||
|
||||
for element in object_map_iter {
|
||||
match element.0.as_str() {
|
||||
"delistTime" => {
|
||||
},
|
||||
"symbols" => {
|
||||
if let Some(array) = element.1.as_array() {
|
||||
for delist_symbol in array {
|
||||
if let Some(symbol) = delist_symbol.as_str() {
|
||||
if symbol.ends_with("USDT") && !delist_hashset.contains(symbol) {
|
||||
delist_hashset.insert(symbol.to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
_ => {
|
||||
log::error!("Elements in body msg are changed. Please update both your delist table and vectors.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if delist_hashset.len() != 0 {
|
||||
#[derive(Debug, FromRow)]
|
||||
struct Symbols {
|
||||
symbol: String,
|
||||
}
|
||||
|
||||
let table_name = String::from("banned_usdt_trades");
|
||||
let column_name = String::from("symbol");
|
||||
let condition = None;
|
||||
let mut symbols = Symbols {
|
||||
symbol: String::new(),
|
||||
};
|
||||
|
||||
let mut select_result = try_select_record(&table_name, &column_name, &condition, &symbols)
|
||||
.await
|
||||
.unwrap();
|
||||
let mut banned_usdt_trades_set: HashSet<String> = HashSet::new();
|
||||
for element in select_result {
|
||||
banned_usdt_trades_set.insert(element.symbol.clone());
|
||||
}
|
||||
|
||||
let insert_column = vec!["symbol"];
|
||||
for element in &delist_hashset {
|
||||
if !banned_usdt_trades_set.contains(element) {
|
||||
let insert_values = vec![element.clone()];
|
||||
insert_one_record(&table_name, &insert_column, &insert_values)
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -244,6 +244,60 @@ async fn initialize_database() {
|
|||
println!("Ok");
|
||||
}
|
||||
|
||||
{
|
||||
print!("table 'banned_usdt_trades'...");
|
||||
io::stdout().flush();
|
||||
|
||||
let table_name = String::from("banned_usdt_trades");
|
||||
let exists_result = exists_table(&table_name).await;
|
||||
let initial_table = vec![
|
||||
("id", "integer", Some("PK, AI")),
|
||||
("symbol", "char(20)", None),
|
||||
];
|
||||
let table_condition = None;
|
||||
|
||||
if exists_result == false {
|
||||
let mut result = new_table(&table_name, &initial_table, &table_condition).await;
|
||||
if result.is_err() {
|
||||
loop {
|
||||
result = new_table(&table_name, &initial_table, &table_condition).await;
|
||||
if result.is_ok() {
|
||||
break;
|
||||
}
|
||||
sleep(Duration::from_millis(10)).await;
|
||||
}
|
||||
}
|
||||
let columns = vec!["symbol"];
|
||||
// add fiat and unnessesary coins
|
||||
let value_wrapper = vec![
|
||||
vec![String::from("BUSDUSDT")],
|
||||
vec![String::from("USTCUSDT")],
|
||||
vec![String::from("FDUSDUSDT")],
|
||||
vec![String::from("TUSDUSDT")],
|
||||
vec![String::from("USDPUSDT")],
|
||||
vec![String::from("SUSDUSDT")],
|
||||
vec![String::from("AUDUSDT")],
|
||||
vec![String::from("EURUSDT")],
|
||||
vec![String::from("GBPUSDT")],
|
||||
vec![String::from("USDCUSDT")],
|
||||
vec![String::from("BZRXUSDT")],
|
||||
vec![String::from("USTUSDT")],
|
||||
vec![String::from("NBTUSDT")],
|
||||
vec![String::from("VGXUSDT")],
|
||||
vec![String::from("RAMPUSDT")],
|
||||
vec![String::from("TORNUSDT")],
|
||||
vec![String::from("BTTCUSDT")],
|
||||
vec![String::from("BTCSTUSDT")],
|
||||
vec![String::from("ACAUSDT")],
|
||||
vec![String::from("ANCUSDT")],
|
||||
];
|
||||
insert_records(&table_name, &columns, &value_wrapper)
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
println!("Ok");
|
||||
}
|
||||
|
||||
{
|
||||
print!("table 'valid_usdt_trades'...");
|
||||
io::stdout().flush();
|
||||
|
|
|
|||
222
src/main.rs
222
src/main.rs
|
|
@ -84,9 +84,12 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
let tx_task24 = tx_task1.clone(); // for Task#24
|
||||
let tx_task25 = tx_task1.clone(); // for Task#25
|
||||
let tx_task26 = tx_task1.clone(); // for Task#26
|
||||
let tx_task27 = tx_task1.clone(); // for Task#27
|
||||
|
||||
let (tx1, mut rx1_1) = watch::channel(0); // local_epoch
|
||||
let (tx2, mut rx2) = watch::channel(0); // epoch_difference
|
||||
let (local_epoch_tx1, mut local_epoch_rx1) = watch::channel(0); // local_epoch
|
||||
let (epoch_difference_tx1, mut epoch_difference_rx1) = watch::channel(0); // epoch_difference
|
||||
let (local_epoch_tx2, mut local_epoch_rx2) = watch::channel(0); // local_epoch
|
||||
let (epoch_difference_tx2, mut epoch_difference_rx2) = watch::channel(0); // epoch_difference
|
||||
|
||||
// trade fee data
|
||||
let mut tradefee_map: HashMap<String, TradeFee> = HashMap::new(); // <symbol, TradeFee>
|
||||
|
|
@ -278,127 +281,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
let result = rx_task0.recv().await;
|
||||
|
||||
match result {
|
||||
Some(1) => {
|
||||
// print!("\r{1[■] 2[ ] 3[ ] 4[ ] 5[ ] 6[ ] 7[ ] 8[ ] 9[ ] 12[ ] 13[ ] 14[ ] 15[ ] 16[ ] 17[ ] 18[ ] 19[ ] 20[ ] 21[ ] 22[ ] 23[ ] 24[ ] 25[ ] 26[ ]}");
|
||||
print!("\r{:2}", 1);
|
||||
Some(_) => {
|
||||
print!("\r{:2}", result.unwrap());
|
||||
io::stdout().flush();
|
||||
}
|
||||
Some(2) => {
|
||||
// print!("\r1[ ] 2[■] 3[ ] 4[ ] 5[ ] 6[ ] 7[ ] 8[ ] 9[ ] 12[ ] 13[ ] 14[ ] 15[ ] 16[ ] 17[ ] 18[ ] 19[ ] 20[ ] 21[ ] 22[ ] 23[ ] 24[ ] 25[ ] 26[ ]");
|
||||
print!("\r{:2}", 2);
|
||||
io::stdout().flush();
|
||||
}
|
||||
Some(3) => {
|
||||
// print!("\r1[ ] 2[ ] 3[■] 4[ ] 5[ ] 6[ ] 7[ ] 8[ ] 9[ ] 12[ ] 13[ ] 14[ ] 15[ ] 16[ ] 17[ ] 18[ ] 19[ ] 20[ ] 21[ ] 22[ ] 23[ ] 24[ ] 25[ ] 26[ ]");
|
||||
print!("\r{:2}", 3);
|
||||
io::stdout().flush();
|
||||
}
|
||||
Some(4) => {
|
||||
// print!("\r1[ ] 2[ ] 3[ ] 4[■] 5[ ] 6[ ] 7[ ] 8[ ] 9[ ] 12[ ] 13[ ] 14[ ] 15[ ] 16[ ] 17[ ] 18[ ] 19[ ] 20[ ] 21[ ] 22[ ] 23[ ] 24[ ] 25[ ] 26[ ]");
|
||||
print!("\r{:2}", 4);
|
||||
io::stdout().flush();
|
||||
}
|
||||
Some(5) => {
|
||||
// print!("\r1[ ] 2[ ] 3[ ] 4[ ] 5[■] 6[ ] 7[ ] 8[ ] 9[ ] 12[ ] 13[ ] 14[ ] 15[ ] 16[ ] 17[ ] 18[ ] 19[ ] 20[ ] 21[ ] 22[ ] 23[ ] 24[ ] 25[ ] 26[ ]");
|
||||
print!("\r{:2}", 5);
|
||||
io::stdout().flush();
|
||||
}
|
||||
Some(6) => {
|
||||
// print!("\r1[ ] 2[ ] 3[ ] 4[ ] 5[ ] 6[■] 7[ ] 8[ ] 9[ ] 12[ ] 13[ ] 14[ ] 15[ ] 16[ ] 17[ ] 18[ ] 19[ ] 20[ ] 21[ ] 22[ ] 23[ ] 24[ ] 25[ ] 26[ ]");
|
||||
print!("\r{:2}", 6);
|
||||
io::stdout().flush();
|
||||
}
|
||||
Some(7) => {
|
||||
// print!("\r1[ ] 2[ ] 3[ ] 4[ ] 5[ ] 6[ ] 7[■] 8[] 9[ ] 12[ ] 13[ ] 14[ ] 15[ ] 16[ ] 17[ ] 18[ ] 19[ ] 20[ ] 21[ ] 22[ ] 23[ ] 24[ ] 25[ ] 26[ ]");
|
||||
print!("\r{:2}", 7);
|
||||
io::stdout().flush();
|
||||
}
|
||||
Some(8) => {
|
||||
// print!("\r1[ ] 2[ ] 3[ ] 4[ ] 5[ ] 6[ ] 7[ ] 8[■ 9[ ] 12[ ] 13[ ] 14[ ] 15[ ] 16[ ] 17[ ] 18[ ] 19[ ] 20[ ] 21[ ] 22[ ] 23[ ] 24[ ] 25[ ] 26[ ]");
|
||||
print!("\r{:2}", 8);
|
||||
io::stdout().flush();
|
||||
}
|
||||
Some(9) => {
|
||||
// print!("\r1[ ] 2[ ] 3[ ] 4[ ] 5[ ] 6[ ] 7[ ] 8[ ] 9[■] 12[ ] 13[ ] 14[ ] 15[ ] 16[ ] 17[ ] 18[ ] 19[ ] 20[ ] 21[ ] 22[ ] 23[ ] 24[ ] 25[ ] 26[ ]");
|
||||
print!("\r{:2}", 9);
|
||||
io::stdout().flush();
|
||||
}
|
||||
Some(12) => {
|
||||
// print!("\r1[ ] 2[ ] 3[ ] 4[ ] 5[ ] 6[ ] 7[ ] 8[ ] 9[ ] 12[■] 13[ ] 14[ ] 15[ ] 16[ ] 17[ ] 18[ ] 19[ ] 20[ ] 21[ ] 22[ ] 23[ ] 24[ ] 25[ ] 26[ ]");
|
||||
print!("\r{:2}", 12);
|
||||
io::stdout().flush();
|
||||
}
|
||||
Some(13) => {
|
||||
// print!("\r1[ ] 2[ ] 3[ ] 4[ ] 5[ ] 6[ ] 7[ ] 8[ ] 9[ ] 12[ ] 13[■] 14[ ] 15[ ] 16[ ] 17[ ] 18[ ] 19[ ] 20[ ] 21[ ] 22[ ] 23[ ] 24[ ] 25[ ] 26[ ]");
|
||||
print!("\r{:2}", 13);
|
||||
io::stdout().flush();
|
||||
}
|
||||
Some(14) => {
|
||||
// print!("\r1[ ] 2[ ] 3[ ] 4[ ] 5[ ] 6[ ] 7[ ] 8[ ] 9[ ] 12[ ] 13[ ] 14[■] 15[ ] 16[ ] 17[ ] 18[ ] 19[ ] 20[ ] 21[ ] 22[ ] 23[ ] 24[ ] 25[ ] 26[ ]");
|
||||
print!("\r{:2}", 14);
|
||||
io::stdout().flush();
|
||||
}
|
||||
Some(15) => {
|
||||
// print!("\r1[ ] 2[ ] 3[ ] 4[ ] 5[ ] 6[ ] 7[ ] 8[ ] 9[ ] 12[ ] 13[ ] 14[ ] 15[■] 16[ ] 17[ ] 18[ ] 19[ ] 20[ ] 21[ ] 22[ ] 23[ ] 24[ ] 25[ ] 26[ ]");
|
||||
print!("\r{:2}", 15);
|
||||
io::stdout().flush();
|
||||
}
|
||||
Some(16) => {
|
||||
// print!("\r1[ ] 2[ ] 3[ ] 4[ ] 5[ ] 6[ ] 7[ ] 8[ ] 9[ ] 12[ ] 13[ ] 14[ ] 15[ ] 16[■] 17[ ] 18[ ] 19[ ] 20[ ] 21[ ] 22[ ] 23[ ] 24[ ] 25[ ] 26[ ]");
|
||||
print!("\r{:2}", 16);
|
||||
io::stdout().flush();
|
||||
}
|
||||
Some(17) => {
|
||||
// print!("\r1[ ] 2[ ] 3[ ] 4[ ] 5[ ] 6[ ] 7[ ] 8[ ] 9[ ] 12[ ] 13[ ] 14[ ] 15[ ] 16[ ] 17[■] 18[ ] 19[ ] 20[ ] 21[ ] 22[ ] 23[ ] 24[ ] 25[ ] 26[ ]");
|
||||
print!("\r{:2}", 17);
|
||||
io::stdout().flush();
|
||||
}
|
||||
Some(18) => {
|
||||
// print!("\r1[ ] 2[ ] 3[ ] 4[ ] 5[ ] 6[ ] 7[ ] 8[ ] 9[ ] 12[ ] 13[ ] 14[ ] 15[ ] 16[ ] 17[ ] 18[■] 19[ ] 20[ ] 21[ ] 22[ ] 23[ ] 24[ ] 25[ ] 26[ ]");
|
||||
print!("\r{:2}", 18);
|
||||
io::stdout().flush();
|
||||
}
|
||||
Some(19) => {
|
||||
// print!("\r1[ ] 2[ ] 3[ ] 4[ ] 5[ ] 6[ ] 7[ ] 8[ ] 9[ ] 12[ ] 13[ ] 14[ ] 15[ ] 16[ ] 17[ ] 18[ ] 19[■] 20[ ] 21[ ] 22[ ] 23[ ] 24[ ] 25[ ] 26[ ]");
|
||||
print!("\r{:2}", 19);
|
||||
io::stdout().flush();
|
||||
}
|
||||
Some(20) => {
|
||||
// print!("\r1[ ] 2[ ] 3[ ] 4[ ] 5[ ] 6[ ] 7[ ] 8[ ] 9[ ] 12[ ] 13[ ] 14[ ] 15[ ] 16[ ] 17[ ] 18[ ] 19[ ] 20[■] 21[ ] 22[ ] 23[ ] 24[ ] 25[ ] 26[ ]");
|
||||
print!("\r{:2}", 20);
|
||||
io::stdout().flush();
|
||||
}
|
||||
Some(21) => {
|
||||
// print!("\r1[ ] 2[ ] 3[ ] 4[ ] 5[ ] 6[ ] 7[ ] 8[ ] 9[ ] 12[ ] 13[ ] 14[ ] 15[ ] 16[ ] 17[ ] 18[ ] 19[ ] 20[ ] 21[■] 22[ ] 23[ ] 24[ ] 25[ ] 26[ ]");
|
||||
print!("\r{:2}", 21);
|
||||
io::stdout().flush();
|
||||
}
|
||||
Some(22) => {
|
||||
// print!("\r1[ ] 2[ ] 3[ ] 4[ ] 5[ ] 6[ ] 7[ ] 8[ ] 9[ ] 12[ ] 13[ ] 14[ ] 15[ ] 16[ ] 17[ ] 18[ ] 19[ ] 20[ ] 21[ ] 22[■] 23[ ] 24[ ] 25[ ] 26[ ]");
|
||||
print!("\r{:2}", 22);
|
||||
io::stdout().flush();
|
||||
}
|
||||
Some(23) => {
|
||||
// print!("\r1[ ] 2[ ] 3[ ] 4[ ] 5[ ] 6[ ] 7[ ] 8[ ] 9[ ] 12[ ] 13[ ] 14[ ] 15[ ] 16[ ] 17[ ] 18[ ] 19[ ] 20[ ] 21[ ] 22[ ] 23[■] 24[ ] 25[ ] 26[ ]");
|
||||
print!("\r{:2}", 23);
|
||||
io::stdout().flush();
|
||||
}
|
||||
Some(24) => {
|
||||
// print!("\r1[ ] 2[ ] 3[ ] 4[ ] 5[ ] 6[ ] 7[ ] 8[ ] 9[ ] 12[ ] 13[ ] 14[ ] 15[ ] 16[ ] 17[ ] 18[ ] 19[ ] 20[ ] 21[ ] 22[ ] 23[ ] 24[■] 25[ ] 26[ ]");
|
||||
print!("\r{:2}", 24);
|
||||
io::stdout().flush();
|
||||
}
|
||||
Some(25) => {
|
||||
// print!("\r1[ ] 2[ ] 3[ ] 4[ ] 5[ ] 6[ ] 7[ ] 8[ ] 9[ ] 12[ ] 13[ ] 14[ ] 15[ ] 16[ ] 17[ ] 18[ ] 19[ ] 20[ ] 21[ ] 22[ ] 23[ ] 24[ ] 25[■] 26[ ]");
|
||||
print!("\r{:2}", 25);
|
||||
io::stdout().flush();
|
||||
}
|
||||
Some(26) => {
|
||||
// print!("\r1[ ] 2[ ] 3[ ] 4[ ] 5[ ] 6[ ] 7[ ] 8[ ] 9[ ] 12[ ] 13[ ] 14[ ] 15[ ] 16[ ] 17[ ] 18[ ] 19[ ] 20[ ] 21[ ] 22[ ] 23[ ] 24[ ] 25[ ] 26[■]");
|
||||
print!("\r{:2}", 26);
|
||||
io::stdout().flush();
|
||||
}
|
||||
Some(_) => {}
|
||||
None => {}
|
||||
}
|
||||
sleep(Duration::from_millis(50)).await;
|
||||
|
|
@ -444,10 +330,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
|
||||
match result {
|
||||
Ok(T) => {
|
||||
tx1.send(usertime.local_epoch)
|
||||
.expect("tx1-rx1 channel has been closed.");
|
||||
tx2.send(usertime.epoch_difference)
|
||||
.expect("tx2-rx2 channel has been closed.");
|
||||
local_epoch_tx1.send(usertime.local_epoch)
|
||||
.expect("local_epoch_tx1-local_epoch_rx1 channel has been closed.");
|
||||
epoch_difference_tx1.send(usertime.epoch_difference)
|
||||
.expect("epoch_difference_tx1-epoch_difference_rx1 channel has been closed.");
|
||||
local_epoch_tx2.send(usertime.local_epoch)
|
||||
.expect("local_epoch_tx2-local_epoch_rx2 channel has been closed.");
|
||||
epoch_difference_tx2.send(usertime.epoch_difference)
|
||||
.expect("epoch_difference_tx2-epoch_difference_rx2 channel has been closed.");
|
||||
tx_task1.send(1).expect("The mpsc channel has been closed.");
|
||||
}
|
||||
Err(E) => {}
|
||||
|
|
@ -511,10 +401,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
.timeout(tokio::time::Duration::from_millis(3000))
|
||||
.build()
|
||||
.unwrap();
|
||||
let tx1_changed = rx1_1.changed().await;
|
||||
let tx2_changed = rx2.changed().await;
|
||||
let local_epoch = *rx1_1.borrow();
|
||||
let difference_epoch = *rx2.borrow();
|
||||
let tx1_changed = local_epoch_rx1.changed().await;
|
||||
let tx2_changed = epoch_difference_rx1.changed().await;
|
||||
let local_epoch = *local_epoch_rx1.borrow();
|
||||
let difference_epoch = *epoch_difference_rx1.borrow();
|
||||
match tx1_changed {
|
||||
Ok(T) => match tx2_changed {
|
||||
Ok(T) => {
|
||||
|
|
@ -1424,47 +1314,41 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
}
|
||||
});
|
||||
|
||||
// Task#27: request delist symbols
|
||||
tokio::task::spawn(async move {
|
||||
let mut elapsed_time = 0;
|
||||
loop {
|
||||
let instant = Instant::now();
|
||||
let client = ClientBuilder::new()
|
||||
.timeout(tokio::time::Duration::from_millis(3000))
|
||||
.build()
|
||||
.unwrap();
|
||||
let tx1_changed = local_epoch_rx2.changed().await;
|
||||
let tx2_changed = epoch_difference_rx2.changed().await;
|
||||
let local_epoch = *local_epoch_rx2.borrow();
|
||||
let difference_epoch = *epoch_difference_rx2.borrow();
|
||||
|
||||
|
||||
let result = request_others::request_delist_symbols(
|
||||
API_KEY,
|
||||
SECRET_KEY,
|
||||
local_epoch,
|
||||
difference_epoch,
|
||||
&client
|
||||
)
|
||||
.await;
|
||||
|
||||
tx_task27.send(27).expect("The mpsc channel has been closed.");
|
||||
|
||||
// sleep as much as the loop recurs per 300 seconds if all operation finished within 300 seconds.
|
||||
elapsed_time = instant.elapsed().as_secs();
|
||||
if 300 > elapsed_time {
|
||||
sleep(Duration::from_secs((300 - elapsed_time) as u64)).await;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
loop {
|
||||
// println!("test limit order 실행");
|
||||
// let client = ClientBuilder::new().timeout(Duration::from_millis(1000)).build().unwrap();
|
||||
// limit_order_buy_test(&client).await;
|
||||
// let instant = Instant::now();
|
||||
// let mut elapsed_time = 0;
|
||||
// let capacity_vec_1 = tradefee_vec_capacity.borrow().clone();
|
||||
// let capacity_vec_2 = valid_usdt_trade_vec_capacity.borrow().clone();
|
||||
// let capacity_vec_3 = price_vec_capacity.borrow().clone();
|
||||
// let capacity_vec_4 = candle_1m_vec_capacity.borrow().clone();
|
||||
// let capacity_vec_5 = candle_30m_vec_capacity.borrow().clone();
|
||||
// let capacity_vec_6 = candle_1d_vec_capacity.borrow().clone();
|
||||
// let capacity_vec_7 = candle_1w_vec_capacity.borrow().clone();
|
||||
// let capacity_vec_8 = candle_1mon_vec_capacity.borrow().clone();
|
||||
// let capacity_vec_9 = rt_price_1m_vec_capacity.borrow().clone();
|
||||
// let capacity_vec_10 = rt_price_30m_vec_capacity.borrow().clone();
|
||||
// let capacity_vec_11 = rt_price_1d_vec_capacity.borrow().clone();
|
||||
// let capacity_vec_12 = rt_price_1w_vec_capacity.borrow().clone();
|
||||
// let capacity_vec_13 = rt_price_1mon_vec_capacity.borrow().clone();
|
||||
// let capacity_vec_14 = exchange_info_data_capacity.borrow().clone();
|
||||
|
||||
// println!("@@ {:3}, {:3}, {:3}, {:3}, {:3}, {:3}, {:3}, {:3}, {:3}, {:3}, {:3}, {:3}, {:3}, {:3},",
|
||||
// capacity_vec_1.capacity(),
|
||||
// capacity_vec_2.capacity(),
|
||||
// capacity_vec_3.capacity(),
|
||||
// capacity_vec_4.capacity(),
|
||||
// capacity_vec_5.capacity(),
|
||||
// capacity_vec_6.capacity(),
|
||||
// capacity_vec_7.capacity(),
|
||||
// capacity_vec_8.capacity(),
|
||||
// capacity_vec_9.capacity(),
|
||||
// capacity_vec_10.capacity(),
|
||||
// capacity_vec_11.capacity(),
|
||||
// capacity_vec_12.capacity(),
|
||||
// capacity_vec_13.capacity(),
|
||||
// capacity_vec_14.capacity());
|
||||
|
||||
// elapsed_time = instant.elapsed().as_millis();
|
||||
// if 1_000 > elapsed_time {
|
||||
// sleep(Duration::from_millis((1_000 - elapsed_time) as u64)).await;
|
||||
// }
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user