Fix wrong selection

This commit is contained in:
Sik Yoon 2024-05-26 07:07:29 +09:00
parent 75f4432090
commit 31f211c3c2
3 changed files with 55 additions and 4 deletions

View File

@ -265,6 +265,56 @@ pub async fn select_filled_positions() -> Result<Vec<PositionCoinList>, Box<dyn
}
}
pub async fn select_short_filled_positions() -> Result<Vec<PositionCoinList>, Box<dyn std::error::Error + Send + Sync>> {
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<Vec<PositionCoinList>, Box<dyn std::error::Error + Send + Sync>> {
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<Vec<PositionCoinList>, Box<dyn std::error::Error + Send + Sync>> {
let select_table_name = String::from("future_ordered_coin_list");
let select_columns = String::from("*");

View File

@ -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<dyn std::error::Error + Send + Sync>> {
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<dyn std::err
&& sma3_open_vec.last().unwrap().close_time > server_epoch
&& sma3_open_vec.last().unwrap().sma_value > sma3_close_vec.last().unwrap().sma_value {
over_turned = true;
}
}
}

View File

@ -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<dyn std::error::Error + Send + Sync>> {
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))