Add strategy005, 006

This commit is contained in:
Sik Yoon 2023-12-18 04:11:12 +09:00
parent 08ef3cf59a
commit 115c7fda72
3 changed files with 750 additions and 365 deletions

View File

@ -1,192 +1,377 @@
// 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());
use super::{
dec, decimal_add, decimal_sub, ema, exists_record, insert_pre_suggested_coins,
limit_order_sell, rsi, select_filled_buy_orders, stoch_rsi, supertrend, try_join_all, AllData,
Arc, Client, ClientBuilder, Decimal, EmaData, ExchangeInfo, FilteredData, Mutex,
RealtimePriceData, RoundingStrategy, RsiData, StochRsiData, SupertrendData, TradeFee, update_record3, adx, AdxData
};
// // 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;
// Triple SuperTrend strategy
// SuperTrend length: 20, multiplier: 1.5, BUY signal
// ADX(10, 10) < 25.0
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());
// 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();
// 1st 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");
// 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?;
let mut filtered_data_1st: Vec<FilteredData> = Vec::new();
let mut filtered_data_1st_arc: Arc<Mutex<Vec<FilteredData>>> =
Arc::new(Mutex::new(filtered_data_1st));
let mut task_vec = Vec::new();
// // 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");
for symbol in &alldata.valid_symbol_vec {
let mut exists_condition_build = String::from("symbol=\'");
exists_condition_build.push_str(symbol.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 symbol_c = symbol.clone();
let filtered_data_1st_arc_c = Arc::clone(&filtered_data_1st_arc);
task_vec.push(tokio::spawn(async move {
let mut filtered_data = FilteredData::new();
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;
// 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();
if inspect_result_1 == false
&& inspect_result_2 == false
&& inspect_result_3 == false
&& inspect_result_4 == false
{
let mut filtered_data_1st_lock = filtered_data_1st_arc_c.lock().await;
// 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;
filtered_data.symbol = symbol_c;
// 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?;
filtered_data_1st_lock.push(filtered_data);
}
}));
}
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();
// 2nd filtering: supertrend(ATR period 20, multiplier: 1.5, 30m close price), signal should be BUY
let filtered_data_1st = filtered_data_1st_arc.lock().await.clone();
let mut filtered_data_2nd: Vec<FilteredData> = Vec::new();
let mut filtered_data_2nd_arc: Arc<Mutex<Vec<FilteredData>>> =
Arc::new(Mutex::new(filtered_data_2nd));
let mut task_vec = Vec::new();
// 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);
// }
// }
// }
// }
// }
// }
for element in filtered_data_1st {
let mut rt_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_data_2nd_arc_c = Arc::clone(&filtered_data_2nd_arc);
task_vec.push(tokio::spawn(async move {
let rt_30m_option = rt_price_30m_vec_c
.iter()
.position(|x| *x.0 == element.symbol);
let supertrend_option_30m =
supertrend(&element.symbol, &rt_price_30m_vec_c, 20, 1.5, true).await;
// // 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();
if rt_30m_option.is_some() && supertrend_option_30m.is_some() {
rt_30m_vec = rt_price_30m_vec_c[rt_30m_option.unwrap()].1.clone();
supertrend_vec = supertrend_option_30m.unwrap();
// 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
if rt_30m_vec.len() >= 3 && supertrend_vec.len() >= 3 {
let supertrend_search_result = supertrend_vec.binary_search_by_key(
&rt_30m_vec.last().unwrap().close_time,
|SupertrendData {
band_value,
signal,
area,
close_time,
}| *close_time,
);
if supertrend_search_result.is_ok() {
let current_price: Decimal = rust_decimal::prelude::FromPrimitive::from_f64(rt_30m_vec.last().unwrap().close_price).unwrap();
if supertrend_vec[supertrend_search_result.unwrap()].signal.as_ref().is_some_and(|x| x.contains("BUY"))
&& current_price
< rust_decimal::prelude::FromPrimitive::from_f64(
supertrend_vec[supertrend_search_result.unwrap()-1].band_value * 1.002,
)
.unwrap()
&& supertrend_vec[supertrend_search_result.unwrap()-1].band_value > supertrend_vec[supertrend_search_result.unwrap()].band_value
{
let mut filtered_data_2nd_lock = filtered_data_2nd_arc_c.lock().await;
let mut filtered_data = FilteredData::new();
filtered_data.symbol = element.symbol.clone();
filtered_data.closetime = supertrend_vec[supertrend_search_result.unwrap()].close_time;
filtered_data.current_price = current_price;
filtered_data.stoploss = rust_decimal::prelude::FromPrimitive::from_f64(supertrend_vec[supertrend_search_result.unwrap()].band_value).unwrap();
let target_price = decimal_add(
filtered_data.current_price,
decimal_sub(filtered_data.current_price, filtered_data.stoploss),
);
filtered_data.target_price = target_price;
filtered_data_2nd_lock.push(filtered_data);
}
}
}
}
}));
}
try_join_all(task_vec).await?;
// 3rd filtering: ADX(10, 10) < 25.0
let filtered_data_2nd = filtered_data_2nd_arc.lock().await.clone();
let mut filtered_data_3rd: Vec<FilteredData> = Vec::new();
let mut filtered_data_3rd_arc: Arc<Mutex<Vec<FilteredData>>> =
Arc::new(Mutex::new(filtered_data_3rd));
let mut task_vec = Vec::new();
let valid_symbol_vec_c = alldata.valid_symbol_vec.clone();
let adx_vec = adx(10, 10, &alldata.rt_price_30m_vec, &filtered_data_2nd).await?;
for element in filtered_data_2nd {
let mut adx_vec_c = adx_vec.clone();
let symbol = element.symbol.clone();
let close_time = element.closetime;
let idx_result = adx_vec.iter().position(|elem| elem.0 == symbol);
let filtered_data_3rd_arc_c = Arc::clone(&filtered_data_3rd_arc);
if idx_result.is_some(){
task_vec.push(tokio::spawn(async move {
let closetime_idx_result = adx_vec_c[idx_result.unwrap()].1.iter().position(|elem| elem.close_time==close_time);
if closetime_idx_result.is_some() {
if adx_vec_c[idx_result.unwrap()].1[closetime_idx_result.unwrap()].adx < 25.0 {
let mut filtered_3rd_symbols_lock =
filtered_data_3rd_arc_c.lock().await;
let mut filtered_data = FilteredData::new();
filtered_data.symbol = element.symbol.clone();
filtered_data.closetime = element.closetime;
filtered_data.current_price = element.current_price;
filtered_data.stoploss = element.stoploss;
filtered_data.target_price = element.target_price;
filtered_3rd_symbols_lock.push(filtered_data);
}
}
}));
}
}
try_join_all(task_vec).await?;
// 4th filtering: supertrend(ATR period 3, multiplier: 1.1, 1d close price), the area should be in UP area.
let filtered_data_3rd = filtered_data_3rd_arc.lock().await.clone();
let mut filtered_data_4th: Vec<FilteredData> = Vec::new();
let mut filtered_data_4th_arc: Arc<Mutex<Vec<FilteredData>>> =
Arc::new(Mutex::new(filtered_data_4th));
let mut task_vec = Vec::new();
let valid_symbol_vec_c = alldata.valid_symbol_vec.clone();
for element in filtered_data_3rd {
let mut opclo_1d_vec: Vec<RealtimePriceData> = Vec::new();
let mut supertrend_vec: Vec<SupertrendData> = Vec::new();
let rt_price_1d_vec_c = alldata.rt_price_1d_vec.clone();
let filtered_data_4th_arc_c = Arc::clone(&filtered_data_4th_arc);
task_vec.push(tokio::spawn(async move {
let supertrend_option_1d =
supertrend(&element.symbol, &rt_price_1d_vec_c, 3, 1.1, true).await;
if supertrend_option_1d.is_some() {
supertrend_vec = supertrend_option_1d.unwrap();
if supertrend_vec.len() >= 3 {
if supertrend_vec.last().unwrap()
.area
.contains("UP")
{
let mut filtered_4th_symbols_lock =
filtered_data_4th_arc_c.lock().await;
let mut filtered_data = FilteredData::new();
filtered_data.symbol = element.symbol.clone();
filtered_data.closetime = element.closetime;
filtered_data.current_price = element.current_price;
filtered_data.stoploss = element.stoploss;
filtered_data.target_price = element.target_price;
filtered_4th_symbols_lock.push(filtered_data);
}
}
}
}));
}
try_join_all(task_vec).await?;
// 5th filtering: 0.5% <= the average amplitude of the latest 10 30m candles <= 1.0%
let filtered_data_4th_c = filtered_data_4th_arc.lock().await.clone();
let mut filtered_data_5th: Vec<FilteredData> = Vec::new();
let mut filtered_data_5th_arc: Arc<Mutex<Vec<FilteredData>>> =
Arc::new(Mutex::new(filtered_data_5th));
let mut task_vec = Vec::new();
for element in filtered_data_4th_c {
let mut supertrend_vec: Vec<SupertrendData> = Vec::new();
let rt_price_30m_vec_c = alldata.rt_price_30m_vec.clone();
let filtered_data_5th_arc_c = Arc::clone(&filtered_data_5th_arc);
task_vec.push(tokio::spawn(async move {
let position_idx = rt_price_30m_vec_c.iter().position(|elem| elem.0 == element.symbol);
if position_idx.is_some() {
let vec_len = rt_price_30m_vec_c[position_idx.unwrap()].1.len();
if vec_len >= 11 {
let candles = rt_price_30m_vec_c[position_idx.unwrap()].1.get(vec_len-12..vec_len-1).unwrap();
let windows = candles.windows(2);
let mut average_amplitude = 0.0;
for window in windows {
average_amplitude += (window.last().unwrap().high_price - window.last().unwrap().low_price) / window.first().unwrap().close_price;
}
average_amplitude /= 10.0;
if 0.005 <= average_amplitude && average_amplitude <= 0.01 {
let mut filtered_data_5th_lock = filtered_data_5th_arc_c.lock().await;
let mut filtered_data = FilteredData::new();
filtered_data.symbol = element.symbol.clone();
filtered_data.closetime = element.closetime;
filtered_data.current_price = element.current_price;
filtered_data.stoploss = element.stoploss;
filtered_data.target_price = element.target_price;
filtered_data_5th_lock.push(filtered_data);
}
}
}
}));
}
try_join_all(task_vec).await?;
let final_filtered_data = filtered_data_5th_arc.lock().await.clone();
insert_pre_suggested_coins(5, false, &final_filtered_data, &alldata).await;
Ok(())
}
pub async fn list_up_for_sell(
all_data: &AllData,
exchange_info_vec: &Vec<ExchangeInfo>,
trade_fee_vec: &Vec<TradeFee>,
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let filled_buy_orders = select_filled_buy_orders(5).await?;
if !filled_buy_orders.is_empty() {
let client = ClientBuilder::new()
.timeout(tokio::time::Duration::from_millis(5000))
.build()
.unwrap();
let mut supertrend_vec: Vec<SupertrendData> = Vec::new();
for element in filled_buy_orders {
if element.used_usdt >= dec!(10.0) {
let lot_step_size_option = exchange_info_vec
.iter()
.position(|exchange_info| exchange_info.symbol == element.symbol);
let quote_commission_precision_option = exchange_info_vec
.iter()
.position(|exchange_info| exchange_info.symbol == element.symbol);
let opclo_30m_option = all_data
.rt_price_30m_vec
.iter()
.position(|x| *x.0 == element.symbol);
let supertrend_option_30m =
supertrend(&element.symbol, &all_data.rt_price_30m_vec, 10, 1.5, true).await;
if lot_step_size_option.is_some()
&& quote_commission_precision_option.is_some()
&& opclo_30m_option.is_some()
&& supertrend_option_30m.is_some()
{
// update stoploss
supertrend_vec = supertrend_option_30m.unwrap();
let band_value: Decimal = rust_decimal::prelude::FromPrimitive::from_f64(supertrend_vec.last().unwrap().band_value).unwrap();
if supertrend_vec.last().unwrap().area.contains("UP")
&& band_value > element.stoploss {
let update_table_name = String::from("buy_ordered_coin_list");
let update_value = vec![
(String::from("stoploss"), band_value.to_string()),
];
let update_condition = vec![(String::from("id"), element.id.to_string())];
update_record3(&update_table_name, &update_value, &update_condition)
.await
.unwrap();
}
let lot_step_size = exchange_info_vec[lot_step_size_option.unwrap()].stepsize;
let quote_commission_precision = exchange_info_vec
[quote_commission_precision_option.unwrap()]
.quote_commission_precision;
let base_qty_to_be_ordered =
element.base_qty_ordered.round_dp_with_strategy(
lot_step_size.normalize().scale(),
RoundingStrategy::ToZero,
);
if (element.is_long == 0 || element.is_long == 1)
&& !element.current_price.is_zero()
{
if element.current_price >= element.target_price
&& element.pure_profit_percent >= 0.1
{
limit_order_sell(
&element,
element.current_price,
base_qty_to_be_ordered,
&client,
&exchange_info_vec,
&trade_fee_vec,
)
.await;
} else if element.current_price <= element.stoploss {
limit_order_sell(
&element,
element.current_price,
base_qty_to_be_ordered,
&client,
&exchange_info_vec,
&trade_fee_vec,
)
.await;
}
// TODO: sell_count가 1일 때 적용하기
// else if (supertrend_vec
// .last()
// .unwrap()
// .close_price,
// ));
// }
// }
// }));
// .signal
// .as_ref()
// .is_some_and(|x| x.contains("SELL"))
// || supertrend_vec.last().unwrap().area.contains("DOWN"))
// && (supertrend_vec.last().unwrap().close_time > element.close_time)
// {
// println!(
// "SELL signal selling {} {:.2}",
// element.symbol, element.pure_profit_percent
// );
// limit_order_sell(
// &element,
// element.current_price,
// base_qty_to_be_ordered,
// &client,
// &exchange_info_vec,
// &trade_fee_vec,
// )
// .await;
// }
}
}
}
}
}
// try_join_all(task_vec).await?;
// let a = filtered_symbols_arc.lock().await.clone();
// insert_pre_suggested_coins(5, false, &a, alldata).await;
// Ok(())
// }
Ok(())
}

View File

@ -1,203 +1,385 @@
// 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());
use super::{
dec, decimal_add, decimal_sub, ema, exists_record, insert_pre_suggested_coins,
limit_order_sell, rsi, select_filled_buy_orders, stoch_rsi, supertrend, try_join_all, AllData,
Arc, Client, ClientBuilder, Decimal, EmaData, ExchangeInfo, FilteredData, Mutex,
RealtimePriceData, RoundingStrategy, RsiData, StochRsiData, SupertrendData, TradeFee, update_record3, adx, AdxData
};
// // 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();
// Triple SuperTrend strategy
// SuperTrend length: 20, multiplier: 1.5, BUY signal
// ADX(10, 10) < 25.0
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());
// 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);
// 1st 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");
// if opclo_30m_option.is_some() {
// opclo_30m_vec = rt_price_30m_vec_c[opclo_30m_option.unwrap()].1.clone();
let mut filtered_data_1st: Vec<FilteredData> = Vec::new();
let mut filtered_data_1st_arc: Arc<Mutex<Vec<FilteredData>>> =
Arc::new(Mutex::new(filtered_data_1st));
let mut task_vec = Vec::new();
// 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?;
for symbol in &alldata.valid_symbol_vec {
let mut exists_condition_build = String::from("symbol=\'");
exists_condition_build.push_str(symbol.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 symbol_c = symbol.clone();
let filtered_data_1st_arc_c = Arc::clone(&filtered_data_1st_arc);
task_vec.push(tokio::spawn(async move {
let mut filtered_data = FilteredData::new();
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;
// // 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");
if inspect_result_1 == false
&& inspect_result_2 == false
&& inspect_result_3 == false
&& inspect_result_4 == false
{
let mut filtered_data_1st_lock = filtered_data_1st_arc_c.lock().await;
// 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();
filtered_data.symbol = symbol_c;
// 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;
filtered_data_1st_lock.push(filtered_data);
}
}));
}
try_join_all(task_vec).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?;
// 2nd filtering: supertrend(ATR period 20, multiplier: 1.5, 30m close price), signal should be BUY
let filtered_data_1st = filtered_data_1st_arc.lock().await.clone();
let mut filtered_data_2nd: Vec<FilteredData> = Vec::new();
let mut filtered_data_2nd_arc: Arc<Mutex<Vec<FilteredData>>> =
Arc::new(Mutex::new(filtered_data_2nd));
let mut task_vec = Vec::new();
// // 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);
for element in filtered_data_1st {
let mut rt_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_data_2nd_arc_c = Arc::clone(&filtered_data_2nd_arc);
task_vec.push(tokio::spawn(async move {
let rt_30m_option = rt_price_30m_vec_c
.iter()
.position(|x| *x.0 == element.symbol);
let supertrend_option_30m =
supertrend(&element.symbol, &rt_price_30m_vec_c, 20, 1.5, true).await;
// if stoch_rsi10_1d_option.is_some() {
// stoch_rsi10_1d_vec = stoch_rsi_data[stoch_rsi10_1d_option.unwrap()].1.clone();
if rt_30m_option.is_some() && supertrend_option_30m.is_some() {
rt_30m_vec = rt_price_30m_vec_c[rt_30m_option.unwrap()].1.clone();
supertrend_vec = supertrend_option_30m.unwrap();
// 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);
// }
// }
// }
// }
// }
if rt_30m_vec.len() >= 3 && supertrend_vec.len() >= 3 {
let supertrend_search_result = supertrend_vec.binary_search_by_key(
&rt_30m_vec.last().unwrap().close_time,
|SupertrendData {
band_value,
signal,
area,
close_time,
}| *close_time,
);
if supertrend_search_result.is_ok() {
let current_price: Decimal = rust_decimal::prelude::FromPrimitive::from_f64(rt_30m_vec.last().unwrap().close_price).unwrap();
// // 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();
if supertrend_vec[supertrend_search_result.unwrap()].signal.as_ref().is_some_and(|x| x.contains("BUY"))
&& current_price
< rust_decimal::prelude::FromPrimitive::from_f64(
supertrend_vec[supertrend_search_result.unwrap()-1].band_value * 1.002,
)
.unwrap()
&& supertrend_vec[supertrend_search_result.unwrap()-1].band_value > supertrend_vec[supertrend_search_result.unwrap()].band_value
{
let mut filtered_data_2nd_lock = filtered_data_2nd_arc_c.lock().await;
let mut filtered_data = FilteredData::new();
filtered_data.symbol = element.symbol.clone();
filtered_data.closetime = supertrend_vec[supertrend_search_result.unwrap()].close_time;
filtered_data.current_price = current_price;
filtered_data.stoploss = rust_decimal::prelude::FromPrimitive::from_f64(supertrend_vec[supertrend_search_result.unwrap()].band_value).unwrap();
let target_price = decimal_add(
filtered_data.current_price,
decimal_sub(filtered_data.current_price, filtered_data.stoploss),
);
filtered_data.target_price = target_price;
// 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?;
filtered_data_2nd_lock.push(filtered_data);
}
}
}
}
}));
}
try_join_all(task_vec).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);
// 3rd filtering: the 5 previous ADX(10, 10)s are over 25.0 and increased
let filtered_data_2nd = filtered_data_2nd_arc.lock().await.clone();
let mut filtered_data_3rd: Vec<FilteredData> = Vec::new();
let mut filtered_data_3rd_arc: Arc<Mutex<Vec<FilteredData>>> =
Arc::new(Mutex::new(filtered_data_3rd));
let mut task_vec = Vec::new();
let valid_symbol_vec_c = alldata.valid_symbol_vec.clone();
let adx_vec = adx(10, 10, &alldata.rt_price_30m_vec, &filtered_data_2nd).await?;
for element in filtered_data_2nd {
let mut adx_vec_c = adx_vec.clone();
let symbol = element.symbol.clone();
let close_time = element.closetime;
let idx_result = adx_vec.iter().position(|elem| elem.0 == symbol);
let filtered_data_3rd_arc_c = Arc::clone(&filtered_data_3rd_arc);
if idx_result.is_some(){
task_vec.push(tokio::spawn(async move {
let closetime_idx_result = adx_vec_c[idx_result.unwrap()].1.iter().position(|elem| elem.close_time==close_time);
if closetime_idx_result.is_some() {
if adx_vec_c[idx_result.unwrap()].1[closetime_idx_result.unwrap()-1].adx > 25.0 &&
adx_vec_c[idx_result.unwrap()].1[closetime_idx_result.unwrap()-2].adx > 25.0 &&
adx_vec_c[idx_result.unwrap()].1[closetime_idx_result.unwrap()-3].adx > 25.0 &&
adx_vec_c[idx_result.unwrap()].1[closetime_idx_result.unwrap()-4].adx > 25.0 &&
adx_vec_c[idx_result.unwrap()].1[closetime_idx_result.unwrap()-5].adx > 25.0 &&
adx_vec_c[idx_result.unwrap()].1[closetime_idx_result.unwrap()-1].adx > adx_vec_c[idx_result.unwrap()].1[closetime_idx_result.unwrap()-2].adx &&
adx_vec_c[idx_result.unwrap()].1[closetime_idx_result.unwrap()-2].adx > adx_vec_c[idx_result.unwrap()].1[closetime_idx_result.unwrap()-3].adx &&
adx_vec_c[idx_result.unwrap()].1[closetime_idx_result.unwrap()-3].adx > adx_vec_c[idx_result.unwrap()].1[closetime_idx_result.unwrap()-4].adx &&
adx_vec_c[idx_result.unwrap()].1[closetime_idx_result.unwrap()-4].adx > adx_vec_c[idx_result.unwrap()].1[closetime_idx_result.unwrap()-5].adx {
let mut filtered_3rd_symbols_lock =
filtered_data_3rd_arc_c.lock().await;
let mut filtered_data = FilteredData::new();
filtered_data.symbol = element.symbol.clone();
filtered_data.closetime = element.closetime;
filtered_data.current_price = element.current_price;
filtered_data.stoploss = element.stoploss;
filtered_data.target_price = element.target_price;
// 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;
filtered_3rd_symbols_lock.push(filtered_data);
}
}
}));
}
}
try_join_all(task_vec).await?;
// 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);
// 4th filtering: supertrend(ATR period 3, multiplier: 1.1, 1d close price), the area should be in UP area.
let filtered_data_3rd = filtered_data_3rd_arc.lock().await.clone();
let mut filtered_data_4th: Vec<FilteredData> = Vec::new();
let mut filtered_data_4th_arc: Arc<Mutex<Vec<FilteredData>>> =
Arc::new(Mutex::new(filtered_data_4th));
let mut task_vec = Vec::new();
let valid_symbol_vec_c = alldata.valid_symbol_vec.clone();
for element in filtered_data_3rd {
let mut opclo_1d_vec: Vec<RealtimePriceData> = Vec::new();
let mut supertrend_vec: Vec<SupertrendData> = Vec::new();
let rt_price_1d_vec_c = alldata.rt_price_1d_vec.clone();
let filtered_data_4th_arc_c = Arc::clone(&filtered_data_4th_arc);
task_vec.push(tokio::spawn(async move {
let supertrend_option_1d =
supertrend(&element.symbol, &rt_price_1d_vec_c, 3, 1.1, true).await;
// // 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);
// }
// // }
// }
// }
// }
if supertrend_option_1d.is_some() {
supertrend_vec = supertrend_option_1d.unwrap();
// // 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();
if supertrend_vec.len() >= 3 {
if supertrend_vec.last().unwrap()
.area
.contains("UP")
{
let mut filtered_4th_symbols_lock =
filtered_data_4th_arc_c.lock().await;
let mut filtered_data = FilteredData::new();
filtered_data.symbol = element.symbol.clone();
filtered_data.closetime = element.closetime;
filtered_data.current_price = element.current_price;
filtered_data.stoploss = element.stoploss;
filtered_data.target_price = element.target_price;
// 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
filtered_4th_symbols_lock.push(filtered_data);
}
}
}
}));
}
try_join_all(task_vec).await?;
// 5th filtering: 0.5% <= the average amplitude of the latest 10 30m candles <= 1.0%
let filtered_data_4th_c = filtered_data_4th_arc.lock().await.clone();
let mut filtered_data_5th: Vec<FilteredData> = Vec::new();
let mut filtered_data_5th_arc: Arc<Mutex<Vec<FilteredData>>> =
Arc::new(Mutex::new(filtered_data_5th));
let mut task_vec = Vec::new();
for element in filtered_data_4th_c {
let mut supertrend_vec: Vec<SupertrendData> = Vec::new();
let rt_price_30m_vec_c = alldata.rt_price_30m_vec.clone();
let filtered_data_5th_arc_c = Arc::clone(&filtered_data_5th_arc);
task_vec.push(tokio::spawn(async move {
let position_idx = rt_price_30m_vec_c.iter().position(|elem| elem.0 == element.symbol);
if position_idx.is_some() {
let vec_len = rt_price_30m_vec_c[position_idx.unwrap()].1.len();
if vec_len >= 11 {
let candles = rt_price_30m_vec_c[position_idx.unwrap()].1.get(vec_len-12..vec_len-1).unwrap();
let windows = candles.windows(2);
let mut average_amplitude = 0.0;
for window in windows {
average_amplitude += (window.last().unwrap().high_price - window.last().unwrap().low_price) / window.first().unwrap().close_price;
}
average_amplitude /= 10.0;
if 0.005 <= average_amplitude && average_amplitude <= 0.01 {
let mut filtered_data_5th_lock = filtered_data_5th_arc_c.lock().await;
let mut filtered_data = FilteredData::new();
filtered_data.symbol = element.symbol.clone();
filtered_data.closetime = element.closetime;
filtered_data.current_price = element.current_price;
filtered_data.stoploss = element.stoploss;
filtered_data.target_price = element.target_price;
filtered_data_5th_lock.push(filtered_data);
}
}
}
}));
}
try_join_all(task_vec).await?;
let final_filtered_data = filtered_data_5th_arc.lock().await.clone();
insert_pre_suggested_coins(6, false, &final_filtered_data, &alldata).await;
Ok(())
}
pub async fn list_up_for_sell(
all_data: &AllData,
exchange_info_vec: &Vec<ExchangeInfo>,
trade_fee_vec: &Vec<TradeFee>,
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let filled_buy_orders = select_filled_buy_orders(6).await?;
if !filled_buy_orders.is_empty() {
let client = ClientBuilder::new()
.timeout(tokio::time::Duration::from_millis(5000))
.build()
.unwrap();
let mut supertrend_vec: Vec<SupertrendData> = Vec::new();
for element in filled_buy_orders {
if element.used_usdt >= dec!(10.0) {
let lot_step_size_option = exchange_info_vec
.iter()
.position(|exchange_info| exchange_info.symbol == element.symbol);
let quote_commission_precision_option = exchange_info_vec
.iter()
.position(|exchange_info| exchange_info.symbol == element.symbol);
let opclo_30m_option = all_data
.rt_price_30m_vec
.iter()
.position(|x| *x.0 == element.symbol);
let supertrend_option_30m =
supertrend(&element.symbol, &all_data.rt_price_30m_vec, 10, 1.5, true).await;
if lot_step_size_option.is_some()
&& quote_commission_precision_option.is_some()
&& opclo_30m_option.is_some()
&& supertrend_option_30m.is_some()
{
// update stoploss
supertrend_vec = supertrend_option_30m.unwrap();
let band_value: Decimal = rust_decimal::prelude::FromPrimitive::from_f64(supertrend_vec.last().unwrap().band_value).unwrap();
if supertrend_vec.last().unwrap().area.contains("UP")
&& band_value > element.stoploss {
let update_table_name = String::from("buy_ordered_coin_list");
let update_value = vec![
(String::from("stoploss"), band_value.to_string()),
];
let update_condition = vec![(String::from("id"), element.id.to_string())];
update_record3(&update_table_name, &update_value, &update_condition)
.await
.unwrap();
}
let lot_step_size = exchange_info_vec[lot_step_size_option.unwrap()].stepsize;
let quote_commission_precision = exchange_info_vec
[quote_commission_precision_option.unwrap()]
.quote_commission_precision;
let base_qty_to_be_ordered =
element.base_qty_ordered.round_dp_with_strategy(
lot_step_size.normalize().scale(),
RoundingStrategy::ToZero,
);
if (element.is_long == 0 || element.is_long == 1)
&& !element.current_price.is_zero()
{
if element.current_price >= element.target_price
&& element.pure_profit_percent >= 0.1
{
limit_order_sell(
&element,
element.current_price,
base_qty_to_be_ordered,
&client,
&exchange_info_vec,
&trade_fee_vec,
)
.await;
} else if element.current_price <= element.stoploss {
limit_order_sell(
&element,
element.current_price,
base_qty_to_be_ordered,
&client,
&exchange_info_vec,
&trade_fee_vec,
)
.await;
}
// TODO: sell_count가 1일 때 적용하기
// else if (supertrend_vec
// .last()
// .unwrap()
// .close_price,
// ));
// }
// }
// }));
// .signal
// .as_ref()
// .is_some_and(|x| x.contains("SELL"))
// || supertrend_vec.last().unwrap().area.contains("DOWN"))
// && (supertrend_vec.last().unwrap().close_time > element.close_time)
// {
// println!(
// "SELL signal selling {} {:.2}",
// element.symbol, element.pure_profit_percent
// );
// limit_order_sell(
// &element,
// element.current_price,
// base_qty_to_be_ordered,
// &client,
// &exchange_info_vec,
// &trade_fee_vec,
// )
// .await;
// }
}
}
}
}
}
// try_join_all(task_vec).await?;
// let a = filtered_symbols_arc.lock().await.clone();
// insert_pre_suggested_coins(6, true, &a, alldata).await;
// Ok(())
// }
Ok(())
}

View File

@ -34,19 +34,23 @@ pub async fn execute_list_up_for_buy(
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let mut task_vec = Vec::new();
// let all_data_c3 = all_data.clone();
let all_data_c4 = all_data.clone();
// let all_data_c4 = all_data.clone();
let all_data_c5 = all_data.clone();
let all_data_c6 = all_data.clone();
// strategist_001(all_data).await?;
// strategist_002(all_data).await?;
// task_vec.push(tokio::spawn(async move {
// crate::strategy_team::strategy_003::list_up_for_buy(all_data_c3).await;
// }));
// task_vec.push(tokio::spawn(async move {
// crate::strategy_team::strategy_004::list_up_for_buy(all_data_c4).await;
// }));
task_vec.push(tokio::spawn(async move {
crate::strategy_team::strategy_004::list_up_for_buy(all_data_c4).await;
crate::strategy_team::strategy_005::list_up_for_buy(all_data_c5).await;
}));
task_vec.push(tokio::spawn(async move {
crate::strategy_team::strategy_006::list_up_for_buy(all_data_c6).await;
}));
// strategist_004(all_data).await?;
// strategist_005(all_data).await?;
// strategist_006(all_data).await?;
// crate::strategy_team::strategy_test::strategist_test(all_data_c4).await;
try_join_all(task_vec).await?;
Ok(())
@ -64,6 +68,20 @@ pub async fn execute_list_up_for_sell(
)
.await?;
crate::strategy_team::strategy_005::list_up_for_sell(
all_data,
exchange_info_vec,
trade_fee_vec,
)
.await?;
crate::strategy_team::strategy_006::list_up_for_sell(
all_data,
exchange_info_vec,
trade_fee_vec,
)
.await?;
Ok(())
}