Update filtering

This commit is contained in:
Sik Yoon 2024-05-25 00:37:31 +09:00
parent b867d231fa
commit 2561a1081d
3 changed files with 92 additions and 62 deletions

View File

@ -134,7 +134,7 @@ pub async fn list_up_for_buy(
Ok(()) Ok(())
} }
pub async fn list_up_for_sell() -> Result<(), Box<dyn std::error::Error + Send + Sync>> { pub async fn list_up_for_sell(alldata: &AllData) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let filled_positions = select_filled_positions().await?; let filled_positions = select_filled_positions().await?;
let client = ClientBuilder::new() let client = ClientBuilder::new()
@ -142,9 +142,21 @@ pub async fn list_up_for_sell() -> Result<(), Box<dyn std::error::Error + Send +
.build() .build()
.unwrap(); .unwrap();
let server_epoch = get_server_epoch().await; let server_epoch = get_server_epoch().await;
let mut filtered_symbols: HashMap<String, FilteredDataValue> = HashMap::new();
for element in &filled_positions {
filtered_symbols.insert(element.symbol.clone(), FilteredDataValue::new());
}
let server_epoch = get_server_epoch().await;
let stoch_rsis = stoch_rsi(30, 30, 2, 2, &alldata.rt_price_1m_vec, &filtered_symbols).await?;
for element in filled_positions { for element in filled_positions {
if let Some(stoch_rsis_vec) = stoch_rsis.get(&element.symbol) {
let mut over_turned = false;
let mut is_sell = false; let mut is_sell = false;
if stoch_rsis_vec.last().unwrap().close_time > server_epoch
&& stoch_rsis_vec.last().unwrap().k < stoch_rsis_vec.last().unwrap().d {
over_turned = true;
}
// TODO: BNB 코인이 있으면 // TODO: BNB 코인이 있으면
// let base_qty_to_be_ordered = // let base_qty_to_be_ordered =
@ -162,6 +174,8 @@ pub async fn list_up_for_sell() -> Result<(), Box<dyn std::error::Error + Send +
} else if server_epoch - element.transact_time >= (300_000) * 1 { } else if server_epoch - element.transact_time >= (300_000) * 1 {
// time up selling // time up selling
is_sell = true; is_sell = true;
} else if over_turned == true {
is_sell = true;
} }
if is_sell == true { if is_sell == true {
@ -176,6 +190,7 @@ pub async fn list_up_for_sell() -> Result<(), Box<dyn std::error::Error + Send +
} }
} }
} }
}
Ok(()) Ok(())
} }

View File

@ -133,17 +133,29 @@ pub async fn list_up_for_buy(
Ok(()) Ok(())
} }
pub async fn list_up_for_sell() -> Result<(), Box<dyn std::error::Error + Send + Sync>> { pub async fn list_up_for_sell(alldata: &AllData) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let filled_positions = select_filled_positions().await?; let filled_positions = select_filled_positions().await?;
let client = ClientBuilder::new() let client = ClientBuilder::new()
.timeout(tokio::time::Duration::from_millis(5000)) .timeout(tokio::time::Duration::from_millis(5000))
.build() .build()
.unwrap(); .unwrap();
let mut filtered_symbols: HashMap<String, FilteredDataValue> = HashMap::new();
for element in &filled_positions {
filtered_symbols.insert(element.symbol.clone(), FilteredDataValue::new());
}
let server_epoch = get_server_epoch().await; let server_epoch = get_server_epoch().await;
let stoch_rsis = stoch_rsi(30, 30, 2, 2, &alldata.rt_price_1m_vec, &filtered_symbols).await?;
for element in filled_positions { for element in filled_positions {
if let Some(stoch_rsis_vec) = stoch_rsis.get(&element.symbol) {
let mut over_turned = false;
let mut is_sell = false; let mut is_sell = false;
if stoch_rsis_vec.last().unwrap().close_time > server_epoch
&& stoch_rsis_vec.last().unwrap().k > stoch_rsis_vec.last().unwrap().d {
over_turned = true;
}
// TODO: BNB 코인이 있으면 // TODO: BNB 코인이 있으면
// let base_qty_to_be_ordered = // let base_qty_to_be_ordered =
@ -161,6 +173,8 @@ pub async fn list_up_for_sell() -> Result<(), Box<dyn std::error::Error + Send +
} else if server_epoch - element.transact_time >= (300_000) * 1 { } else if server_epoch - element.transact_time >= (300_000) * 1 {
// time up selling // time up selling
is_sell = true; is_sell = true;
} else if over_turned == true {
is_sell = true;
} }
if is_sell == true { if is_sell == true {
@ -175,6 +189,7 @@ pub async fn list_up_for_sell() -> Result<(), Box<dyn std::error::Error + Send +
} }
} }
} }
}
Ok(()) Ok(())
} }

View File

@ -84,8 +84,8 @@ pub async fn execute_list_up_for_sell(
// &trade_fee_map, // &trade_fee_map,
// ) // )
// .await; // .await;
crate::strategy_team::future_strategy_long::list_up_for_sell().await; crate::strategy_team::future_strategy_long::list_up_for_sell(&all_data).await;
crate::strategy_team::future_strategy_short::list_up_for_sell().await; crate::strategy_team::future_strategy_short::list_up_for_sell(&all_data).await;
Ok(()) Ok(())
} }