Merge pull request 'Add ADX indicator' (#2) from strategy-test into master
Reviewed-on: http://192.168.1.100:3000/Sik/tradingbot/pulls/2
This commit is contained in:
commit
195ac9cea1
|
|
@ -4,6 +4,7 @@ pub mod strategy_003;
|
||||||
pub mod strategy_004;
|
pub mod strategy_004;
|
||||||
pub mod strategy_005;
|
pub mod strategy_005;
|
||||||
pub mod strategy_006;
|
pub mod strategy_006;
|
||||||
|
pub mod strategy_test;
|
||||||
pub mod strategy_manager;
|
pub mod strategy_manager;
|
||||||
|
|
||||||
use crate::coex::order_team::{limit_order_sell, select_filled_buy_orders};
|
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::sma::{sma, SmaData};
|
||||||
use crate::value_estimation_team::indicators::stoch_rsi::{stoch_rsi, StochRsiData};
|
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::supertrend::{supertrend, SupertrendData};
|
||||||
|
use crate::value_estimation_team::indicators::adx::{AdxData, adx};
|
||||||
use futures::future::try_join_all;
|
use futures::future::try_join_all;
|
||||||
use reqwest::{Client, ClientBuilder};
|
use reqwest::{Client, ClientBuilder};
|
||||||
use rust_decimal::{prelude::FromPrimitive, prelude::ToPrimitive, Decimal, RoundingStrategy};
|
use rust_decimal::{prelude::FromPrimitive, prelude::ToPrimitive, Decimal, RoundingStrategy};
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ use rust_decimal::prelude::ToPrimitive;
|
||||||
use rust_decimal::Decimal;
|
use rust_decimal::Decimal;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
|
use super::strategy_test;
|
||||||
use super::{
|
use super::{
|
||||||
exists_record, insert_one_record, try_join_all, try_select_record, AllData, ExchangeInfo,
|
exists_record, insert_one_record, try_join_all, try_select_record, AllData, ExchangeInfo,
|
||||||
FilteredData, FromRow, RealtimePriceData, TradeFee,
|
FilteredData, FromRow, RealtimePriceData, TradeFee,
|
||||||
|
|
@ -31,7 +32,7 @@ struct Record {
|
||||||
pub async fn execute_list_up_for_buy(
|
pub async fn execute_list_up_for_buy(
|
||||||
all_data: &AllData,
|
all_data: &AllData,
|
||||||
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||||
let mut task_vec = Vec::new();
|
// let mut task_vec = Vec::new();
|
||||||
// let all_data_c3 = all_data.clone();
|
// let all_data_c3 = all_data.clone();
|
||||||
let all_data_c4 = all_data.clone();
|
let all_data_c4 = all_data.clone();
|
||||||
// strategist_001(all_data).await?;
|
// strategist_001(all_data).await?;
|
||||||
|
|
@ -39,14 +40,15 @@ pub async fn execute_list_up_for_buy(
|
||||||
// task_vec.push(tokio::spawn(async move {
|
// task_vec.push(tokio::spawn(async move {
|
||||||
// crate::strategy_team::strategy_003::list_up_for_buy(all_data_c3).await;
|
// crate::strategy_team::strategy_003::list_up_for_buy(all_data_c3).await;
|
||||||
// }));
|
// }));
|
||||||
task_vec.push(tokio::spawn(async move {
|
// task_vec.push(tokio::spawn(async move {
|
||||||
crate::strategy_team::strategy_004::list_up_for_buy(all_data_c4).await;
|
// crate::strategy_team::strategy_004::list_up_for_buy(all_data_c4).await;
|
||||||
}));
|
// }));
|
||||||
// strategist_004(all_data).await?;
|
// strategist_004(all_data).await?;
|
||||||
// strategist_005(all_data).await?;
|
// strategist_005(all_data).await?;
|
||||||
// strategist_006(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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
32
src/strategy_team/strategy_test.rs
Normal file
32
src/strategy_team/strategy_test.rs
Normal file
|
|
@ -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<dyn std::error::Error + Send + Sync>> {
|
||||||
|
// 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<FilteredData> = 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(())
|
||||||
|
}
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
// use std::thread::current;
|
|
||||||
|
|
||||||
use super::{FilteredData, RealtimePriceData, try_join_all, Arc, Mutex};
|
use super::{FilteredData, RealtimePriceData, try_join_all, Arc, Mutex};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct AdxData {
|
pub struct AdxData {
|
||||||
pub adx: f64,
|
pub adx: f64,
|
||||||
pub close_time: i64
|
pub close_time: i64
|
||||||
|
|
@ -96,13 +94,14 @@ filtered_symbols: &Vec<FilteredData>,) -> Result<Vec<(String, Vec<AdxData>)>, Bo
|
||||||
// step 4: calculate ADX
|
// step 4: calculate ADX
|
||||||
let mut initial_adx_vec: Vec<AdxData> = Vec::new();
|
let mut initial_adx_vec: Vec<AdxData> = Vec::new();
|
||||||
for di_data in di_data_vec {
|
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 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);
|
initial_adx_vec.push(adx_data);
|
||||||
}
|
}
|
||||||
let partial_vec1 = initial_adx_vec.get(..adx_len).unwrap(); // for calculation of initial value
|
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<AdxData> = Vec::new();
|
let mut smoothed_adx_vec: Vec<AdxData> = Vec::new();
|
||||||
let mut adx_calculated = 0.0;
|
let mut adx_calculated = 0.0;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user