From 31f211c3c2d8b96594c7ffc86ae66d1f44e1ebcd Mon Sep 17 00:00:00 2001 From: Sik Yoon Date: Sun, 26 May 2024 07:07:29 +0900 Subject: [PATCH] Fix wrong selection --- src/future/table_mgmt.rs | 50 ++++++++++++++++++++++ src/strategy_team/future_strategy_long.rs | 5 ++- src/strategy_team/future_strategy_short.rs | 4 +- 3 files changed, 55 insertions(+), 4 deletions(-) diff --git a/src/future/table_mgmt.rs b/src/future/table_mgmt.rs index b1bf768..80860c5 100644 --- a/src/future/table_mgmt.rs +++ b/src/future/table_mgmt.rs @@ -265,6 +265,56 @@ pub async fn select_filled_positions() -> Result, Box Result, Box> { + let select_table_name = String::from("future_ordered_coin_list"); + let select_columns = String::from("*"); + let mut select_condition_build = String::from("WHERE order_type = 'POSITIONING' and position = 'Short' and (status = 'FILLED' or status = 'SIMUL')"); + + let select_condition = Some(select_condition_build); + + let data_struct = PositionCoinList::new(); + + let select_result = try_select_record( + &select_table_name, + &select_columns, + &select_condition, + &data_struct, + ) + .await; + + if select_result.is_ok() { + Ok(select_result.unwrap()) + } else { + eprint!("select_filled_positions() error!"); + Err("error")? + } +} + +pub async fn select_long_filled_positions() -> Result, Box> { + let select_table_name = String::from("future_ordered_coin_list"); + let select_columns = String::from("*"); + let mut select_condition_build = String::from("WHERE order_type = 'POSITIONING' and position = 'Long' and (status = 'FILLED' or status = 'SIMUL')"); + + let select_condition = Some(select_condition_build); + + let data_struct = PositionCoinList::new(); + + let select_result = try_select_record( + &select_table_name, + &select_columns, + &select_condition, + &data_struct, + ) + .await; + + if select_result.is_ok() { + Ok(select_result.unwrap()) + } else { + eprint!("select_filled_positions() error!"); + Err("error")? + } +} + pub async fn select_listuped_positions() -> Result, Box> { let select_table_name = String::from("future_ordered_coin_list"); let select_columns = String::from("*"); diff --git a/src/strategy_team/future_strategy_long.rs b/src/strategy_team/future_strategy_long.rs index 121160c..b960cb9 100644 --- a/src/strategy_team/future_strategy_long.rs +++ b/src/strategy_team/future_strategy_long.rs @@ -13,7 +13,7 @@ use super::{ }; use crate::future::{Position, FuturesExchangeInfo}; -use crate::future::table_mgmt::select_filled_positions; +use crate::future::table_mgmt::select_long_filled_positions; use crate::future::order::{limit_order_close, TimeInForce}; // BUY conditions @@ -250,7 +250,7 @@ pub async fn list_up_for_buy( } pub async fn list_up_for_sell(all_data: &AllData) -> Result<(), Box> { - let filled_positions = select_filled_positions().await?; + let filled_positions = select_long_filled_positions().await?; let client = ClientBuilder::new() .timeout(tokio::time::Duration::from_millis(5000)) @@ -274,6 +274,7 @@ pub async fn list_up_for_sell(all_data: &AllData) -> Result<(), Box server_epoch && sma3_open_vec.last().unwrap().sma_value > sma3_close_vec.last().unwrap().sma_value { over_turned = true; + } } } diff --git a/src/strategy_team/future_strategy_short.rs b/src/strategy_team/future_strategy_short.rs index 293cb43..aeb0919 100644 --- a/src/strategy_team/future_strategy_short.rs +++ b/src/strategy_team/future_strategy_short.rs @@ -13,7 +13,7 @@ use super::{ }; use crate::future::{Position, FuturesExchangeInfo}; -use crate::future::table_mgmt::select_filled_positions; +use crate::future::table_mgmt::select_short_filled_positions; use crate::future::order::{limit_order_close, TimeInForce}; // BUY conditions @@ -250,7 +250,7 @@ pub async fn list_up_for_buy( } pub async fn list_up_for_sell(all_data: &AllData) -> Result<(), Box> { - let filled_positions = select_filled_positions().await?; + let filled_positions = select_short_filled_positions().await?; let client = ClientBuilder::new() .timeout(tokio::time::Duration::from_millis(5000))