diff --git a/src/strategy_team/mod.rs b/src/strategy_team/mod.rs index 5ebc47c..ef8f45e 100644 --- a/src/strategy_team/mod.rs +++ b/src/strategy_team/mod.rs @@ -4,6 +4,7 @@ pub mod strategy_003; pub mod strategy_004; pub mod strategy_005; pub mod strategy_006; +pub mod strategy_test; pub mod strategy_manager; use crate::coex::order_team::{limit_order_sell, select_filled_buy_orders}; @@ -21,6 +22,7 @@ use crate::value_estimation_team::indicators::rsi::{rsi, RsiData}; use crate::value_estimation_team::indicators::sma::{sma, SmaData}; 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::adx::{AdxData, adx}; use futures::future::try_join_all; use reqwest::{Client, ClientBuilder}; use rust_decimal::{prelude::FromPrimitive, prelude::ToPrimitive, Decimal, RoundingStrategy}; diff --git a/src/strategy_team/strategy_manager.rs b/src/strategy_team/strategy_manager.rs index 51d4686..28c37b6 100644 --- a/src/strategy_team/strategy_manager.rs +++ b/src/strategy_team/strategy_manager.rs @@ -6,6 +6,7 @@ use rust_decimal::prelude::ToPrimitive; use rust_decimal::Decimal; use serde::Deserialize; +use super::strategy_test; use super::{ exists_record, insert_one_record, try_join_all, try_select_record, AllData, ExchangeInfo, FilteredData, FromRow, RealtimePriceData, TradeFee, @@ -31,7 +32,7 @@ struct Record { pub async fn execute_list_up_for_buy( all_data: &AllData, ) -> Result<(), Box> { - let mut task_vec = Vec::new(); + // let mut task_vec = Vec::new(); // let all_data_c3 = all_data.clone(); let all_data_c4 = all_data.clone(); // strategist_001(all_data).await?; @@ -39,14 +40,15 @@ pub async fn execute_list_up_for_buy( // 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; + // })); // 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?; + // try_join_all(task_vec).await?; Ok(()) } diff --git a/src/strategy_team/strategy_test.rs b/src/strategy_team/strategy_test.rs new file mode 100644 index 0000000..810b0c2 --- /dev/null +++ b/src/strategy_team/strategy_test.rs @@ -0,0 +1,32 @@ +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 +}; + + +pub async fn strategist_test( + alldata: AllData, +) -> Result<(), Box> { + // 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: lookup tables if the tradepair is already there + let mut symbol_1 = FilteredData::new(); + // let mut symbol_2 = FilteredData::new(); + // let mut symbol_3 = FilteredData::new(); + symbol_1.symbol = String::from("BTCUSDT"); + // symbol_2.symbol = String::from("XRPUSDT"); + // symbol_3.symbol = String::from("ETHUSDT"); + let mut test_symbols: Vec = Vec::new(); + test_symbols.push(symbol_1); + // test_symbols.push(symbol_2); + // test_symbols.push(symbol_3); + + let a = adx(10, 10, &alldata.rt_price_30m_vec, &test_symbols).await?; + println!("{:?}", a); + + Ok(()) +} diff --git a/src/value_estimation_team/indicators/adx.rs b/src/value_estimation_team/indicators/adx.rs index 0698698..9ecdce4 100644 --- a/src/value_estimation_team/indicators/adx.rs +++ b/src/value_estimation_team/indicators/adx.rs @@ -1,8 +1,6 @@ -// use std::thread::current; - use super::{FilteredData, RealtimePriceData, try_join_all, Arc, Mutex}; -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct AdxData { pub adx: f64, pub close_time: i64 @@ -96,13 +94,14 @@ filtered_symbols: &Vec,) -> Result)>, Bo // step 4: calculate ADX let mut initial_adx_vec: Vec = Vec::new(); for di_data in di_data_vec { - let sum = di_data.di_plus - di_data.di_minus; + let sum = di_data.di_plus + di_data.di_minus; + let difference = (di_data.di_plus - di_data.di_minus).abs(); let divisor = if sum <= 0.00000001 { 1.0 } else { sum }; - let adx_data = AdxData { adx: sum.abs()/divisor, close_time: di_data.close_time }; + let adx_data = AdxData { adx: difference.abs()/divisor, close_time: di_data.close_time }; initial_adx_vec.push(adx_data); } let partial_vec1 = initial_adx_vec.get(..adx_len).unwrap(); // for calculation of initial value - let partial_vec2 = initial_adx_vec.get(di_len..).unwrap(); // for calculation of the rest + let partial_vec2 = initial_adx_vec.get(adx_len..).unwrap(); // for calculation of the rest let mut smoothed_adx_vec: Vec = Vec::new(); let mut adx_calculated = 0.0;