From aca9eff415dbe607c9370b8bdce71f11b334423f Mon Sep 17 00:00:00 2001 From: Sik Yoon Date: Mon, 18 Dec 2023 01:17:05 +0900 Subject: [PATCH 1/4] Add strategy_test --- src/strategy_team/mod.rs | 2 ++ src/strategy_team/strategy_test.rs | 32 +++++++++++++++++++++ src/value_estimation_team/indicators/adx.rs | 4 +-- 3 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 src/strategy_team/strategy_test.rs 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_test.rs b/src/strategy_team/strategy_test.rs new file mode 100644 index 0000000..1c0a146 --- /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..554306e 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 From b09edb979626d29433934d4268dd8c5a23f09818 Mon Sep 17 00:00:00 2001 From: Sik Yoon Date: Mon, 18 Dec 2023 01:20:31 +0900 Subject: [PATCH 2/4] Change code to test --- src/strategy_team/strategy_manager.rs | 12 +++++++----- src/strategy_team/strategy_test.rs | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/strategy_team/strategy_manager.rs b/src/strategy_team/strategy_manager.rs index 51d4686..1223dfb 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); - 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 index 1c0a146..7461fcd 100644 --- a/src/strategy_team/strategy_test.rs +++ b/src/strategy_team/strategy_test.rs @@ -7,7 +7,7 @@ use super::{ pub async fn strategist_test( - alldata: &AllData, + alldata: AllData, ) -> Result<(), Box> { // print rt_price for debugging // let a = alldata.rt_price_30m_vec.iter().position(|a| a.0 == "BTCUSDT"); From 832ebd76fb83eabab763be3c3b71ae031db0e482 Mon Sep 17 00:00:00 2001 From: Sik Yoon Date: Mon, 18 Dec 2023 01:53:21 +0900 Subject: [PATCH 3/4] Fix wrong calculation --- src/strategy_team/strategy_manager.rs | 2 +- src/strategy_team/strategy_test.rs | 12 ++++++------ src/value_estimation_team/indicators/adx.rs | 5 +++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/strategy_team/strategy_manager.rs b/src/strategy_team/strategy_manager.rs index 1223dfb..28c37b6 100644 --- a/src/strategy_team/strategy_manager.rs +++ b/src/strategy_team/strategy_manager.rs @@ -46,7 +46,7 @@ pub async fn execute_list_up_for_buy( // 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); + crate::strategy_team::strategy_test::strategist_test(all_data_c4).await; // try_join_all(task_vec).await?; Ok(()) diff --git a/src/strategy_team/strategy_test.rs b/src/strategy_team/strategy_test.rs index 7461fcd..810b0c2 100644 --- a/src/strategy_team/strategy_test.rs +++ b/src/strategy_team/strategy_test.rs @@ -15,15 +15,15 @@ pub async fn strategist_test( // 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(); + // 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"); + // 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); + // 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); diff --git a/src/value_estimation_team/indicators/adx.rs b/src/value_estimation_team/indicators/adx.rs index 554306e..3473758 100644 --- a/src/value_estimation_team/indicators/adx.rs +++ b/src/value_estimation_team/indicators/adx.rs @@ -94,9 +94,10 @@ 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 From c66c24ff81dfdbca34a110c77ce7045cb813195e Mon Sep 17 00:00:00 2001 From: Sik Yoon Date: Mon, 18 Dec 2023 02:25:47 +0900 Subject: [PATCH 4/4] Fix typo --- src/value_estimation_team/indicators/adx.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/value_estimation_team/indicators/adx.rs b/src/value_estimation_team/indicators/adx.rs index 3473758..9ecdce4 100644 --- a/src/value_estimation_team/indicators/adx.rs +++ b/src/value_estimation_team/indicators/adx.rs @@ -101,7 +101,7 @@ filtered_symbols: &Vec,) -> Result)>, Bo 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;