Make mod.rs

This commit is contained in:
Sik Yoon 2023-11-18 23:51:29 +09:00
parent abd03aaeab
commit de71293f0b
23 changed files with 2718 additions and 8429 deletions

854
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -24,4 +24,3 @@ thirtyfour = { version = "0.28.1", features = ["tokio-runtime"]}
ord_subset = "3.1.1"
rust_decimal = "1.29.1"
rust_decimal_macros = "1.29.1"
plotters = "0.3.1"

View File

@ -1,6 +1,6 @@
use crate::coex::assets_managing_team::*;
use crate::coex::order_team::*;
use crate::coex::strategy_team::AllData;
use crate::strategy_team::AllData;
use crate::coin_health_check_team::request_others::{CoinPriceData, ExchangeInfo, TradeFee};
use crate::database_control::*;
use crate::decimal_funcs::{decimal, decimal_add, decimal_div, decimal_mul, decimal_sub};

View File

@ -1,4 +1,3 @@
pub mod assets_managing_team;
pub mod exchange_team;
pub mod order_team;
pub mod strategy_team;

View File

@ -11,8 +11,7 @@ use crate::URL_TEST;
// use crates
use crate::coex::assets_managing_team::*;
use crate::coex::exchange_team::*;
use crate::coex::strategy_team::AllData;
use crate::coex::strategy_team::TimeData;
use crate::strategy_team::{AllData, TimeData};
use crate::coin_health_check_team::request_others::{CoinPriceData, ExchangeInfo, TradeFee};
use crate::database_control::*;
use crate::decimal_funcs::*;

File diff suppressed because it is too large Load Diff

View File

@ -748,7 +748,7 @@ where
let mut conn_result = sqlx::mysql::MySqlConnection::connect(DB_URL).await;
//retry connection until it will be done.
while conn_result.is_err() {
sleep(Duration::from_millis(200)).await;
sleep(Duration::from_millis(50)).await;
conn_result = sqlx::mysql::MySqlConnection::connect(DB_URL).await;
}
let mut conn = conn_result.unwrap();

View File

@ -22,13 +22,15 @@ pub enum RunningMode {
TEST,
REAL,
}
pub const RUNNING_MODE: RunningMode = RunningMode::REAL;
pub const RUNNING_MODE: RunningMode = RunningMode::SIMUL;
mod coex;
mod coin_health_check_team;
mod database_control;
mod decimal_funcs;
mod server_health_check_team;
mod signal_association;
mod time_checking_team;
mod value_estimation_team;
pub mod coex;
pub mod coin_health_check_team;
pub mod database_control;
pub mod decimal_funcs;
pub mod server_health_check_team;
pub mod signal_association;
pub mod time_checking_team;
pub mod value_estimation_team;
pub mod strategy_team;
pub mod initialization;

View File

@ -1,18 +1,7 @@
#![allow(unused)]
#![allow(warnings)]
mod coex;
mod coin_health_check_team;
mod database_control;
mod decimal_funcs;
mod initialization;
mod server_health_check_team;
mod signal_association;
mod time_checking_team;
mod value_estimation_team;
use crate::coex::order_team::*;
use crate::coex::strategy_team::AllData;
use crate::strategy_team::AllData;
use crate::coin_health_check_team::*;
use crate::request_candles::CandleData;
use crate::request_others::{CoinPriceData, ExchangeInfo, TradeFee};
@ -84,6 +73,7 @@ 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 mut rx1_2 = rx1_1.clone();
@ -198,6 +188,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut rx2_exchange_info_data = rx_exchange_info_data.clone();
let mut rx3_exchange_info_data = rx_exchange_info_data.clone();
let mut rx4_exchange_info_data = rx_exchange_info_data.clone();
let mut rx5_exchange_info_data = rx_exchange_info_data.clone();
{
if RUNNING_MODE == RunningMode::REAL {
@ -268,99 +259,103 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
match result {
Some(1) => {
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!("\r1[■] 2[ ] 3[ ] 4[ ] 5[ ] 6[ ] 7[ ] 8[ ] 9[ ] 12[ ] 13[ ] 14[ ] 15[ ] 16[ ] 17[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] 25[■] 26[ ] 27[ ]");
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!("\r1[ ] 2[ ] 3[ ] 4[ ] 5[ ] 6[ ] 7[ ] 8[ ] 9[ ] 12[ ] 13[ ] 14[ ] 15[ ] 16[ ] 17[ ] 18[ ] 19[ ] 20[ ] 21[ ] 22[ ] 23[ ] 24[ ] 25[ ] 26[■] 27[ ]");
io::stdout().flush();
}
Some(27) => {
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[ ] 27[■]");
io::stdout().flush();
}
Some(_) => {}
@ -529,8 +524,51 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
}
});
// Task#3: request 24h price changes, pick valid USDT Trades, monitor total_24h_change_profit_index, usdt_24h_change_profit_index, total_price_down_dist_index
// Task#13: request lot stepsize and ticksize
tokio::task::spawn(async move {
let client = ClientBuilder::new()
.timeout(tokio::time::Duration::from_millis(3000))
.build()
.unwrap();
loop {
let mut exchange_info_data_temp: Vec<ExchangeInfo> = Vec::new();
let mut result;
loop {
result = coin_health_check_team::request_others::request_exchange_infomation(
&client,
&mut exchange_info_data_temp,
)
.await;
// retry
if exchange_info_data_temp.len() == 0 {
sleep(Duration::from_secs(3)).await;
} else {
break;
}
}
match result {
Ok(T) => {
tx_exchange_info_data.send_modify(|vec| *vec = exchange_info_data_temp);
tx_task13
.send(13)
.expect("The mpsc channel has been closed.");
}
Err(E) => {}
}
sleep(Duration::from_secs(300)).await; // sleep for 5 mins
}
});
// Task#3: request 24h price changes,
// pick valid USDT Trades,
// filtering stop USDT Trades,
// monitor total_24h_change_profit_index,
// usdt_24h_change_profit_index,
// total_price_down_dist_index
tokio::task::spawn(async move {
sleep(Duration::from_secs(10)).await;
let client = ClientBuilder::new()
.timeout(tokio::time::Duration::from_millis(3000))
.build()
@ -541,9 +579,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let result = request_others::request_24hr_ticker_price_change_statistics(&client).await;
match result {
Ok(T) => {
let exchange_info_vec = rx5_exchange_info_data.borrow().clone();
let mut valid_usdt_trade_vec_temp: Vec<String> = Vec::new();
let result =
monitors::collect_valid_usde_trade(&mut valid_usdt_trade_vec_temp).await;
monitors::collect_valid_usde_trade(&mut valid_usdt_trade_vec_temp, &exchange_info_vec).await;
match result {
Ok(T) => {
@ -881,43 +920,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
});
}
// Task#13: request lot stepsize and ticksize
tokio::task::spawn(async move {
let client = ClientBuilder::new()
.timeout(tokio::time::Duration::from_millis(3000))
.build()
.unwrap();
loop {
let mut exchange_info_data_temp: Vec<ExchangeInfo> = Vec::new();
let mut result;
loop {
result = coin_health_check_team::request_others::request_exchange_infomation(
&client,
&mut exchange_info_data_temp,
)
.await;
// retry
if exchange_info_data_temp.len() == 0 {
sleep(Duration::from_secs(3)).await;
} else {
break;
}
}
match result {
Ok(T) => {
tx_exchange_info_data.send_modify(|vec| *vec = exchange_info_data_temp);
tx_task13
.send(13)
.expect("The mpsc channel has been closed.");
}
Err(E) => {}
}
sleep(Duration::from_secs(1200)).await; // sleep for 20mins
}
});
// Task#14: monitoring foreign exchange rate
if RUNNING_MODE == REAL || RUNNING_MODE == SIMUL {
tokio::task::spawn(async move {
@ -1008,7 +1010,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
// all_data.rt_price_1w_vec = rx3_rt_price_1w_vec.borrow().clone();
// all_data.rt_price_1mon_vec = rx3_rt_price_1mon_vec.borrow().clone();
let result = coex::strategy_team::execute_strategists(&all_data).await;
let result = strategy_team::strategy_manager::execute_list_up_for_buy(&all_data).await;
match result {
Ok(T) => {
@ -1017,7 +1019,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.expect("The mpsc channel has been closed.");
}
Err(E) => {
eprintln!("Couldn't execute strategists.");
// eprintln!("Couldn't execute strategists.");
}
}
@ -1382,6 +1384,34 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
}
});
// Task#27: update kelly_criterion
tokio::task::spawn(async move {
let mut elapsed_time = 0;
loop {
let instant = Instant::now();
let result =
coex::assets_managing_team::update_kelly_criterion().await;
// send Task#0 a message to notify running on
match result {
Ok(T) => {
tx_task27
.send(27)
.expect("The mpsc channel has been closed.");
}
Err(E) => {
println!("{}", E);
}
}
// sleep as much as the loop recurs per 1 minutes
elapsed_time = instant.elapsed().as_secs();
if 60 > elapsed_time {
sleep(Duration::from_secs((60 - elapsed_time) as u64)).await;
}
}
});
loop {
// println!("test limit order 실행");
// let client = ClientBuilder::new().timeout(Duration::from_millis(1000)).build().unwrap();

58
src/strategy_team/mod.rs Normal file
View File

@ -0,0 +1,58 @@
pub mod strategy_manager;
pub mod strategy_001;
pub mod strategy_002;
pub mod strategy_003;
pub mod strategy_004;
pub mod strategy_005;
pub mod strategy_006;
use std::{sync::Arc};
use crate::database_control::*;
use crate::value_estimation_team::datapoints::price_data::RealtimePriceData;
use crate::value_estimation_team::indicators::macd::{ema_macd, EmaMacd};
use crate::value_estimation_team::indicators::rsi::{rsi, RsiData};
use crate::value_estimation_team::indicators::sma::{sma, SmaData};
use crate::value_estimation_team::indicators::ema::{ema, EmaData};
use crate::value_estimation_team::indicators::bollingerband::{bollingerband, BollingerBandData};
use crate::value_estimation_team::indicators::stoch_rsi::{stoch_rsi, StochRsiData};
use crate::value_estimation_team::indicators::supertrend::{supertrend, SupertrendData};
use crate::value_estimation_team::indicators::heatmap_volume::{
heatmap_volume, HeatMapLevel, HeatmapVolumeData,
};
use futures::future::try_join_all;
use sqlx::FromRow;
use tokio::sync::Mutex;
#[derive(Debug)]
pub struct AllData {
pub valid_symbol_vec: Vec<String>,
pub rt_price_1m_vec: Vec<(String, Vec<RealtimePriceData>)>,
pub rt_price_30m_vec: Vec<(String, Vec<RealtimePriceData>)>,
pub rt_price_1d_vec: Vec<(String, Vec<RealtimePriceData>)>,
pub rt_price_1w_vec: Vec<(String, Vec<RealtimePriceData>)>,
pub rt_price_1mon_vec: Vec<(String, Vec<RealtimePriceData>)>,
}
impl AllData {
pub fn new() -> AllData {
let a = AllData {
valid_symbol_vec: Vec::new(),
rt_price_1m_vec: Vec::new(),
rt_price_30m_vec: Vec::new(),
rt_price_1d_vec: Vec::new(),
rt_price_1w_vec: Vec::new(),
rt_price_1mon_vec: Vec::new(),
};
a
}
}
#[derive(Debug, FromRow)]
pub struct TimeData {
pub server_epoch: u64,
pub local_epoch: u64,
pub epoch_difference: i64,
pub server_ymdhs: String,
pub local_ymdhs: String,
pub last_server_epoch: u64,
pub last_server_ymdhs: String,
}

View File

@ -0,0 +1,424 @@
// pub async fn strategist_001(
// alldata: &AllData,
// ) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
// // print rt_price for debugging
// // let a = alldata.rt_price_30m_vec.iter().position(|a| a.0 == "BTCUSDT");
// // println!("BTCUSDT: {:?}", alldata.rt_price_30m_vec[a.unwrap()].1.last().unwrap());
// // // 1st filtering: supertrend(ATR period 10, multiplier: 1.3, 30m close price), the area should be in SELL area.
// // let mut filtered_2nd_symbols: Vec<(String, i64)> = Vec::new();
// // let mut filtered_2nd_symbols_arc: Arc<Mutex<Vec<(String, i64)>>> =
// // Arc::new(Mutex::new(filtered_2nd_symbols)); // (symbol, closetime)
// // let mut task_vec = Vec::new();
// // let valid_symbol_vec_c = alldata.valid_symbol_vec.clone();
// // for symbol in valid_symbol_vec_c {
// // let mut opclo_30m_vec: Vec<RealtimePriceData> = Vec::new();
// // let mut supertrend_vec: Vec<SupertrendData> = Vec::new();
// // let rt_price_30m_vec_c = alldata.rt_price_30m_vec.clone();
// // let filtered_2nd_symbols_arc_c = Arc::clone(&filtered_2nd_symbols_arc);
// // task_vec.push(tokio::spawn(async move {
// // let opclo_30m_option = rt_price_30m_vec_c.iter().position(|x| *x.0 == symbol);
// // let supertrend_option_30m =
// // supertrend(&symbol, &rt_price_30m_vec_c, 10, 1.3, true).await;
// // if opclo_30m_option.is_some() && supertrend_option_30m.is_some() {
// // opclo_30m_vec = rt_price_30m_vec_c[opclo_30m_option.unwrap()].1.clone();
// // supertrend_vec = supertrend_option_30m.unwrap();
// // if opclo_30m_vec.len() >= 3 && supertrend_vec.len() >= 3 {
// // let supertrend_search_result = supertrend_vec.binary_search_by_key(
// // &opclo_30m_vec.last().unwrap().close_time,
// // |SupertrendData {
// // band_value,
// // signal,
// // area,
// // close_time,
// // }| *close_time,
// // );
// // if supertrend_search_result.is_ok() {
// // if supertrend_vec[supertrend_search_result.unwrap()]
// // .area
// // .contains("DOWN")
// // {
// // let mut filtered_2nd_symbols_lock =
// // filtered_2nd_symbols_arc_c.lock().await;
// // filtered_2nd_symbols_lock
// // .push((symbol.clone(), opclo_30m_vec.last().unwrap().close_time));
// // }
// // }
// // }
// // }
// // }));
// // }
// // try_join_all(task_vec).await?;
// // 1st filtering: making basic form
// let mut filtered_2nd_symbols: Vec<(String, i64)> = Vec::new();
// let mut filtered_2nd_symbols_arc: Arc<Mutex<Vec<(String, i64)>>> =
// Arc::new(Mutex::new(filtered_2nd_symbols)); // (symbol, closetime)
// let mut task_vec = Vec::new();
// let valid_symbol_vec_c = alldata.valid_symbol_vec.clone();
// for symbol in valid_symbol_vec_c {
// let mut opclo_30m_vec: Vec<RealtimePriceData> = Vec::new();
// let rt_price_30m_vec_c = alldata.rt_price_30m_vec.clone();
// let filtered_2nd_symbols_arc_c = Arc::clone(&filtered_2nd_symbols_arc);
// task_vec.push(tokio::spawn(async move {
// let opclo_30m_option = rt_price_30m_vec_c.iter().position(|x| *x.0 == symbol);
// if opclo_30m_option.is_some() {
// opclo_30m_vec = rt_price_30m_vec_c[opclo_30m_option.unwrap()].1.clone();
// if opclo_30m_vec.len() >= 3 {
// let mut filtered_2nd_symbols_lock =
// filtered_2nd_symbols_arc_c.lock().await;
// filtered_2nd_symbols_lock
// .push((symbol.clone(), opclo_30m_vec.last().unwrap().close_time));
// }
// }
// }));
// }
// try_join_all(task_vec).await?;
// // 2nd filtering: lookup tables if the tradepair is already there
// let inspect_table_name_1 = String::from("buy_ordered_coin_list");
// let inspect_table_name_2 = String::from("sell_ordered_coin_list");
// let inspect_table_name_3 = String::from("pre_suggested_coin_list");
// let inspect_table_name_4 = String::from("suggested_coin_list");
// let mut filtered_3rd_symbols: Vec<(String, i64)> = Vec::new();
// let mut filtered_3rd_symbols_arc: Arc<Mutex<Vec<(String, i64)>>> =
// Arc::new(Mutex::new(filtered_3rd_symbols)); // (symbol, closetime)
// let mut task_vec = Vec::new();
// let filtered_2nd_iter = filtered_2nd_symbols_arc.lock().await.clone().into_iter();
// for element in filtered_2nd_iter {
// let mut exists_condition_build = String::from("symbol=\'");
// exists_condition_build.push_str(element.0.as_str());
// exists_condition_build.push_str("\' AND registerer=");
// exists_condition_build.push_str(1.to_string().as_str());
// // exists_condition_build.push_str("\' AND close_time=");
// // exists_condition_build.push_str(element.1.to_string().as_str());
// let exists_condition = Some(exists_condition_build);
// let exists_condition_c = exists_condition.clone();
// let inspect_table_name_1_c = inspect_table_name_1.clone();
// let inspect_table_name_2_c = inspect_table_name_2.clone();
// let inspect_table_name_3_c = inspect_table_name_3.clone();
// let inspect_table_name_4_c = inspect_table_name_4.clone();
// let element_c = element.clone();
// let filtered_3rd_symbols_arc_c = Arc::clone(&filtered_3rd_symbols_arc);
// task_vec.push(tokio::spawn(async move {
// let inspect_result_1 =
// exists_record(&inspect_table_name_1_c, &exists_condition_c).await;
// let inspect_result_2 =
// exists_record(&inspect_table_name_2_c, &exists_condition_c).await;
// let inspect_result_3 =
// exists_record(&inspect_table_name_3_c, &exists_condition_c).await;
// let inspect_result_4 =
// exists_record(&inspect_table_name_4_c, &exists_condition_c).await;
// if inspect_result_1 == false
// && inspect_result_2 == false
// && inspect_result_3 == false
// && inspect_result_4 == false
// {
// let mut filtered_3rd_symbols_lock = filtered_3rd_symbols_arc_c.lock().await;
// filtered_3rd_symbols_lock.push(element_c);
// }
// }));
// }
// try_join_all(task_vec).await?;
// // 3rd filtering: BollingerBand (length 10, stddev: 2.5, 30m close price) the current price should be under the lowerband of BB.
// let filtered_3rd_symbols_c = filtered_3rd_symbols_arc.lock().await.clone();
// let sma10_30m_data: Vec<(String, Vec<SmaData>)> = sma(
// 10,
// &alldata.rt_price_30m_vec,
// &filtered_3rd_symbols_c,
// )
// .await?;
// let bb10_30m_data: Vec<(String, Vec<BollingerBandData>)> =
// bollingerband(
// 10,
// 3.0,
// &sma10_30m_data,
// &alldata.rt_price_30m_vec,
// &filtered_3rd_symbols_c,
// )
// .await?;
// let mut task_vec = Vec::new();
// let mut filtered_4th_symbols: Vec<(String, i64)> = Vec::new();
// let mut filtered_4th_symbols_arc: Arc<Mutex<Vec<(String, i64)>>> =
// Arc::new(Mutex::new(filtered_4th_symbols)); // (symbol, closetime)
// for element in filtered_3rd_symbols_c {
// let mut bb10_30m_vec: Vec<BollingerBandData> = Vec::new();
// let bb10_30m_option = bb10_30m_data.iter().position(|x| *x.0 == element.0);
// let bb10_30m_option_c = bb10_30m_option.clone();
// let element_c = element.clone();
// let filtered_4th_symbols_arc_c = Arc::clone(&filtered_4th_symbols_arc);
// if bb10_30m_option_c.is_some() {
// bb10_30m_vec = bb10_30m_data[bb10_30m_option_c.unwrap()].1.clone();
// if bb10_30m_vec.len() >= 3 {
// let bb10_30m_vec_c = bb10_30m_vec.clone();
// let current_price = get_current_price(&element_c.0, &alldata.rt_price_30m_vec)
// .await
// .unwrap();
// task_vec.push(tokio::spawn(async move {
// let bb_search_result = bb10_30m_vec_c.binary_search_by_key(
// &element_c.1,
// |&BollingerBandData {
// sma,
// upperband,
// lowerband,
// close_time,
// }| close_time,
// );
// if bb_search_result.is_ok() {
// if bb10_30m_vec_c[bb_search_result.unwrap()].lowerband > current_price {
// let mut filtered_4th_symbols_lock =
// filtered_4th_symbols_arc_c.lock().await;
// filtered_4th_symbols_lock.push(element_c);
// }
// }
// }));
// }
// }
// }
// try_join_all(task_vec).await?;
// // 4th filtering: the current price should be lower than lowest price from the latest 20 candles.
// let mut task_vec = Vec::new();
// let filtered_4th_symbols_c = filtered_4th_symbols_arc.lock().await.clone();
// let mut filtered_5th_symbols: Vec<(String, i64)> = Vec::new();
// let mut filtered_5th_symbols_arc: Arc<Mutex<Vec<(String, i64)>>> =
// Arc::new(Mutex::new(filtered_5th_symbols)); // (symbol, closetime)
// for element in filtered_4th_symbols_c {
// let rt_price_30m_option = alldata.rt_price_30m_vec.iter().position(|x| *x.0 == element.0);
// let element_c = element.clone();
// let filtered_5th_symbols_arc_c = Arc::clone(&filtered_5th_symbols_arc);
// if rt_price_30m_option.is_some() {
// let mut rt_price_30m_vec_c = alldata.rt_price_30m_vec[rt_price_30m_option.unwrap()].1.clone();
// let current_price = get_current_price(&element_c.0, &alldata.rt_price_30m_vec)
// .await
// .unwrap();
// task_vec.push(tokio::spawn(async move {
// if rt_price_30m_vec_c.len() >= 21 {
// rt_price_30m_vec_c.pop();
// rt_price_30m_vec_c.reverse();
// rt_price_30m_vec_c.truncate(20);
// let lowest_price_option = rt_price_30m_vec_c.iter()
// .enumerate()
// .min_by(|(_, a), (_, b)| {
// a.low_price
// .partial_cmp(&b.low_price)
// .expect("Nan was forbidden.")
// })
// .map(|(index, _)| index);
// if lowest_price_option.is_some() {
// let lowest_price = rt_price_30m_vec_c[lowest_price_option.unwrap()].low_price;
// if lowest_price > current_price {
// let mut filtered_5th_symbols_lock =
// filtered_5th_symbols_arc_c.lock().await;
// filtered_5th_symbols_lock.push(element_c);
// }
// }
// }
// }));
// }
// }
// try_join_all(task_vec).await?;
// // 5th filtering: RSI (length: 10, 30m close price) the current index should be lower than 30.
// let filtered_5th_symbol_c = filtered_5th_symbols_arc.lock().await.clone();
// let mut rsi10_30m_data: Vec<(String, Vec<RsiData>)> = rsi(
// 10,
// &alldata.rt_price_30m_vec,
// &filtered_5th_symbol_c,
// )
// .await?;
// let mut task_vec = Vec::new();
// let mut filtered_6th_symbols: Vec<(String, i64)> = Vec::new(); // (symbol, closetime)
// let mut filtered_6th_symbols_arc: Arc<Mutex<Vec<(String, i64)>>> =
// Arc::new(Mutex::new(filtered_6th_symbols)); // (symbol, closetime)
// for element in filtered_5th_symbol_c {
// let rsi10_30m_option = rsi10_30m_data.iter().position(|x| *x.0 == element.0);
// let filtered_6th_symbols_arc_c = Arc::clone(&filtered_6th_symbols_arc);
// if rsi10_30m_option.is_some() {
// let mut rsi10_30m_vec = rsi10_30m_data[rsi10_30m_option.unwrap()].1.clone();
// if rsi10_30m_vec.len() >= 3 {
// let element_c = element.clone();
// task_vec.push(tokio::spawn(async move {
// let rsi_search_result = rsi10_30m_vec.binary_search_by_key(
// &element.1,
// |&RsiData {
// rsi_value,
// close_time,
// }| close_time,
// );
// if rsi_search_result.is_ok() {
// if rsi10_30m_vec[rsi_search_result.unwrap()].rsi_value <= 20.0 {
// let mut filtered_6th_symbols_lock =
// filtered_6th_symbols_arc_c.lock().await;
// filtered_6th_symbols_lock.push(element_c);
// }
// }
// }));
// }
// }
// }
// try_join_all(task_vec).await?;
// // 6th filtering: StochRSI (RSI length: 14, Stoch length: 14, smooth k: 3, smooth d: 3) smooth kn <= 10, kn-1 <= 25.0
// let filtered_6th_symbol_c = filtered_6th_symbols_arc.lock().await.clone();
// let mut rsi14_30m_data: Vec<(String, Vec<RsiData>)> = rsi(
// 14,
// &alldata.rt_price_30m_vec,
// &filtered_6th_symbol_c,
// )
// .await?;
// let stoch_rsi_data = stoch_rsi(&rsi14_30m_data, 14, 3, 3).await?;
// let mut stoch_rsi14_30m_vec: Vec<StochRsiData> = Vec::new();
// let mut filtered_7th_symbols: Vec<(String, i64)> = Vec::new(); // (symbol, closetime)
// for element in filtered_6th_symbol_c {
// let stoch_rsi14_30m_option = stoch_rsi_data.iter().position(|x| *x.0 == element.0);
// if stoch_rsi14_30m_option.is_some() {
// stoch_rsi14_30m_vec = stoch_rsi_data[stoch_rsi14_30m_option.unwrap()].1.clone();
// if stoch_rsi14_30m_vec.len() >= 3 {
// let stoch_rsi_search_result = stoch_rsi14_30m_vec.binary_search_by_key(
// &element.1,
// |&StochRsiData {
// k,
// d,
// close_time,
// }| close_time,
// );
// if stoch_rsi_search_result.is_ok() {
// if stoch_rsi14_30m_vec[stoch_rsi_search_result.unwrap()].k <= 10.0 && stoch_rsi14_30m_vec[stoch_rsi_search_result.unwrap()-1].k <= 25.0 {
// filtered_7th_symbols.push(element);
// }
// }
// }
// }
// }
// // 7th filtering: heatmap volume(MA length 10, std length 10, 30m close price), the current candle should be over than high at least.
// let mut filtered_8th_symbols: Vec<(String, i64)> = Vec::new(); // (symbol, closetime)
// for element in filtered_7th_symbols {
// let rt_price_30m_vec_c = alldata.rt_price_30m_vec.clone();
// let opclo_30m_option = rt_price_30m_vec_c.iter().position(|x| *x.0 == element.0);
// if opclo_30m_option.is_some() {
// let opclo_30m_vec = rt_price_30m_vec_c[opclo_30m_option.unwrap()].1.clone();
// if opclo_30m_vec.len() >= 3 {
// let heatmap_volume_option =
// heatmap_volume(&element.0, &rt_price_30m_vec_c, 10, 10, 4.0, 2.5, 1.0, -0.5)
// .await;
// if heatmap_volume_option.is_some() {
// let heatmap_volume_vec = heatmap_volume_option.unwrap();
// let heatmap_search_result = heatmap_volume_vec.binary_search_by_key(
// &element.1,
// |HeatmapVolumeData {
// heatmap_value,
// heatmap_level,
// close_time,
// }| *close_time,
// );
// if heatmap_search_result.is_ok() {
// if heatmap_volume_vec[heatmap_search_result.unwrap()].heatmap_level
// == HeatMapLevel::Medium
// ||
// heatmap_volume_vec[heatmap_search_result.unwrap()].heatmap_level
// == HeatMapLevel::High
// || heatmap_volume_vec[heatmap_search_result.unwrap()].heatmap_level
// == HeatMapLevel::ExtraHigh
// {
// filtered_8th_symbols.push(element);
// }
// }
// }
// }
// }
// }
// // final job: adding price information to filtered results
// let mut filtered_symbols: Vec<(String, i64, f64)> = Vec::new(); // (symbol, closetime, current price)
// let mut filtered_symbols_arc = Arc::new(Mutex::new(filtered_symbols));
// let mut task_vec = Vec::new();
// for element in filtered_8th_symbols {
// let mut filtered_symbols_arc_c = Arc::clone(&filtered_symbols_arc);
// let rt_price_30m_vec_c = alldata.rt_price_30m_vec.clone();
// let elememt_c = element.clone();
// task_vec.push(tokio::spawn(async move {
// let opclo_30m_option = rt_price_30m_vec_c.iter().position(|x| *x.0 == element.0);
// if opclo_30m_option.is_some() {
// if rt_price_30m_vec_c[opclo_30m_option.unwrap()]
// .1
// .last()
// .is_some()
// {
// let mut filtered_symbols_lock: tokio::sync::MutexGuard<
// '_,
// Vec<(String, i64, f64)>,
// > = filtered_symbols_arc_c.lock().await;
// filtered_symbols_lock.push((
// elememt_c.0,
// elememt_c.1,
// rt_price_30m_vec_c[opclo_30m_option.unwrap()]
// .1
// .last()
// .unwrap()
// .close_price,
// ));
// }
// }
// }));
// }
// try_join_all(task_vec).await?;
// // 6th filtering condition: MACD
// // let mut opclo_30m_vec: Vec<RealtimePriceData> = Vec::new();
// // let mut ema3_1d_vec: &Vec<EmaData> = &Vec::new();
// // let mut ema10_1d_vec: &Vec<EmaData> = &Vec::new();
// // let mut filtered_7th_symbols: Vec<(String, i64)> = Vec::new(); // (symbol, closetime)
// // for element in filtered_6th_symbols {
// // let ema3_1d_option = alldata.ema3_1d_data.iter().position(|x| *x.0 == *element.0);
// // let ema10_1d_option = alldata.ema10_1d_data.iter().position(|x| *x.0 == *element.0);
// // if ema3_1d_option.is_some() && ema10_1d_option.is_some() {
// // ema3_1d_vec = &alldata.ema3_1d_data[ema3_1d_option.unwrap()].1;
// // ema10_1d_vec = &alldata.ema10_1d_data[ema10_1d_option.unwrap()].1;
// // if ema3_1d_vec.len() > 20 && ema10_1d_vec.len() > 20 {
// // let macd_vec = ema_macd(&ema3_1d_vec, &ema10_1d_vec, 10).await?;
// // // let macd_search_result = macd_vec.binary_search_by_key(&element.1, |&EmaMacd{macd_value, close_time}|close_time);
// // // if macd_search_result.is_ok() {
// // if macd_vec.last().unwrap().macd_value - macd_vec[macd_vec.len() -2].macd_value >= 0.0 {
// // filtered_7th_symbols.push(element);
// // }
// // // }
// // }
// // }
// // }
// let a = filtered_symbols_arc.lock().await.clone();
// insert_pre_suggested_coins(1, false, &a, alldata).await;
// Ok(())
// }

View File

@ -0,0 +1,277 @@
// pub async fn strategist_002(
// alldata: &AllData,
// ) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
// // print rt_price for debugging
// // let a = alldata.rt_price_30m_vec.iter().position(|a| a.0 == "BTCUSDT");
// // println!("BTCUSDT: {:?}", alldata.rt_price_30m_vec[a.unwrap()].1.last().unwrap());
// // 1st filtering: making basic form
// let mut filtered_2nd_symbols: Vec<(String, i64)> = Vec::new();
// let mut filtered_2nd_symbols_arc: Arc<Mutex<Vec<(String, i64)>>> =
// Arc::new(Mutex::new(filtered_2nd_symbols)); // (symbol, closetime)
// let mut task_vec = Vec::new();
// let valid_symbol_vec_c = alldata.valid_symbol_vec.clone();
// for symbol in valid_symbol_vec_c {
// let mut opclo_30m_vec: Vec<RealtimePriceData> = Vec::new();
// let rt_price_30m_vec_c = alldata.rt_price_30m_vec.clone();
// let filtered_2nd_symbols_arc_c = Arc::clone(&filtered_2nd_symbols_arc);
// task_vec.push(tokio::spawn(async move {
// let opclo_30m_option = rt_price_30m_vec_c.iter().position(|x| *x.0 == symbol);
// if opclo_30m_option.is_some() {
// opclo_30m_vec = rt_price_30m_vec_c[opclo_30m_option.unwrap()].1.clone();
// if opclo_30m_vec.len() >= 3 {
// let mut filtered_2nd_symbols_lock =
// filtered_2nd_symbols_arc_c.lock().await;
// filtered_2nd_symbols_lock
// .push((symbol.clone(), opclo_30m_vec.last().unwrap().close_time));
// }
// }
// }));
// }
// try_join_all(task_vec).await?;
// // 2nd filtering: lookup tables if the tradepair is already there
// let inspect_table_name_1 = String::from("buy_ordered_coin_list");
// let inspect_table_name_2 = String::from("sell_ordered_coin_list");
// let inspect_table_name_3 = String::from("pre_suggested_coin_list");
// let inspect_table_name_4 = String::from("suggested_coin_list");
// let mut filtered_3rd_symbols: Vec<(String, i64)> = Vec::new();
// let mut filtered_3rd_symbols_arc: Arc<Mutex<Vec<(String, i64)>>> =
// Arc::new(Mutex::new(filtered_3rd_symbols)); // (symbol, closetime)
// let mut task_vec = Vec::new();
// let filtered_2nd_iter = filtered_2nd_symbols_arc.lock().await.clone().into_iter();
// for element in filtered_2nd_iter {
// let mut exists_condition_build = String::from("symbol=\'");
// exists_condition_build.push_str(element.0.as_str());
// exists_condition_build.push_str("\' AND registerer=");
// exists_condition_build.push_str(2.to_string().as_str());
// // exists_condition_build.push_str("\' AND close_time=");
// // exists_condition_build.push_str(element.1.to_string().as_str());
// let exists_condition = Some(exists_condition_build);
// let exists_condition_c = exists_condition.clone();
// let inspect_table_name_1_c = inspect_table_name_1.clone();
// let inspect_table_name_2_c = inspect_table_name_2.clone();
// let inspect_table_name_3_c = inspect_table_name_3.clone();
// let inspect_table_name_4_c = inspect_table_name_4.clone();
// let element_c = element.clone();
// let filtered_3rd_symbols_arc_c = Arc::clone(&filtered_3rd_symbols_arc);
// task_vec.push(tokio::spawn(async move {
// let inspect_result_1 =
// exists_record(&inspect_table_name_1_c, &exists_condition_c).await;
// let inspect_result_2 =
// exists_record(&inspect_table_name_2_c, &exists_condition_c).await;
// let inspect_result_3 =
// exists_record(&inspect_table_name_3_c, &exists_condition_c).await;
// let inspect_result_4 =
// exists_record(&inspect_table_name_4_c, &exists_condition_c).await;
// if inspect_result_1 == false
// && inspect_result_2 == false
// && inspect_result_3 == false
// && inspect_result_4 == false
// {
// let mut filtered_3rd_symbols_lock = filtered_3rd_symbols_arc_c.lock().await;
// filtered_3rd_symbols_lock.push(element_c);
// }
// }));
// }
// try_join_all(task_vec).await?;
// // 3rd filtering: EMA30 > EMA 150
// let filtered_3rd_symbols_c = filtered_3rd_symbols_arc.lock().await.clone();
// let ema30_30m_data: Vec<(String, Vec<EmaData>)> = ema(
// 30,
// &alldata.rt_price_30m_vec,
// &filtered_3rd_symbols_c,
// )
// .await?;
// let ema150_30m_data: Vec<(String, Vec<EmaData>)> = ema(
// 150,
// &alldata.rt_price_30m_vec,
// &filtered_3rd_symbols_c,
// )
// .await?;
// let mut task_vec = Vec::new();
// let mut filtered_4th_symbols: Vec<(String, i64)> = Vec::new();
// let mut filtered_4th_symbols_arc: Arc<Mutex<Vec<(String, i64)>>> =
// Arc::new(Mutex::new(filtered_4th_symbols)); // (symbol, closetime)
// for element in filtered_3rd_symbols_c {
// let mut ema30_30m_vec: Vec<EmaData> = Vec::new();
// let mut ema150_30m_vec: Vec<EmaData> = Vec::new();
// let ema30_30m_option = ema30_30m_data.iter().position(|x| *x.0 == element.0);
// let ema30_30m_option_c = ema30_30m_option.clone();
// let ema150_30m_option = ema150_30m_data.iter().position(|x| *x.0 == element.0);
// let ema150_30m_option_c = ema150_30m_option.clone();
// let element_c = element.clone();
// let filtered_4th_symbols_arc_c = Arc::clone(&filtered_4th_symbols_arc);
// if ema30_30m_option_c.is_some() && ema150_30m_option_c.is_some() {
// ema30_30m_vec = ema30_30m_data[ema30_30m_option.unwrap()].1.clone();
// ema150_30m_vec = ema150_30m_data[ema150_30m_option.unwrap()].1.clone();
// if ema30_30m_vec.len() >= 10 && ema150_30m_vec.len() >= 10 {
// let ema30_30m_vec_c = ema30_30m_vec.clone();
// let ema150_30m_vec_c = ema150_30m_vec.clone();
// task_vec.push(tokio::spawn(async move {
// let ema30_search_result = ema30_30m_vec_c.binary_search_by_key(
// &element_c.1,
// |&EmaData {
// ema_value,
// close_time,
// }| close_time,
// );
// let ema150_search_result = ema150_30m_vec_c.binary_search_by_key(
// &element_c.1,
// |&EmaData {
// ema_value,
// close_time,
// }| close_time,
// );
// if ema30_search_result.is_ok() && ema150_search_result.is_ok() {
// if ema30_30m_vec_c[ema30_search_result.unwrap()-3].ema_value > ema150_30m_vec_c[ema150_search_result.unwrap()-3].ema_value &&
// ema30_30m_vec_c[ema30_search_result.unwrap()-2].ema_value > ema150_30m_vec_c[ema150_search_result.unwrap()-2].ema_value &&
// ema30_30m_vec_c[ema30_search_result.unwrap()-1].ema_value > ema150_30m_vec_c[ema150_search_result.unwrap()-1].ema_value &&
// ema30_30m_vec_c[ema30_search_result.unwrap()].ema_value > ema150_30m_vec_c[ema150_search_result.unwrap()].ema_value &&
// ema30_30m_vec_c[ema30_search_result.unwrap()].ema_value > ema30_30m_vec_c[ema30_search_result.unwrap()-1].ema_value &&
// ema30_30m_vec_c[ema30_search_result.unwrap()-1].ema_value > ema30_30m_vec_c[ema30_search_result.unwrap()-2].ema_value &&
// ema30_30m_vec_c[ema30_search_result.unwrap()-2].ema_value > ema30_30m_vec_c[ema30_search_result.unwrap()-3].ema_value
// {
// let mut filtered_4th_symbols_lock =
// filtered_4th_symbols_arc_c.lock().await;
// filtered_4th_symbols_lock.push(element_c);
// }
// }
// }));
// }
// }
// }
// try_join_all(task_vec).await?;
// // 6th filtering: StochRSI (RSI length: 10, Stoch length: 10, smooth k: 3, smooth d: 3) smooth dn == 0, kn == 0, kn-1 < 5
// let filtered_4th_symbol_c = filtered_4th_symbols_arc.lock().await.clone();
// let mut rsi10_30m_data: Vec<(String, Vec<RsiData>)> = rsi(
// 10,
// &alldata.rt_price_30m_vec,
// &filtered_4th_symbol_c,
// )
// .await?;
// let stoch_rsi_data = stoch_rsi(&rsi10_30m_data, 10, 3, 3).await?;
// let mut stoch_rsi10_30m_vec: Vec<StochRsiData> = Vec::new();
// let mut filtered_5th_symbols: Vec<(String, i64)> = Vec::new(); // (symbol, closetime)
// for element in filtered_4th_symbol_c {
// let stoch_rsi10_30m_option = stoch_rsi_data.iter().position(|x| *x.0 == element.0);
// if stoch_rsi10_30m_option.is_some() {
// stoch_rsi10_30m_vec = stoch_rsi_data[stoch_rsi10_30m_option.unwrap()].1.clone();
// if stoch_rsi10_30m_vec.len() >= 3 {
// let stoch_rsi_search_result = stoch_rsi10_30m_vec.binary_search_by_key(
// &element.1,
// |&StochRsiData {
// k,
// d,
// close_time,
// }| close_time,
// );
// if stoch_rsi_search_result.is_ok() {
// if stoch_rsi10_30m_vec[stoch_rsi_search_result.unwrap()].k <= 5.0 &&
// stoch_rsi10_30m_vec[stoch_rsi_search_result.unwrap()].d <= 5.0 &&
// stoch_rsi10_30m_vec[stoch_rsi_search_result.unwrap()-1].k <= 5.0 {
// filtered_5th_symbols.push(element);
// }
// }
// }
// }
// }
// // 7th filtering: heatmap volume(MA length 10, std length 10, 30m close price), the current candle should be over than high at least.
// let mut filtered_6th_symbols: Vec<(String, i64)> = Vec::new(); // (symbol, closetime)
// for element in filtered_5th_symbols {
// let rt_price_30m_vec_c = alldata.rt_price_30m_vec.clone();
// let opclo_30m_option = rt_price_30m_vec_c.iter().position(|x| *x.0 == element.0);
// if opclo_30m_option.is_some() {
// let opclo_30m_vec = rt_price_30m_vec_c[opclo_30m_option.unwrap()].1.clone();
// if opclo_30m_vec.len() >= 3 {
// let heatmap_volume_option =
// heatmap_volume(&element.0, &rt_price_30m_vec_c, 10, 10, 4.0, 2.5, 1.0, -0.5)
// .await;
// if heatmap_volume_option.is_some() {
// let heatmap_volume_vec = heatmap_volume_option.unwrap();
// let heatmap_search_result = heatmap_volume_vec.binary_search_by_key(
// &element.1,
// |HeatmapVolumeData {
// heatmap_value,
// heatmap_level,
// close_time,
// }| *close_time,
// );
// if heatmap_search_result.is_ok() {
// if
// // heatmap_volume_vec[heatmap_search_result.unwrap()].heatmap_level
// // == HeatMapLevel::Medium
// // ||
// heatmap_volume_vec[heatmap_search_result.unwrap()].heatmap_level
// == HeatMapLevel::High
// || heatmap_volume_vec[heatmap_search_result.unwrap()].heatmap_level
// == HeatMapLevel::ExtraHigh
// {
// filtered_6th_symbols.push(element);
// }
// }
// }
// }
// }
// }
// // final job: adding price information to filtered results
// let mut filtered_symbols: Vec<(String, i64, f64)> = Vec::new(); // (symbol, closetime, current price)
// let mut filtered_symbols_arc = Arc::new(Mutex::new(filtered_symbols));
// let mut task_vec = Vec::new();
// for element in filtered_6th_symbols {
// let mut filtered_symbols_arc_c = Arc::clone(&filtered_symbols_arc);
// let rt_price_30m_vec_c = alldata.rt_price_30m_vec.clone();
// let elememt_c = element.clone();
// task_vec.push(tokio::spawn(async move {
// let opclo_30m_option = rt_price_30m_vec_c.iter().position(|x| *x.0 == element.0);
// if opclo_30m_option.is_some() {
// if rt_price_30m_vec_c[opclo_30m_option.unwrap()]
// .1
// .last()
// .is_some()
// {
// let mut filtered_symbols_lock: tokio::sync::MutexGuard<
// '_,
// Vec<(String, i64, f64)>,
// > = filtered_symbols_arc_c.lock().await;
// filtered_symbols_lock.push((
// elememt_c.0,
// elememt_c.1,
// rt_price_30m_vec_c[opclo_30m_option.unwrap()]
// .1
// .last()
// .unwrap()
// .close_price,
// ));
// }
// }
// }));
// }
// try_join_all(task_vec).await?;
// let a = filtered_symbols_arc.lock().await.clone();
// insert_pre_suggested_coins(2, false, &a, alldata).await;
// Ok(())
// }

View File

@ -0,0 +1,286 @@
use super::{AllData, RealtimePriceData, Mutex, Arc, try_join_all, exists_record, StochRsiData, EmaData, SupertrendData, RsiData, stoch_rsi, ema, rsi, supertrend};
pub async fn list_up_for_buy(
alldata: &AllData,
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
// print rt_price for debugging
// let a = alldata.rt_price_30m_vec.iter().position(|a| a.0 == "BTCUSDT");
// println!("BTCUSDT: {:?}", alldata.rt_price_30m_vec[a.unwrap()].1.last().unwrap());
// 1st filtering: supertrend(ATR period 100, multiplier: 6.0, 30m close price), the area should be in UP area.
let mut filtered_2nd_symbols: Vec<(String, i64)> = Vec::new();
let mut filtered_2nd_symbols_arc: Arc<Mutex<Vec<(String, i64)>>> =
Arc::new(Mutex::new(filtered_2nd_symbols)); // (symbol, closetime)
let mut task_vec = Vec::new();
let valid_symbol_vec_c = alldata.valid_symbol_vec.clone();
for symbol in valid_symbol_vec_c {
let mut opclo_30m_vec: Vec<RealtimePriceData> = Vec::new();
let mut supertrend_vec: Vec<SupertrendData> = Vec::new();
let rt_price_30m_vec_c = alldata.rt_price_30m_vec.clone();
let filtered_2nd_symbols_arc_c = Arc::clone(&filtered_2nd_symbols_arc);
task_vec.push(tokio::spawn(async move {
let opclo_30m_option = rt_price_30m_vec_c.iter().position(|x| *x.0 == symbol);
let supertrend_option_30m =
supertrend(&symbol, &rt_price_30m_vec_c, 100, 6.0, true).await;
if opclo_30m_option.is_some() && supertrend_option_30m.is_some() {
opclo_30m_vec = rt_price_30m_vec_c[opclo_30m_option.unwrap()].1.clone();
supertrend_vec = supertrend_option_30m.unwrap();
if opclo_30m_vec.len() >= 3 && supertrend_vec.len() >= 3 {
let supertrend_search_result = supertrend_vec.binary_search_by_key(
&opclo_30m_vec.last().unwrap().close_time,
|SupertrendData {
band_value,
signal,
area,
close_time,
}| *close_time,
);
if supertrend_search_result.is_ok() {
if supertrend_vec[supertrend_search_result.unwrap()]
.area
.contains("UP")
{
let mut filtered_2nd_symbols_lock =
filtered_2nd_symbols_arc_c.lock().await;
filtered_2nd_symbols_lock
.push((symbol.clone(), opclo_30m_vec.last().unwrap().close_time));
}
}
}
}
}));
}
try_join_all(task_vec).await?;
// 2nd filtering: lookup tables if the tradepair is already there
let inspect_table_name_1 = String::from("buy_ordered_coin_list");
let inspect_table_name_2 = String::from("sell_ordered_coin_list");
let inspect_table_name_3 = String::from("pre_suggested_coin_list");
let inspect_table_name_4 = String::from("suggested_coin_list");
let mut filtered_3rd_symbols: Vec<(String, i64)> = Vec::new();
let mut filtered_3rd_symbols_arc: Arc<Mutex<Vec<(String, i64)>>> =
Arc::new(Mutex::new(filtered_3rd_symbols)); // (symbol, closetime)
let mut task_vec = Vec::new();
let filtered_2nd_iter = filtered_2nd_symbols_arc.lock().await.clone().into_iter();
for element in filtered_2nd_iter {
let mut exists_condition_build = String::from("symbol=\'");
exists_condition_build.push_str(element.0.as_str());
exists_condition_build.push_str("\' AND registerer=");
exists_condition_build.push_str(3.to_string().as_str());
// exists_condition_build.push_str("\' AND close_time=");
// exists_condition_build.push_str(element.1.to_string().as_str());
let exists_condition = Some(exists_condition_build);
let exists_condition_c = exists_condition.clone();
let inspect_table_name_1_c = inspect_table_name_1.clone();
let inspect_table_name_2_c = inspect_table_name_2.clone();
let inspect_table_name_3_c = inspect_table_name_3.clone();
let inspect_table_name_4_c = inspect_table_name_4.clone();
let element_c = element.clone();
let filtered_3rd_symbols_arc_c = Arc::clone(&filtered_3rd_symbols_arc);
task_vec.push(tokio::spawn(async move {
let inspect_result_1 =
exists_record(&inspect_table_name_1_c, &exists_condition_c).await;
let inspect_result_2 =
exists_record(&inspect_table_name_2_c, &exists_condition_c).await;
let inspect_result_3 =
exists_record(&inspect_table_name_3_c, &exists_condition_c).await;
let inspect_result_4 =
exists_record(&inspect_table_name_4_c, &exists_condition_c).await;
if inspect_result_1 == false
&& inspect_result_2 == false
&& inspect_result_3 == false
&& inspect_result_4 == false
{
let mut filtered_3rd_symbols_lock = filtered_3rd_symbols_arc_c.lock().await;
filtered_3rd_symbols_lock.push(element_c);
}
}));
}
try_join_all(task_vec).await?;
// 3rd filtering: EMA30 > EMA 150
let filtered_3rd_symbols_c = filtered_3rd_symbols_arc.lock().await.clone();
let ema30_30m_data: Vec<(String, Vec<EmaData>)> = ema(
30,
&alldata.rt_price_30m_vec,
&filtered_3rd_symbols_c,
)
.await?;
let ema150_30m_data: Vec<(String, Vec<EmaData>)> = ema(
150,
&alldata.rt_price_30m_vec,
&filtered_3rd_symbols_c,
)
.await?;
let mut task_vec = Vec::new();
let mut filtered_4th_symbols: Vec<(String, i64)> = Vec::new();
let mut filtered_4th_symbols_arc: Arc<Mutex<Vec<(String, i64)>>> =
Arc::new(Mutex::new(filtered_4th_symbols)); // (symbol, closetime)
for element in filtered_3rd_symbols_c {
let mut ema30_30m_vec: Vec<EmaData> = Vec::new();
let mut ema150_30m_vec: Vec<EmaData> = Vec::new();
let ema30_30m_option = ema30_30m_data.iter().position(|x| *x.0 == element.0);
let ema30_30m_option_c = ema30_30m_option.clone();
let ema150_30m_option = ema150_30m_data.iter().position(|x| *x.0 == element.0);
let ema150_30m_option_c = ema150_30m_option.clone();
let element_c = element.clone();
let filtered_4th_symbols_arc_c = Arc::clone(&filtered_4th_symbols_arc);
if ema30_30m_option_c.is_some() && ema150_30m_option_c.is_some() {
ema30_30m_vec = ema30_30m_data[ema30_30m_option.unwrap()].1.clone();
ema150_30m_vec = ema150_30m_data[ema150_30m_option.unwrap()].1.clone();
if ema30_30m_vec.len() >= 10 && ema150_30m_vec.len() >= 10 {
let ema30_30m_vec_c = ema30_30m_vec.clone();
let ema150_30m_vec_c = ema150_30m_vec.clone();
task_vec.push(tokio::spawn(async move {
let ema30_search_result = ema30_30m_vec_c.binary_search_by_key(
&element_c.1,
|&EmaData {
ema_value,
close_time,
}| close_time,
);
let ema150_search_result = ema150_30m_vec_c.binary_search_by_key(
&element_c.1,
|&EmaData {
ema_value,
close_time,
}| close_time,
);
if ema30_search_result.is_ok() && ema150_search_result.is_ok() {
if ema30_30m_vec_c[ema30_search_result.unwrap()-3].ema_value > ema150_30m_vec_c[ema150_search_result.unwrap()-3].ema_value &&
ema30_30m_vec_c[ema30_search_result.unwrap()-2].ema_value > ema150_30m_vec_c[ema150_search_result.unwrap()-2].ema_value &&
ema30_30m_vec_c[ema30_search_result.unwrap()-1].ema_value > ema150_30m_vec_c[ema150_search_result.unwrap()-1].ema_value &&
ema30_30m_vec_c[ema30_search_result.unwrap()].ema_value > ema150_30m_vec_c[ema150_search_result.unwrap()].ema_value &&
ema30_30m_vec_c[ema30_search_result.unwrap()].ema_value > ema30_30m_vec_c[ema30_search_result.unwrap()-1].ema_value &&
ema30_30m_vec_c[ema30_search_result.unwrap()-1].ema_value > ema30_30m_vec_c[ema30_search_result.unwrap()-2].ema_value &&
ema30_30m_vec_c[ema30_search_result.unwrap()-2].ema_value > ema30_30m_vec_c[ema30_search_result.unwrap()-3].ema_value
{
let mut filtered_4th_symbols_lock =
filtered_4th_symbols_arc_c.lock().await;
filtered_4th_symbols_lock.push(element_c);
}
}
}));
}
}
}
try_join_all(task_vec).await?;
// 4th filtering: StochRSI (RSI length: 10, Stoch length: 10, smooth k: 3, smooth d: 3) 20 > k > kn-1 > kn-2 > kn-3,
let filtered_4th_symbol_c = filtered_4th_symbols_arc.lock().await.clone();
let mut rsi10_30m_data: Vec<(String, Vec<RsiData>)> = rsi(
10,
&alldata.rt_price_30m_vec,
&filtered_4th_symbol_c,
)
.await?;
let stoch_rsi_data = stoch_rsi(&rsi10_30m_data, 10, 3, 3).await?;
let mut stoch_rsi10_30m_vec: Vec<StochRsiData> = Vec::new();
let mut filtered_5th_symbols: Vec<(String, i64)> = Vec::new(); // (symbol, closetime)
for element in filtered_4th_symbol_c {
let stoch_rsi10_30m_option = stoch_rsi_data.iter().position(|x| *x.0 == element.0);
if stoch_rsi10_30m_option.is_some() {
stoch_rsi10_30m_vec = stoch_rsi_data[stoch_rsi10_30m_option.unwrap()].1.clone();
if stoch_rsi10_30m_vec.len() >= 3 {
let stoch_rsi_search_result = stoch_rsi10_30m_vec.binary_search_by_key(
&element.1,
|&StochRsiData {
k,
d,
close_time,
}| close_time,
);
if stoch_rsi_search_result.is_ok() {
if 10.0 > stoch_rsi10_30m_vec[stoch_rsi_search_result.unwrap()].k &&
stoch_rsi10_30m_vec[stoch_rsi_search_result.unwrap()].k > stoch_rsi10_30m_vec[stoch_rsi_search_result.unwrap()-1].k &&
stoch_rsi10_30m_vec[stoch_rsi_search_result.unwrap()-1].k <= stoch_rsi10_30m_vec[stoch_rsi_search_result.unwrap()-2].k &&
stoch_rsi10_30m_vec[stoch_rsi_search_result.unwrap()-2].k <= stoch_rsi10_30m_vec[stoch_rsi_search_result.unwrap()-3].k {
filtered_5th_symbols.push(element);
}
}
}
}
}
// final job: adding price information to filtered results
let mut filtered_symbols: Vec<(String, i64, f64)> = Vec::new(); // (symbol, closetime, current price)
let mut filtered_symbols_arc = Arc::new(Mutex::new(filtered_symbols));
let mut task_vec = Vec::new();
for element in filtered_5th_symbols {
let mut filtered_symbols_arc_c = Arc::clone(&filtered_symbols_arc);
let rt_price_30m_vec_c = alldata.rt_price_30m_vec.clone();
let elememt_c = element.clone();
task_vec.push(tokio::spawn(async move {
let opclo_30m_option = rt_price_30m_vec_c.iter().position(|x| *x.0 == element.0);
if opclo_30m_option.is_some() {
if rt_price_30m_vec_c[opclo_30m_option.unwrap()]
.1
.last()
.is_some()
{
let mut filtered_symbols_lock: tokio::sync::MutexGuard<
'_,
Vec<(String, i64, f64)>,
> = filtered_symbols_arc_c.lock().await;
filtered_symbols_lock.push((
elememt_c.0,
elememt_c.1,
rt_price_30m_vec_c[opclo_30m_option.unwrap()]
.1
.last()
.unwrap()
.close_price,
));
}
}
}));
}
try_join_all(task_vec).await?;
// TODO: abnormal price filtering (too high current price)
// 6th filtering condition: MACD
// let mut opclo_30m_vec: Vec<RealtimePriceData> = Vec::new();
// let mut ema3_1d_vec: &Vec<EmaData> = &Vec::new();
// let mut ema10_1d_vec: &Vec<EmaData> = &Vec::new();
// let mut filtered_7th_symbols: Vec<(String, i64)> = Vec::new(); // (symbol, closetime)
// for element in filtered_6th_symbols {
// let ema3_1d_option = alldata.ema3_1d_data.iter().position(|x| *x.0 == *element.0);
// let ema10_1d_option = alldata.ema10_1d_data.iter().position(|x| *x.0 == *element.0);
// if ema3_1d_option.is_some() && ema10_1d_option.is_some() {
// ema3_1d_vec = &alldata.ema3_1d_data[ema3_1d_option.unwrap()].1;
// ema10_1d_vec = &alldata.ema10_1d_data[ema10_1d_option.unwrap()].1;
// if ema3_1d_vec.len() > 20 && ema10_1d_vec.len() > 20 {
// let macd_vec = ema_macd(&ema3_1d_vec, &ema10_1d_vec, 10).await?;
// // let macd_search_result = macd_vec.binary_search_by_key(&element.1, |&EmaMacd{macd_value, close_time}|close_time);
// // if macd_search_result.is_ok() {
// if macd_vec.last().unwrap().macd_value - macd_vec[macd_vec.len() -2].macd_value >= 0.0 {
// filtered_7th_symbols.push(element);
// }
// // }
// }
// }
// }
let a = filtered_symbols_arc.lock().await.clone();
super::strategy_manager::insert_pre_suggested_coins(3, false, &a, alldata).await;
Ok(())
}

View File

@ -0,0 +1,268 @@
// pub async fn strategist_004(
// alldata: &AllData,
// ) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
// // print rt_price for debugging
// // let a = alldata.rt_price_30m_vec.iter().position(|a| a.0 == "BTCUSDT");
// // println!("BTCUSDT: {:?}", alldata.rt_price_30m_vec[a.unwrap()].1.last().unwrap());
// // 1st filtering: supertrend(ATR period 10, multiplier: 2.0, 30m close price), the area should be in UP area.
// let mut filtered_2nd_symbols: Vec<(String, i64)> = Vec::new();
// let mut filtered_2nd_symbols_arc: Arc<Mutex<Vec<(String, i64)>>> =
// Arc::new(Mutex::new(filtered_2nd_symbols)); // (symbol, closetime)
// let mut task_vec = Vec::new();
// let valid_symbol_vec_c = alldata.valid_symbol_vec.clone();
// for symbol in valid_symbol_vec_c {
// let mut opclo_30m_vec: Vec<RealtimePriceData> = Vec::new();
// let mut supertrend_vec: Vec<SupertrendData> = Vec::new();
// let rt_price_30m_vec_c = alldata.rt_price_30m_vec.clone();
// let filtered_2nd_symbols_arc_c = Arc::clone(&filtered_2nd_symbols_arc);
// task_vec.push(tokio::spawn(async move {
// let opclo_30m_option = rt_price_30m_vec_c.iter().position(|x| *x.0 == symbol);
// let supertrend_option_30m =
// supertrend(&symbol, &rt_price_30m_vec_c, 10, 2.0, true).await;
// if opclo_30m_option.is_some() && supertrend_option_30m.is_some() {
// opclo_30m_vec = rt_price_30m_vec_c[opclo_30m_option.unwrap()].1.clone();
// supertrend_vec = supertrend_option_30m.unwrap();
// if opclo_30m_vec.len() >= 3 && supertrend_vec.len() >= 3 {
// let supertrend_search_result = supertrend_vec.binary_search_by_key(
// &opclo_30m_vec.last().unwrap().close_time,
// |SupertrendData {
// band_value,
// signal,
// area,
// close_time,
// }| *close_time,
// );
// if supertrend_search_result.is_ok() {
// if supertrend_vec[supertrend_search_result.unwrap()]
// .area
// .contains("UP")
// {
// let mut filtered_2nd_symbols_lock =
// filtered_2nd_symbols_arc_c.lock().await;
// filtered_2nd_symbols_lock
// .push((symbol.clone(), opclo_30m_vec.last().unwrap().close_time));
// }
// }
// }
// }
// }));
// }
// try_join_all(task_vec).await?;
// // 2nd filtering: lookup tables if the tradepair is already there
// let inspect_table_name_1 = String::from("buy_ordered_coin_list");
// let inspect_table_name_2 = String::from("sell_ordered_coin_list");
// let inspect_table_name_3 = String::from("pre_suggested_coin_list");
// let inspect_table_name_4 = String::from("suggested_coin_list");
// let mut filtered_3rd_symbols: Vec<(String, i64)> = Vec::new();
// let mut filtered_3rd_symbols_arc: Arc<Mutex<Vec<(String, i64)>>> =
// Arc::new(Mutex::new(filtered_3rd_symbols)); // (symbol, closetime)
// let mut task_vec = Vec::new();
// let filtered_2nd_iter = filtered_2nd_symbols_arc.lock().await.clone().into_iter();
// for element in filtered_2nd_iter {
// let mut exists_condition_build = String::from("symbol=\'");
// exists_condition_build.push_str(element.0.as_str());
// exists_condition_build.push_str("\' AND registerer=");
// exists_condition_build.push_str(4.to_string().as_str());
// // exists_condition_build.push_str("\' AND close_time=");
// // exists_condition_build.push_str(element.1.to_string().as_str());
// let exists_condition = Some(exists_condition_build);
// let exists_condition_c = exists_condition.clone();
// let inspect_table_name_1_c = inspect_table_name_1.clone();
// let inspect_table_name_2_c = inspect_table_name_2.clone();
// let inspect_table_name_3_c = inspect_table_name_3.clone();
// let inspect_table_name_4_c = inspect_table_name_4.clone();
// let element_c = element.clone();
// let filtered_3rd_symbols_arc_c = Arc::clone(&filtered_3rd_symbols_arc);
// task_vec.push(tokio::spawn(async move {
// let inspect_result_1 =
// exists_record(&inspect_table_name_1_c, &exists_condition_c).await;
// let inspect_result_2 =
// exists_record(&inspect_table_name_2_c, &exists_condition_c).await;
// let inspect_result_3 =
// exists_record(&inspect_table_name_3_c, &exists_condition_c).await;
// let inspect_result_4 =
// exists_record(&inspect_table_name_4_c, &exists_condition_c).await;
// if inspect_result_1 == false
// && inspect_result_2 == false
// && inspect_result_3 == false
// && inspect_result_4 == false
// {
// let mut filtered_3rd_symbols_lock = filtered_3rd_symbols_arc_c.lock().await;
// filtered_3rd_symbols_lock.push(element_c);
// }
// }));
// }
// try_join_all(task_vec).await?;
// // 3rd filtering: EMA30 >= EMA 150
// let filtered_3rd_symbols_c = filtered_3rd_symbols_arc.lock().await.clone();
// let ema30_30m_data: Vec<(String, Vec<EmaData>)> = ema(
// 30,
// &alldata.rt_price_30m_vec,
// &filtered_3rd_symbols_c,
// )
// .await?;
// let ema150_30m_data: Vec<(String, Vec<EmaData>)> = ema(
// 150,
// &alldata.rt_price_30m_vec,
// &filtered_3rd_symbols_c,
// )
// .await?;
// let mut task_vec = Vec::new();
// let mut filtered_4th_symbols: Vec<(String, i64)> = Vec::new();
// let mut filtered_4th_symbols_arc: Arc<Mutex<Vec<(String, i64)>>> =
// Arc::new(Mutex::new(filtered_4th_symbols)); // (symbol, closetime)
// for element in filtered_3rd_symbols_c {
// let mut ema30_30m_vec: Vec<EmaData> = Vec::new();
// let mut ema150_30m_vec: Vec<EmaData> = Vec::new();
// let ema30_30m_option = ema30_30m_data.iter().position(|x| *x.0 == element.0);
// let ema30_30m_option_c = ema30_30m_option.clone();
// let ema150_30m_option = ema150_30m_data.iter().position(|x| *x.0 == element.0);
// let ema150_30m_option_c = ema150_30m_option.clone();
// let element_c = element.clone();
// let filtered_4th_symbols_arc_c = Arc::clone(&filtered_4th_symbols_arc);
// if ema30_30m_option_c.is_some() && ema150_30m_option_c.is_some() {
// ema30_30m_vec = ema30_30m_data[ema30_30m_option.unwrap()].1.clone();
// ema150_30m_vec = ema150_30m_data[ema150_30m_option.unwrap()].1.clone();
// if ema30_30m_vec.len() >= 10 && ema150_30m_vec.len() >= 10 {
// let ema30_30m_vec_c = ema30_30m_vec.clone();
// let ema150_30m_vec_c = ema150_30m_vec.clone();
// task_vec.push(tokio::spawn(async move {
// let ema30_search_result = ema30_30m_vec_c.binary_search_by_key(
// &element_c.1,
// |&EmaData {
// ema_value,
// close_time,
// }| close_time,
// );
// let ema150_search_result = ema150_30m_vec_c.binary_search_by_key(
// &element_c.1,
// |&EmaData {
// ema_value,
// close_time,
// }| close_time,
// );
// if ema30_search_result.is_ok() && ema150_search_result.is_ok() {
// if ema30_30m_vec_c[ema30_search_result.unwrap()-9].ema_value < ema150_30m_vec_c[ema150_search_result.unwrap()-9].ema_value &&
// ema30_30m_vec_c[ema30_search_result.unwrap()-8].ema_value < ema150_30m_vec_c[ema150_search_result.unwrap()-8].ema_value &&
// ema30_30m_vec_c[ema30_search_result.unwrap()-7].ema_value < ema150_30m_vec_c[ema150_search_result.unwrap()-7].ema_value &&
// ema30_30m_vec_c[ema30_search_result.unwrap()-6].ema_value < ema150_30m_vec_c[ema150_search_result.unwrap()-6].ema_value &&
// ema30_30m_vec_c[ema30_search_result.unwrap()-5].ema_value < ema150_30m_vec_c[ema150_search_result.unwrap()-5].ema_value &&
// ema30_30m_vec_c[ema30_search_result.unwrap()-4].ema_value < ema150_30m_vec_c[ema150_search_result.unwrap()-4].ema_value &&
// ema30_30m_vec_c[ema30_search_result.unwrap()-3].ema_value < ema150_30m_vec_c[ema150_search_result.unwrap()-3].ema_value &&
// ema30_30m_vec_c[ema30_search_result.unwrap()-2].ema_value < ema150_30m_vec_c[ema150_search_result.unwrap()-2].ema_value &&
// ema30_30m_vec_c[ema30_search_result.unwrap()-1].ema_value < ema150_30m_vec_c[ema150_search_result.unwrap()-1].ema_value &&
// ema30_30m_vec_c[ema30_search_result.unwrap()].ema_value >= ema150_30m_vec_c[ema150_search_result.unwrap()].ema_value &&
// ema30_30m_vec_c[ema30_search_result.unwrap()].ema_value > ema30_30m_vec_c[ema30_search_result.unwrap()-1].ema_value &&
// ema30_30m_vec_c[ema30_search_result.unwrap()-1].ema_value > ema30_30m_vec_c[ema30_search_result.unwrap()-2].ema_value &&
// ema30_30m_vec_c[ema30_search_result.unwrap()-2].ema_value > ema30_30m_vec_c[ema30_search_result.unwrap()-3].ema_value
// {
// let mut filtered_4th_symbols_lock =
// filtered_4th_symbols_arc_c.lock().await;
// filtered_4th_symbols_lock.push(element_c);
// }
// }
// }));
// }
// }
// }
// try_join_all(task_vec).await?;
// // 4th filtering: heatmap volume(MA length 10, std length 10, 30m close price), the current candle should be Normal or Low.
// let filtered_4th_symbols_c = filtered_4th_symbols_arc.lock().await.clone();
// let mut filtered_5th_symbols: Vec<(String, i64)> = Vec::new(); // (symbol, closetime)
// for element in filtered_4th_symbols_c {
// let rt_price_30m_vec_c = alldata.rt_price_30m_vec.clone();
// let opclo_30m_option = rt_price_30m_vec_c.iter().position(|x| *x.0 == element.0);
// if opclo_30m_option.is_some() {
// let opclo_30m_vec = rt_price_30m_vec_c[opclo_30m_option.unwrap()].1.clone();
// if opclo_30m_vec.len() >= 3 {
// let heatmap_volume_option =
// heatmap_volume(&element.0, &rt_price_30m_vec_c, 10, 10, 4.0, 2.5, 1.0, -0.5)
// .await;
// if heatmap_volume_option.is_some() {
// let heatmap_volume_vec = heatmap_volume_option.unwrap();
// let heatmap_search_result = heatmap_volume_vec.binary_search_by_key(
// &element.1,
// |HeatmapVolumeData {
// heatmap_value,
// heatmap_level,
// close_time,
// }| *close_time,
// );
// if heatmap_search_result.is_ok() {
// if (heatmap_volume_vec[heatmap_search_result.unwrap()].heatmap_level
// == HeatMapLevel::Low
// ||
// heatmap_volume_vec[heatmap_search_result.unwrap()].heatmap_level
// == HeatMapLevel::Normal) &&
// (heatmap_volume_vec[heatmap_search_result.unwrap()-1].heatmap_level
// == HeatMapLevel::Low
// ||
// heatmap_volume_vec[heatmap_search_result.unwrap()-1].heatmap_level
// == HeatMapLevel::Normal
// )
// {
// filtered_5th_symbols.push(element);
// }
// }
// }
// }
// }
// }
// // final job: adding price information to filtered results
// let mut filtered_symbols: Vec<(String, i64, f64)> = Vec::new(); // (symbol, closetime, current price)
// let mut filtered_symbols_arc = Arc::new(Mutex::new(filtered_symbols));
// let mut task_vec = Vec::new();
// for element in filtered_5th_symbols {
// let mut filtered_symbols_arc_c = Arc::clone(&filtered_symbols_arc);
// let rt_price_30m_vec_c = alldata.rt_price_30m_vec.clone();
// let elememt_c = element.clone();
// task_vec.push(tokio::spawn(async move {
// let opclo_30m_option = rt_price_30m_vec_c.iter().position(|x| *x.0 == element.0);
// if opclo_30m_option.is_some() {
// if rt_price_30m_vec_c[opclo_30m_option.unwrap()]
// .1
// .last()
// .is_some()
// {
// let mut filtered_symbols_lock: tokio::sync::MutexGuard<
// '_,
// Vec<(String, i64, f64)>,
// > = filtered_symbols_arc_c.lock().await;
// filtered_symbols_lock.push((
// elememt_c.0,
// elememt_c.1,
// rt_price_30m_vec_c[opclo_30m_option.unwrap()]
// .1
// .last()
// .unwrap()
// .close_price,
// ));
// }
// }
// }));
// }
// try_join_all(task_vec).await?;
// let a = filtered_symbols_arc.lock().await.clone();
// insert_pre_suggested_coins(4, false, &a, alldata).await;
// Ok(())
// }

View File

@ -0,0 +1,192 @@
// pub async fn strategist_005(
// alldata: &AllData,
// ) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
// // print rt_price for debugging
// // let a = alldata.rt_price_30m_vec.iter().position(|a| a.0 == "BTCUSDT");
// // println!("BTCUSDT: {:?}", alldata.rt_price_30m_vec[a.unwrap()].1.last().unwrap());
// // 1st filtering: supertrend(ATR period 30, multiplier: 6.0, 30m close price), the area should be in UP area.
// let mut filtered_2nd_symbols: Vec<(String, i64)> = Vec::new();
// let mut filtered_2nd_symbols_arc: Arc<Mutex<Vec<(String, i64)>>> =
// Arc::new(Mutex::new(filtered_2nd_symbols)); // (symbol, closetime)
// let mut task_vec = Vec::new();
// let valid_symbol_vec_c = alldata.valid_symbol_vec.clone();
// for symbol in valid_symbol_vec_c {
// let mut opclo_30m_vec: Vec<RealtimePriceData> = Vec::new();
// let mut supertrend_vec: Vec<SupertrendData> = Vec::new();
// let rt_price_30m_vec_c = alldata.rt_price_30m_vec.clone();
// let filtered_2nd_symbols_arc_c = Arc::clone(&filtered_2nd_symbols_arc);
// task_vec.push(tokio::spawn(async move {
// let opclo_30m_option = rt_price_30m_vec_c.iter().position(|x| *x.0 == symbol);
// let supertrend_option_30m =
// supertrend(&symbol, &rt_price_30m_vec_c, 30, 6.0, true).await;
// if opclo_30m_option.is_some() && supertrend_option_30m.is_some() {
// opclo_30m_vec = rt_price_30m_vec_c[opclo_30m_option.unwrap()].1.clone();
// supertrend_vec = supertrend_option_30m.unwrap();
// if opclo_30m_vec.len() >= 3 && supertrend_vec.len() >= 3 {
// let supertrend_search_result = supertrend_vec.binary_search_by_key(
// &opclo_30m_vec.last().unwrap().close_time,
// |SupertrendData {
// band_value,
// signal,
// area,
// close_time,
// }| *close_time,
// );
// if supertrend_search_result.is_ok() {
// if supertrend_vec[supertrend_search_result.unwrap()]
// .signal.as_ref().is_some_and(|signal| signal.contains("BUY"))
// {
// let mut filtered_2nd_symbols_lock =
// filtered_2nd_symbols_arc_c.lock().await;
// filtered_2nd_symbols_lock
// .push((symbol.clone(), opclo_30m_vec.last().unwrap().close_time));
// }
// }
// }
// }
// }));
// }
// try_join_all(task_vec).await?;
// // 2nd filtering: lookup tables if the tradepair is already there
// let inspect_table_name_1 = String::from("buy_ordered_coin_list");
// let inspect_table_name_2 = String::from("sell_ordered_coin_list");
// let inspect_table_name_3 = String::from("pre_suggested_coin_list");
// let inspect_table_name_4 = String::from("suggested_coin_list");
// let mut filtered_3rd_symbols: Vec<(String, i64)> = Vec::new();
// let mut filtered_3rd_symbols_arc: Arc<Mutex<Vec<(String, i64)>>> =
// Arc::new(Mutex::new(filtered_3rd_symbols)); // (symbol, closetime)
// let mut task_vec = Vec::new();
// let filtered_2nd_iter = filtered_2nd_symbols_arc.lock().await.clone().into_iter();
// for element in filtered_2nd_iter {
// let mut exists_condition_build = String::from("symbol=\'");
// exists_condition_build.push_str(element.0.as_str());
// exists_condition_build.push_str("\' AND registerer=");
// exists_condition_build.push_str(5.to_string().as_str());
// // exists_condition_build.push_str("\' AND close_time=");
// // exists_condition_build.push_str(element.1.to_string().as_str());
// let exists_condition = Some(exists_condition_build);
// let exists_condition_c = exists_condition.clone();
// let inspect_table_name_1_c = inspect_table_name_1.clone();
// let inspect_table_name_2_c = inspect_table_name_2.clone();
// let inspect_table_name_3_c = inspect_table_name_3.clone();
// let inspect_table_name_4_c = inspect_table_name_4.clone();
// let element_c = element.clone();
// let filtered_3rd_symbols_arc_c = Arc::clone(&filtered_3rd_symbols_arc);
// task_vec.push(tokio::spawn(async move {
// let inspect_result_1 =
// exists_record(&inspect_table_name_1_c, &exists_condition_c).await;
// let inspect_result_2 =
// exists_record(&inspect_table_name_2_c, &exists_condition_c).await;
// let inspect_result_3 =
// exists_record(&inspect_table_name_3_c, &exists_condition_c).await;
// let inspect_result_4 =
// exists_record(&inspect_table_name_4_c, &exists_condition_c).await;
// if inspect_result_1 == false
// && inspect_result_2 == false
// && inspect_result_3 == false
// && inspect_result_4 == false
// {
// let mut filtered_3rd_symbols_lock = filtered_3rd_symbols_arc_c.lock().await;
// filtered_3rd_symbols_lock.push(element_c);
// }
// }));
// }
// try_join_all(task_vec).await?;
// // 3rd filtering: heatmap volume(MA length 10, std length 10, 30m close price), the current candle should be Normal or Low.
// let filtered_3rd_symbols_c = filtered_3rd_symbols_arc.lock().await.clone();
// let mut filtered_4th_symbols: Vec<(String, i64)> = Vec::new(); // (symbol, closetime)
// for element in filtered_3rd_symbols_c {
// let rt_price_30m_vec_c = alldata.rt_price_30m_vec.clone();
// let opclo_30m_option = rt_price_30m_vec_c.iter().position(|x| *x.0 == element.0);
// if opclo_30m_option.is_some() {
// let opclo_30m_vec = rt_price_30m_vec_c[opclo_30m_option.unwrap()].1.clone();
// if opclo_30m_vec.len() >= 3 {
// let heatmap_volume_option =
// heatmap_volume(&element.0, &rt_price_30m_vec_c, 10, 10, 4.0, 2.5, 1.0, -0.5)
// .await;
// if heatmap_volume_option.is_some() {
// let heatmap_volume_vec = heatmap_volume_option.unwrap();
// let heatmap_search_result = heatmap_volume_vec.binary_search_by_key(
// &element.1,
// |HeatmapVolumeData {
// heatmap_value,
// heatmap_level,
// close_time,
// }| *close_time,
// );
// if heatmap_search_result.is_ok() {
// if (heatmap_volume_vec[heatmap_search_result.unwrap()].heatmap_level
// == HeatMapLevel::Low
// ||
// heatmap_volume_vec[heatmap_search_result.unwrap()].heatmap_level
// == HeatMapLevel::Normal) &&
// (heatmap_volume_vec[heatmap_search_result.unwrap()-1].heatmap_level
// == HeatMapLevel::Low
// ||
// heatmap_volume_vec[heatmap_search_result.unwrap()-1].heatmap_level
// == HeatMapLevel::Normal) &&
// (heatmap_volume_vec[heatmap_search_result.unwrap()-2].heatmap_level
// == HeatMapLevel::Low
// ||
// heatmap_volume_vec[heatmap_search_result.unwrap()-2].heatmap_level
// == HeatMapLevel::Normal)
// {
// filtered_4th_symbols.push(element);
// }
// }
// }
// }
// }
// }
// // final job: adding price information to filtered results
// let mut filtered_symbols: Vec<(String, i64, f64)> = Vec::new(); // (symbol, closetime, current price)
// let mut filtered_symbols_arc = Arc::new(Mutex::new(filtered_symbols));
// let mut task_vec = Vec::new();
// for element in filtered_4th_symbols {
// let mut filtered_symbols_arc_c = Arc::clone(&filtered_symbols_arc);
// let rt_price_30m_vec_c = alldata.rt_price_30m_vec.clone();
// let elememt_c = element.clone();
// task_vec.push(tokio::spawn(async move {
// let opclo_30m_option = rt_price_30m_vec_c.iter().position(|x| *x.0 == element.0);
// if opclo_30m_option.is_some() {
// if rt_price_30m_vec_c[opclo_30m_option.unwrap()]
// .1
// .last()
// .is_some()
// {
// let mut filtered_symbols_lock: tokio::sync::MutexGuard<
// '_,
// Vec<(String, i64, f64)>,
// > = filtered_symbols_arc_c.lock().await;
// filtered_symbols_lock.push((
// elememt_c.0,
// elememt_c.1,
// rt_price_30m_vec_c[opclo_30m_option.unwrap()]
// .1
// .last()
// .unwrap()
// .close_price,
// ));
// }
// }
// }));
// }
// try_join_all(task_vec).await?;
// let a = filtered_symbols_arc.lock().await.clone();
// insert_pre_suggested_coins(5, false, &a, alldata).await;
// Ok(())
// }

View File

@ -0,0 +1,203 @@
// pub async fn strategist_006(
// alldata: &AllData,
// ) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
// // print rt_price for debugging
// // let a = alldata.rt_price_30m_vec.iter().position(|a| a.0 == "BTCUSDT");
// // println!("BTCUSDT: {:?}", alldata.rt_price_30m_vec[a.unwrap()].1.last().unwrap());
// // 1st filtering: making basic form
// let mut filtered_2nd_symbols: Vec<(String, i64)> = Vec::new();
// let mut filtered_2nd_symbols_arc: Arc<Mutex<Vec<(String, i64)>>> =
// Arc::new(Mutex::new(filtered_2nd_symbols)); // (symbol, closetime)
// let mut task_vec = Vec::new();
// let valid_symbol_vec_c = alldata.valid_symbol_vec.clone();
// for symbol in valid_symbol_vec_c {
// let mut opclo_30m_vec: Vec<RealtimePriceData> = Vec::new();
// let rt_price_30m_vec_c = alldata.rt_price_30m_vec.clone();
// let filtered_2nd_symbols_arc_c = Arc::clone(&filtered_2nd_symbols_arc);
// task_vec.push(tokio::spawn(async move {
// let opclo_30m_option = rt_price_30m_vec_c.iter().position(|x| *x.0 == symbol);
// if opclo_30m_option.is_some() {
// opclo_30m_vec = rt_price_30m_vec_c[opclo_30m_option.unwrap()].1.clone();
// if opclo_30m_vec.len() >= 3 {
// let mut filtered_2nd_symbols_lock =
// filtered_2nd_symbols_arc_c.lock().await;
// filtered_2nd_symbols_lock
// .push((symbol.clone(), opclo_30m_vec.last().unwrap().close_time));
// }
// }
// }));
// }
// try_join_all(task_vec).await?;
// // 2nd filtering: lookup tables if the tradepair is already there
// let inspect_table_name_1 = String::from("buy_ordered_coin_list");
// let inspect_table_name_2 = String::from("sell_ordered_coin_list");
// let inspect_table_name_3 = String::from("pre_suggested_coin_list");
// let inspect_table_name_4 = String::from("suggested_coin_list");
// let mut filtered_3rd_symbols: Vec<(String, i64)> = Vec::new();
// let mut filtered_3rd_symbols_arc: Arc<Mutex<Vec<(String, i64)>>> =
// Arc::new(Mutex::new(filtered_3rd_symbols)); // (symbol, closetime)
// let mut task_vec = Vec::new();
// let filtered_2nd_iter = filtered_2nd_symbols_arc.lock().await.clone().into_iter();
// for element in filtered_2nd_iter {
// let mut exists_condition_build = String::from("symbol=\'");
// exists_condition_build.push_str(element.0.as_str());
// exists_condition_build.push_str("\' AND registerer=");
// exists_condition_build.push_str(6.to_string().as_str());
// // exists_condition_build.push_str("\' AND close_time=");
// // exists_condition_build.push_str(element.1.to_string().as_str());
// let exists_condition = Some(exists_condition_build);
// let exists_condition_c = exists_condition.clone();
// let inspect_table_name_1_c = inspect_table_name_1.clone();
// let inspect_table_name_2_c = inspect_table_name_2.clone();
// let inspect_table_name_3_c = inspect_table_name_3.clone();
// let inspect_table_name_4_c = inspect_table_name_4.clone();
// let element_c = element.clone();
// let filtered_3rd_symbols_arc_c = Arc::clone(&filtered_3rd_symbols_arc);
// task_vec.push(tokio::spawn(async move {
// let inspect_result_1 =
// exists_record(&inspect_table_name_1_c, &exists_condition_c).await;
// let inspect_result_2 =
// exists_record(&inspect_table_name_2_c, &exists_condition_c).await;
// let inspect_result_3 =
// exists_record(&inspect_table_name_3_c, &exists_condition_c).await;
// let inspect_result_4 =
// exists_record(&inspect_table_name_4_c, &exists_condition_c).await;
// if inspect_result_1 == false
// && inspect_result_2 == false
// && inspect_result_3 == false
// && inspect_result_4 == false
// {
// let mut filtered_3rd_symbols_lock = filtered_3rd_symbols_arc_c.lock().await;
// filtered_3rd_symbols_lock.push(element_c);
// }
// }));
// }
// try_join_all(task_vec).await?;
// // 6th filtering: StochRSI (RSI length: 10, Stoch length: 10, smooth k: 3, smooth d: 3) smooth kn > kn-1
// let filtered_3rd_symbol_c = filtered_3rd_symbols_arc.lock().await.clone();
// let mut rsi10_1d_data: Vec<(String, Vec<RsiData>)> = rsi(
// 10,
// &alldata.rt_price_1d_vec,
// &filtered_3rd_symbol_c,
// )
// .await?;
// let stoch_rsi_data = stoch_rsi(&rsi10_1d_data, 10, 3, 3).await?;
// let mut stoch_rsi10_1d_vec: Vec<StochRsiData> = Vec::new();
// let mut filtered_4th_symbols: Vec<(String, i64)> = Vec::new(); // (symbol, closetime)
// for element in filtered_3rd_symbol_c {
// let stoch_rsi10_1d_option = stoch_rsi_data.iter().position(|x| *x.0 == element.0);
// if stoch_rsi10_1d_option.is_some() {
// stoch_rsi10_1d_vec = stoch_rsi_data[stoch_rsi10_1d_option.unwrap()].1.clone();
// if stoch_rsi10_1d_vec.len() >= 3 {
// let stoch_rsi_search_result = stoch_rsi10_1d_vec.binary_search_by_key(
// &element.1,
// |&StochRsiData {
// k,
// d,
// close_time,
// }| close_time,
// );
// if stoch_rsi_search_result.is_ok() {
// if stoch_rsi10_1d_vec[stoch_rsi_search_result.unwrap()].k > stoch_rsi10_1d_vec[stoch_rsi_search_result.unwrap()-1].k &&
// stoch_rsi10_1d_vec[stoch_rsi_search_result.unwrap()].k < 90.0 &&
// stoch_rsi10_1d_vec[stoch_rsi_search_result.unwrap()-1].k > 10.0 {
// filtered_4th_symbols.push(element);
// }
// }
// }
// }
// }
// // 6th filtering condition: MACD
// let mut opclo_30m_vec: Vec<RealtimePriceData> = Vec::new();
// let mut ema3_1d_vec: &Vec<EmaData> = &Vec::new();
// let mut ema10_1d_vec: &Vec<EmaData> = &Vec::new();
// let ema3_1d_data: Vec<(String, Vec<EmaData>)> = ema(
// 3,
// &alldata.rt_price_1d_vec,
// &filtered_4th_symbols,
// )
// .await?;
// let ema10_1d_data: Vec<(String, Vec<EmaData>)> = ema(
// 10,
// &alldata.rt_price_1d_vec,
// &filtered_4th_symbols,
// )
// .await?;
// let mut filtered_5th_symbols: Vec<(String, i64)> = Vec::new(); // (symbol, closetime)
// for element in filtered_4th_symbols {
// let ema3_1d_option = ema3_1d_data.iter().position(|x| *x.0 == *element.0);
// let ema10_1d_option = ema10_1d_data.iter().position(|x| *x.0 == *element.0);
// if ema3_1d_option.is_some() && ema10_1d_option.is_some() {
// ema3_1d_vec = &ema3_1d_data[ema3_1d_option.unwrap()].1;
// ema10_1d_vec = &ema10_1d_data[ema10_1d_option.unwrap()].1;
// if ema3_1d_vec.len() > 20 && ema10_1d_vec.len() > 20 {
// let macd_vec = ema_macd(&ema3_1d_vec, &ema10_1d_vec, 10).await?;
// // let macd_search_result = macd_vec.binary_search_by_key(&element.1, |&EmaMacd{macd_value, close_time}|close_time);
// // if macd_search_result.is_ok() {
// if macd_vec.last().unwrap().macd_value > macd_vec[macd_vec.len() -1].macd_value {
// filtered_5th_symbols.push(element);
// }
// // }
// }
// }
// }
// // final job: adding price information to filtered results
// let mut filtered_symbols: Vec<(String, i64, f64)> = Vec::new(); // (symbol, closetime, current price)
// let mut filtered_symbols_arc = Arc::new(Mutex::new(filtered_symbols));
// let mut task_vec = Vec::new();
// for element in filtered_5th_symbols {
// let mut filtered_symbols_arc_c = Arc::clone(&filtered_symbols_arc);
// let rt_price_30m_vec_c = alldata.rt_price_30m_vec.clone();
// let elememt_c = element.clone();
// task_vec.push(tokio::spawn(async move {
// let opclo_30m_option = rt_price_30m_vec_c.iter().position(|x| *x.0 == element.0);
// if opclo_30m_option.is_some() {
// if rt_price_30m_vec_c[opclo_30m_option.unwrap()]
// .1
// .last()
// .is_some()
// {
// let mut filtered_symbols_lock: tokio::sync::MutexGuard<
// '_,
// Vec<(String, i64, f64)>,
// > = filtered_symbols_arc_c.lock().await;
// filtered_symbols_lock.push((
// elememt_c.0,
// elememt_c.1,
// rt_price_30m_vec_c[opclo_30m_option.unwrap()]
// .1
// .last()
// .unwrap()
// .close_price,
// ));
// }
// }
// }));
// }
// try_join_all(task_vec).await?;
// let a = filtered_symbols_arc.lock().await.clone();
// insert_pre_suggested_coins(6, true, &a, alldata).await;
// Ok(())
// }

View File

@ -0,0 +1,641 @@
use crate::coex::exchange_team::*;
use crate::coex::order_team::*;
use crate::coin_health_check_team::request_others::CoinPriceData;
use csv::{DeserializeRecordsIter, StringRecord};
use rust_decimal::prelude::ToPrimitive;
use rust_decimal::Decimal;
use serde::Deserialize;
use tokio::time::{sleep, Duration, Instant};
use crate::signal_association::signal_decision::*;
use super::{AllData, RealtimePriceData, exists_record, try_select_record, insert_one_record, FromRow};
#[derive(Debug, FromRow)]
struct ServerEpoch {
server_epoch: u64,
}
#[derive(Debug, FromRow)]
struct Record {
symbol: String,
suggested_price: Decimal,
close_time: u64,
registered_server_epoch: u64,
registerer: u16,
is_long: u8,
}
pub async fn execute_list_up_for_buy(
all_data: &AllData,
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
// strategist_001(all_data).await?;
// strategist_002(all_data).await?;
crate::strategy_team::strategy_003::list_up_for_buy(all_data).await?;
// strategist_004(all_data).await?;
// strategist_005(all_data).await?;
// strategist_006(all_data).await?;
Ok(())
}
// useful functions for strategists
pub async fn get_current_price(
symbol: &String,
rt_price_vec: &Vec<(String, Vec<RealtimePriceData>)>,
) -> Option<f64> {
let index_result = rt_price_vec.iter().position(|x| *x.0 == *symbol);
match index_result {
Some(T) => {
if rt_price_vec[T].1.last().is_some() {
Some(rt_price_vec[T].1.last().unwrap().close_price)
} else {
None
}
}
None => None,
}
}
pub async fn insert_pre_suggested_coins(
registerer: i32,
is_long: bool,
filtered_symbols: &Vec<(String, i64, f64)>,
alldata: &AllData,
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
// Check the existance of record that is registered by this strategist
let mut dest_table_name = String::from("suggested_coin_list");
let mut dest2_table_name = String::from("buy_ordered_coin_list");
let mut dest3_table_name = String::from("pre_suggested_coin_list");
let mut insert_table_name = String::from("pre_suggested_coin_list");
let mut exists_condition_build = String::from("registerer=");
exists_condition_build.push_str(registerer.to_string().as_str());
let mut exists_condition = Some(exists_condition_build);
let exists_result1 = exists_record(&dest_table_name, &exists_condition).await;
let exists_result2 = exists_record(&dest2_table_name, &exists_condition).await;
let exists_result3 = exists_record(&dest3_table_name, &exists_condition).await;
let insert_columns = vec![
"symbol",
"close_time",
"suggested_price",
"current_price",
"registered_server_epoch",
"profit_percent",
"minimum_profit_percent",
"maximum_profit_percent",
"registerer",
"is_long",
];
if exists_result1 == true && exists_result2 == true && exists_result3 == true {
// Bring the current list of pre-suggested coins from [pre_suggested_coin_list] and [ordered_coin_list]
#[derive(FromRow)]
struct SelectData {
symbol: String,
close_time: i64,
}
#[derive(FromRow)]
struct SelectData2 {
symbol: String,
close_time: i64,
}
let mut select_columns = String::from("symbol, close_time");
let mut condition_build = String::from("WHERE registerer=");
condition_build.push_str(registerer.to_string().as_str());
let select_condition = Some(condition_build);
let select_data_structure = SelectData {
symbol: String::new(),
close_time: 0,
};
let mut select_columns2 = String::from("symbol, close_time");
let select_data_structure2 = SelectData2 {
symbol: String::new(),
close_time: 0,
};
let suggested_coin_list = try_select_record(
&dest_table_name,
&select_columns,
&select_condition,
&select_data_structure,
)
.await?;
let ordered_coin_list = try_select_record(
&dest2_table_name,
&select_columns2,
&select_condition,
&select_data_structure2,
)
.await?;
let pre_suggested_coin_list = try_select_record(
&dest3_table_name,
&select_columns,
&select_condition,
&select_data_structure,
)
.await?;
// insert record without duplicate(registerer, closetime, symbol) into [pre_suggested_coin_list]
for filtered_element in filtered_symbols {
let mut is_dupe = false; // initialize
for list_element in &suggested_coin_list {
if (filtered_element.0 == list_element.symbol)
&& (filtered_element.1 == list_element.close_time)
{
is_dupe = true;
break;
}
}
for list_element in &ordered_coin_list {
if (filtered_element.0 == list_element.symbol)
&& (filtered_element.1 == list_element.close_time)
{
is_dupe = true;
break;
}
}
for list_element in &pre_suggested_coin_list {
if (filtered_element.0 == list_element.symbol)
&& (filtered_element.1 == list_element.close_time)
{
is_dupe = true;
break;
}
}
if is_dupe == false {
let mut insert_values = vec![
filtered_element.0.clone(), // symbol
filtered_element.1.to_string(), // close_time
filtered_element.2.to_string(), // suggested_price
filtered_element.2.to_string(), // current_price
server_epoch().await.to_string(), // registered_server_epoch
0.0.to_string(), // profit_percent
0.0.to_string(), // minimum_profit_percent
0.0.to_string(), // maximum_profit_percent
registerer.to_string(), // registerer
];
if is_long == true {
insert_values.push(1.to_string()); // is_long
} else {
insert_values.push(0.to_string()); // is_long
}
insert_one_record(&insert_table_name, &insert_columns, &insert_values).await;
}
}
} else if exists_result1 == true && exists_result2 == true && exists_result3 == false {
// Bring the current list of pre-suggested coins from [pre_suggested_coin_list] and [ordered_coin_list]
#[derive(FromRow)]
struct SelectData {
symbol: String,
close_time: i64,
}
#[derive(FromRow)]
struct SelectData2 {
symbol: String,
close_time: i64,
}
let mut select_columns = String::from("symbol, close_time");
let mut condition_build = String::from("WHERE registerer=");
condition_build.push_str(registerer.to_string().as_str());
let select_condition = Some(condition_build);
let select_data_structure = SelectData {
symbol: String::new(),
close_time: 0,
};
let mut select_columns2 = String::from("symbol, close_time");
let select_data_structure2 = SelectData2 {
symbol: String::new(),
close_time: 0,
};
let suggested_coin_list = try_select_record(
&dest_table_name,
&select_columns,
&select_condition,
&select_data_structure,
)
.await?;
let ordered_coin_list = try_select_record(
&dest2_table_name,
&select_columns2,
&select_condition,
&select_data_structure2,
)
.await?;
// insert record without duplicate(registerer, closetime, symbol) into [pre_suggested_coin_list]
for filtered_element in filtered_symbols {
let mut is_dupe = false; // initialize
for list_element in &suggested_coin_list {
if (filtered_element.0 == list_element.symbol)
&& (filtered_element.1 == list_element.close_time)
{
is_dupe = true;
break;
}
}
for list_element in &ordered_coin_list {
if (filtered_element.0 == list_element.symbol)
&& (filtered_element.1 == list_element.close_time)
{
is_dupe = true;
break;
}
}
if is_dupe == false {
let mut insert_values = vec![
filtered_element.0.clone(), // symbol
filtered_element.1.to_string(), // close_time
filtered_element.2.to_string(), // suggested_price
filtered_element.2.to_string(), // current_price
server_epoch().await.to_string(), // registered_server_epoch
0.0.to_string(), // profit_percent
0.0.to_string(), // minimum_profit_percent
0.0.to_string(), // maximum_profit_percent
registerer.to_string(), // registerer
];
if is_long == true {
insert_values.push(1.to_string()); // is_long
} else {
insert_values.push(0.to_string()); // is_long
}
insert_one_record(&insert_table_name, &insert_columns, &insert_values).await;
}
}
} else if exists_result1 == true && exists_result2 == false && exists_result3 == true {
// Bring the current list of pre-suggested coins from [pre_suggested_coin_list] and [ordered_coin_list]
#[derive(FromRow)]
struct SelectData {
symbol: String,
close_time: i64,
}
let mut select_columns = String::from("symbol, close_time");
let mut condition_build = String::from("WHERE registerer=");
condition_build.push_str(registerer.to_string().as_str());
let select_condition = Some(condition_build);
let select_data_structure = SelectData {
symbol: String::new(),
close_time: 0,
};
let suggested_coin_list = try_select_record(
&dest_table_name,
&select_columns,
&select_condition,
&select_data_structure,
)
.await?;
let pre_suggested_coin_list = try_select_record(
&dest3_table_name,
&select_columns,
&select_condition,
&select_data_structure,
)
.await?;
// insert record without duplicate(registerer, closetime, symbol) into [pre_suggested_coin_list]
for filtered_element in filtered_symbols {
let mut is_dupe = false; // initialize
for list_element in &suggested_coin_list {
if (filtered_element.0 == list_element.symbol)
&& (filtered_element.1 == list_element.close_time)
{
is_dupe = true;
break;
}
}
for list_element in &pre_suggested_coin_list {
if (filtered_element.0 == list_element.symbol)
&& (filtered_element.1 == list_element.close_time)
{
is_dupe = true;
break;
}
}
if is_dupe == false {
let mut insert_values = vec![
filtered_element.0.clone(), // symbol
filtered_element.1.to_string(), // close_time
filtered_element.2.to_string(), // suggested_price
filtered_element.2.to_string(), // current_price
server_epoch().await.to_string(), // registered_server_epoch
0.0.to_string(), // profit_percent
0.0.to_string(), // minimum_profit_percent
0.0.to_string(), // maximum_profit_percent
registerer.to_string(), // registerer
];
if is_long == true {
insert_values.push(1.to_string()); // is_long
} else {
insert_values.push(0.to_string()); // is_long
}
insert_one_record(&insert_table_name, &insert_columns, &insert_values).await;
}
}
} else if exists_result1 == true && exists_result2 == false && exists_result3 == false {
// Bring the current list of pre-suggested coins from [pre_suggested_coin_list] and [ordered_coin_list]
#[derive(FromRow)]
struct SelectData {
symbol: String,
close_time: i64,
}
let mut select_columns = String::from("symbol, close_time");
let mut condition_build = String::from("WHERE registerer=");
condition_build.push_str(registerer.to_string().as_str());
let select_condition = Some(condition_build);
let select_data_structure = SelectData {
symbol: String::new(),
close_time: 0,
};
let suggested_coin_list = try_select_record(
&dest_table_name,
&select_columns,
&select_condition,
&select_data_structure,
)
.await?;
// insert record without duplicate(registerer, closetime, symbol) into [pre_suggested_coin_list]
for filtered_element in filtered_symbols {
let mut is_dupe = false; // initialize
for list_element in &suggested_coin_list {
if (filtered_element.0 == list_element.symbol)
&& (filtered_element.1 == list_element.close_time)
{
is_dupe = true;
break;
}
}
if is_dupe == false {
let mut insert_values = vec![
filtered_element.0.clone(), // symbol
filtered_element.1.to_string(), // close_time
filtered_element.2.to_string(), // suggested_price
filtered_element.2.to_string(), // current_price
server_epoch().await.to_string(), // registered_server_epoch
0.0.to_string(), // profit_percent
0.0.to_string(), // minimum_profit_percent
0.0.to_string(), // maximum_profit_percent
registerer.to_string(), // registerer
];
if is_long == true {
insert_values.push(1.to_string()); // is_long
} else {
insert_values.push(0.to_string()); // is_long
}
insert_one_record(&insert_table_name, &insert_columns, &insert_values).await;
}
}
} else if exists_result1 == false && exists_result2 == true && exists_result3 == true {
// Bring the current list of pre-suggested coins from [pre_suggested_coin_list] and [ordered_coin_list]
#[derive(FromRow)]
struct SelectData {
symbol: String,
close_time: i64,
}
#[derive(FromRow)]
struct SelectData2 {
symbol: String,
close_time: i64,
}
let mut select_columns = String::from("symbol, close_time");
let mut condition_build = String::from("WHERE registerer=");
condition_build.push_str(registerer.to_string().as_str());
let select_condition = Some(condition_build);
let select_data_structure = SelectData {
symbol: String::new(),
close_time: 0,
};
let mut select_columns2 = String::from("symbol, close_time");
let select_data_structure2 = SelectData2 {
symbol: String::new(),
close_time: 0,
};
let ordered_coin_list = try_select_record(
&dest2_table_name,
&select_columns2,
&select_condition,
&select_data_structure2,
)
.await?;
let pre_suggested_coin_list = try_select_record(
&dest3_table_name,
&select_columns,
&select_condition,
&select_data_structure,
)
.await?;
// insert record without duplicate(registerer, close_time, symbol) into [pre_suggested_coin_list]
for filtered_element in filtered_symbols {
let mut is_dupe = false; // initialize
for list_element in &ordered_coin_list {
if (filtered_element.0 == list_element.symbol)
&& (filtered_element.1 == list_element.close_time)
{
is_dupe = true;
break;
}
}
for list_element in &pre_suggested_coin_list {
if (filtered_element.0 == list_element.symbol)
&& (filtered_element.1 == list_element.close_time)
{
is_dupe = true;
break;
}
}
if is_dupe == false {
let mut insert_values = vec![
filtered_element.0.clone(), // symbol
filtered_element.1.to_string(), // close_time
filtered_element.2.to_string(), // suggested_price
filtered_element.2.to_string(), // current_price
server_epoch().await.to_string(), // registered_server_epoch
0.0.to_string(), // profit_percent
0.0.to_string(), // minimum_profit_percent
0.0.to_string(), // maximum_profit_percent
registerer.to_string(), // registerer
];
if is_long == true {
insert_values.push(1.to_string()); // is_long
} else {
insert_values.push(0.to_string()); // is_long
}
insert_one_record(&insert_table_name, &insert_columns, &insert_values).await;
}
}
} else if exists_result1 == false && exists_result2 == true && exists_result3 == false {
// Bring the current list of pre-suggested coins from [pre_suggested_coin_list] and [ordered_coin_list]
#[derive(FromRow)]
struct SelectData {
symbol: String,
close_time: i64,
}
#[derive(FromRow)]
struct SelectData2 {
symbol: String,
close_time: i64,
}
let mut select_columns = String::from("symbol, close_time");
let mut condition_build = String::from("WHERE registerer=");
condition_build.push_str(registerer.to_string().as_str());
let select_condition = Some(condition_build);
let select_data_structure = SelectData {
symbol: String::new(),
close_time: 0,
};
let mut select_columns2 = String::from("symbol, close_time");
let select_data_structure2 = SelectData2 {
symbol: String::new(),
close_time: 0,
};
let ordered_coin_list = try_select_record(
&dest2_table_name,
&select_columns2,
&select_condition,
&select_data_structure2,
)
.await?;
// insert record without duplicate(registerer, closetime, symbol) into [pre_suggested_coin_list]
for filtered_element in filtered_symbols {
let mut is_dupe = false; // initialize
for list_element in &ordered_coin_list {
if (filtered_element.0 == list_element.symbol)
&& (filtered_element.1 == list_element.close_time)
{
is_dupe = true;
break;
}
}
if is_dupe == false {
let mut insert_values = vec![
filtered_element.0.clone(), // symbol
filtered_element.1.to_string(), // close_time
filtered_element.2.to_string(), // suggested_price
filtered_element.2.to_string(), // current_price
server_epoch().await.to_string(), // registered_server_epoch
0.0.to_string(), // profit_percent
0.0.to_string(), // minimum_profit_percent
0.0.to_string(), // maximum_profit_percent
registerer.to_string(), // registerer
];
if is_long == true {
insert_values.push(1.to_string()); // is_long
} else {
insert_values.push(0.to_string()); // is_long
}
insert_one_record(&insert_table_name, &insert_columns, &insert_values).await;
}
}
} else if exists_result1 == false && exists_result2 == false && exists_result3 == true {
// Bring the current list of pre-suggested coins from [pre_suggested_coin_list] and [ordered_coin_list]
#[derive(FromRow)]
struct SelectData {
symbol: String,
close_time: i64,
}
let mut select_columns = String::from("symbol, close_time");
let mut condition_build = String::from("WHERE registerer=");
condition_build.push_str(registerer.to_string().as_str());
let select_condition = Some(condition_build);
let select_data_structure = SelectData {
symbol: String::new(),
close_time: 0,
};
let pre_suggested_coin_list = try_select_record(
&dest3_table_name,
&select_columns,
&select_condition,
&select_data_structure,
)
.await?;
// insert record without duplicate(registerer, closetime, symbol) into [pre_suggested_coin_list]
for filtered_element in filtered_symbols {
let mut is_dupe = false; // initialize
for list_element in &pre_suggested_coin_list {
if (filtered_element.0 == list_element.symbol)
&& (filtered_element.1 == list_element.close_time)
{
is_dupe = true;
break;
}
}
if is_dupe == false {
let mut insert_values = vec![
filtered_element.0.clone(), // symbol
filtered_element.1.to_string(), // close_time
filtered_element.2.to_string(), // suggested_price
filtered_element.2.to_string(), // current_price
server_epoch().await.to_string(), // registered_server_epoch
0.0.to_string(), // profit_percent
0.0.to_string(), // minimum_profit_percent
0.0.to_string(), // maximum_profit_percent
registerer.to_string(), // registerer
];
if is_long == true {
insert_values.push(1.to_string()); // is_long
} else {
insert_values.push(0.to_string()); // is_long
}
insert_one_record(&insert_table_name, &insert_columns, &insert_values).await;
}
}
} else {
for filtered_element in filtered_symbols {
let mut insert_values = vec![
filtered_element.0.clone(), // symbol
filtered_element.1.to_string(), // close_time
filtered_element.2.to_string(), // suggested_price
filtered_element.2.to_string(), // current_price
server_epoch().await.to_string(), // registered_server_epoch
0.0.to_string(), // profit_percent
0.0.to_string(), // minimum_profit_percent
0.0.to_string(), // maximum_profit_percent
registerer.to_string(), // registerer
];
if is_long == true {
insert_values.push(1.to_string()); // is_long
} else {
insert_values.push(0.to_string()); // is_long
}
insert_one_record(&insert_table_name, &insert_columns, &insert_values).await;
}
}
Ok(())
}

View File

@ -1 +0,0 @@
pub mod price_data;

View File

@ -0,0 +1 @@
pub mod price_data;