Apply Cargo fmt
This commit is contained in:
parent
8a53e18553
commit
5b7c4a9acb
|
|
@ -1,6 +1,7 @@
|
||||||
// assets_managing_team manages [asset_manage_announcement], [kelly_criterion], and[wallet] ([wallet_testnet] as well)
|
// assets_managing_team manages [asset_manage_announcement], [kelly_criterion], and[wallet] ([wallet_testnet] as well)
|
||||||
|
|
||||||
use crate::coex::exchange_team::*;
|
use crate::coex::exchange_team::*;
|
||||||
|
use crate::coex::order_team::{DBlist, SellHistoryList};
|
||||||
use crate::database_control::*;
|
use crate::database_control::*;
|
||||||
use crate::decimal_funcs::*;
|
use crate::decimal_funcs::*;
|
||||||
use crate::RunningMode::*;
|
use crate::RunningMode::*;
|
||||||
|
|
@ -10,7 +11,6 @@ use rust_decimal::{prelude::ToPrimitive, Decimal, RoundingStrategy};
|
||||||
use rust_decimal_macros::dec;
|
use rust_decimal_macros::dec;
|
||||||
use serde_json::{Result, Value};
|
use serde_json::{Result, Value};
|
||||||
use sqlx::FromRow;
|
use sqlx::FromRow;
|
||||||
use crate::coex::order_team::{DBlist, SellHistoryList};
|
|
||||||
|
|
||||||
#[derive(Debug, FromRow)]
|
#[derive(Debug, FromRow)]
|
||||||
pub struct AchievementEvaluationInfo {
|
pub struct AchievementEvaluationInfo {
|
||||||
|
|
@ -106,7 +106,7 @@ pub async fn set_unit_usdt() {
|
||||||
let mut set_unit_trade_usdt = Decimal::new(0, 8);
|
let mut set_unit_trade_usdt = Decimal::new(0, 8);
|
||||||
|
|
||||||
set_unit_trade_usdt = dec!(30.0); // $30 for each trade
|
set_unit_trade_usdt = dec!(30.0); // $30 for each trade
|
||||||
|
|
||||||
// update fields in [asset_manage_announcement] table
|
// update fields in [asset_manage_announcement] table
|
||||||
let update_table_name = String::from("asset_manage_announcement");
|
let update_table_name = String::from("asset_manage_announcement");
|
||||||
let update_values = vec![(
|
let update_values = vec![(
|
||||||
|
|
@ -196,12 +196,16 @@ pub async fn update_current_total_usdt() {
|
||||||
let asset_info = select_asset_manage_announcement().await;
|
let asset_info = select_asset_manage_announcement().await;
|
||||||
|
|
||||||
let achievement_evaluation = select_achievement_evaluation().await;
|
let achievement_evaluation = select_achievement_evaluation().await;
|
||||||
let balance = decimal_sub(achievement_evaluation.usdt_profit, achievement_evaluation.invested_usdt);
|
let balance = decimal_sub(
|
||||||
|
achievement_evaluation.usdt_profit,
|
||||||
|
achievement_evaluation.invested_usdt,
|
||||||
|
);
|
||||||
let current_total_usdt = decimal_add(asset_info.initial_usdt, balance);
|
let current_total_usdt = decimal_add(asset_info.initial_usdt, balance);
|
||||||
|
|
||||||
let profit = decimal_sub(
|
let profit = decimal_sub(
|
||||||
decimal_div(current_total_usdt, asset_info.initial_usdt),
|
decimal_div(current_total_usdt, asset_info.initial_usdt),
|
||||||
dec!(1));
|
dec!(1),
|
||||||
|
);
|
||||||
|
|
||||||
update_values = vec![
|
update_values = vec![
|
||||||
(
|
(
|
||||||
|
|
@ -290,16 +294,27 @@ pub async fn update_kelly_criterion() -> Result<()> {
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let least_number = 50; // the least number of sell hostory to calculate kelly criterion
|
// FIXME: let least_number = 50;
|
||||||
|
let least_number = 1000000000; // the least number of sell hostory to calculate kelly criterion
|
||||||
|
|
||||||
if sell_history_vec.len() >= least_number {
|
if sell_history_vec.len() >= least_number {
|
||||||
let lose_collection_vec = sell_history_vec.iter().filter(|&a| a.pure_profit_percent < 0.0).collect::<Vec<_>>();
|
let lose_collection_vec = sell_history_vec
|
||||||
let win_collection_vec = sell_history_vec.iter().filter(|&a| a.pure_profit_percent >= 0.0).collect::<Vec<_>>();
|
.iter()
|
||||||
let win_rate: f64 = (win_collection_vec.len() as f64)/(sell_history_vec.len() as f64);
|
.filter(|&a| a.pure_profit_percent < 0.0)
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
let win_collection_vec = sell_history_vec
|
||||||
|
.iter()
|
||||||
|
.filter(|&a| a.pure_profit_percent >= 0.0)
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
let win_rate: f64 = (win_collection_vec.len() as f64) / (sell_history_vec.len() as f64);
|
||||||
let lose_rate: f64 = 1.0 - win_rate;
|
let lose_rate: f64 = 1.0 - win_rate;
|
||||||
let loss_sum = lose_collection_vec.iter().fold(0.0, |acc, x| acc + x.pure_profit_percent);
|
let loss_sum = lose_collection_vec
|
||||||
|
.iter()
|
||||||
|
.fold(0.0, |acc, x| acc + x.pure_profit_percent);
|
||||||
let loss_rate_avg = (loss_sum * 0.01) / (lose_collection_vec.len() as f64) * -1.0;
|
let loss_rate_avg = (loss_sum * 0.01) / (lose_collection_vec.len() as f64) * -1.0;
|
||||||
let profit_sum = win_collection_vec.iter().fold(0.0, |acc, x| acc + x.pure_profit_percent);
|
let profit_sum = win_collection_vec
|
||||||
|
.iter()
|
||||||
|
.fold(0.0, |acc, x| acc + x.pure_profit_percent);
|
||||||
let profit_rate_avg = (profit_sum * 0.01) / (win_collection_vec.len() as f64);
|
let profit_rate_avg = (profit_sum * 0.01) / (win_collection_vec.len() as f64);
|
||||||
|
|
||||||
let betting_rate = (win_rate / loss_rate_avg) - (lose_rate / profit_rate_avg);
|
let betting_rate = (win_rate / loss_rate_avg) - (lose_rate / profit_rate_avg);
|
||||||
|
|
@ -307,19 +322,18 @@ pub async fn update_kelly_criterion() -> Result<()> {
|
||||||
// update kelly_criterion
|
// update kelly_criterion
|
||||||
let update_table_name = String::from("kelly_criterion");
|
let update_table_name = String::from("kelly_criterion");
|
||||||
let update_value = vec![
|
let update_value = vec![
|
||||||
(String::from("betting_rate"), betting_rate.to_string()),
|
(String::from("betting_rate"), betting_rate.to_string()),
|
||||||
(String::from("win_rate"), win_rate.to_string()),
|
(String::from("win_rate"), win_rate.to_string()),
|
||||||
(String::from("lose_rate"), lose_rate.to_string()),
|
(String::from("lose_rate"), lose_rate.to_string()),
|
||||||
(String::from("profit_rate"), profit_rate_avg.to_string()),
|
(String::from("profit_rate"), profit_rate_avg.to_string()),
|
||||||
(String::from("loss_rate"), loss_rate_avg.to_string()),
|
(String::from("loss_rate"), loss_rate_avg.to_string()),
|
||||||
]
|
];
|
||||||
;
|
|
||||||
let update_condition = vec![(String::from("id"), String::from("1"))];
|
let update_condition = vec![(String::from("id"), String::from("1"))];
|
||||||
update_record3(&update_table_name, &update_value, &update_condition)
|
update_record3(&update_table_name, &update_value, &update_condition)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
@ -376,19 +390,24 @@ pub async fn set_available_usdt() {
|
||||||
// fetch current_total_usdt
|
// fetch current_total_usdt
|
||||||
let mut asset_info = select_asset_manage_announcement().await;
|
let mut asset_info = select_asset_manage_announcement().await;
|
||||||
let kelly_criterion_info = select_kelly_criterion().await;
|
let kelly_criterion_info = select_kelly_criterion().await;
|
||||||
|
|
||||||
let mut available_usdt: Decimal;
|
let mut available_usdt: Decimal;
|
||||||
if kelly_criterion_info.betting_rate >= 5.0 && kelly_criterion_info.betting_rate < 100.0 {;
|
if kelly_criterion_info.betting_rate >= 5.0 && kelly_criterion_info.betting_rate < 100.0 {
|
||||||
available_usdt = decimal_mul(asset_info.current_total_usdt, rust_decimal::prelude::FromPrimitive::from_f64(
|
available_usdt = decimal_mul(
|
||||||
kelly_criterion_info.betting_rate * 0.01,
|
asset_info.current_total_usdt,
|
||||||
)
|
rust_decimal::prelude::FromPrimitive::from_f64(
|
||||||
.unwrap());
|
kelly_criterion_info.betting_rate * 0.01,
|
||||||
|
)
|
||||||
|
.unwrap(),
|
||||||
|
);
|
||||||
} else if kelly_criterion_info.betting_rate >= 100.0 {
|
} else if kelly_criterion_info.betting_rate >= 100.0 {
|
||||||
available_usdt = asset_info.current_total_usdt;
|
available_usdt = asset_info.current_total_usdt;
|
||||||
} else { // default: 5% of current_total_usdt
|
} else {
|
||||||
available_usdt = decimal_mul(asset_info.current_total_usdt, dec!(0.05));
|
// default: 5% of current_total_usdt
|
||||||
|
// FIXME: dec!(0.05)
|
||||||
|
available_usdt = decimal_mul(asset_info.current_total_usdt, dec!(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
let unit_trade_usdt = asset_info.unit_trade_usdt;
|
let unit_trade_usdt = asset_info.unit_trade_usdt;
|
||||||
|
|
||||||
// set available_usdt with current_total_usdt and update is_tradable
|
// set available_usdt with current_total_usdt and update is_tradable
|
||||||
|
|
@ -563,9 +582,14 @@ pub async fn select_achievement_evaluation() -> AchievementEvaluationInfo {
|
||||||
let columns = String::from("*");
|
let columns = String::from("*");
|
||||||
let condition = None;
|
let condition = None;
|
||||||
// FIXME: this code should be general
|
// FIXME: this code should be general
|
||||||
let select_result = select_record(&table_name, &columns, &condition, &achievement_evaluation_info)
|
let select_result = select_record(
|
||||||
.await
|
&table_name,
|
||||||
.unwrap();
|
&columns,
|
||||||
|
&condition,
|
||||||
|
&achievement_evaluation_info,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
let result_vec = &select_result[2]; //strategist #3
|
let result_vec = &select_result[2]; //strategist #3
|
||||||
|
|
||||||
achievement_evaluation_info.strategist = result_vec.strategist;
|
achievement_evaluation_info.strategist = result_vec.strategist;
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
use crate::coex::assets_managing_team::*;
|
use crate::coex::assets_managing_team::*;
|
||||||
use crate::coex::order_team::*;
|
use crate::coex::order_team::*;
|
||||||
use crate::strategy_team::AllData;
|
|
||||||
use crate::coin_health_check_team::request_others::{CoinPriceData, ExchangeInfo, TradeFee};
|
use crate::coin_health_check_team::request_others::{CoinPriceData, ExchangeInfo, TradeFee};
|
||||||
use crate::database_control::*;
|
use crate::database_control::*;
|
||||||
use crate::decimal_funcs::{decimal, decimal_add, decimal_div, decimal_mul, decimal_sub};
|
use crate::decimal_funcs::{decimal, decimal_add, decimal_div, decimal_mul, decimal_sub};
|
||||||
use crate::signal_association::signal_decision::*;
|
use crate::signal_association::signal_decision::*;
|
||||||
|
use crate::strategy_team::AllData;
|
||||||
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};
|
||||||
use rust_decimal_macros::dec;
|
use rust_decimal_macros::dec;
|
||||||
|
|
@ -196,7 +196,7 @@ pub struct MarketCapIndex {
|
||||||
|
|
||||||
impl DBlist for MarketCapIndex {
|
impl DBlist for MarketCapIndex {
|
||||||
fn new() -> MarketCapIndex {
|
fn new() -> MarketCapIndex {
|
||||||
let a = MarketCapIndex {
|
let a = MarketCapIndex {
|
||||||
market_cap_index: 0.0,
|
market_cap_index: 0.0,
|
||||||
minimum: 0.0,
|
minimum: 0.0,
|
||||||
maximum: 0.0,
|
maximum: 0.0,
|
||||||
|
|
@ -221,15 +221,15 @@ pub async fn buy_coin(
|
||||||
let mut filtered_suggested_coin_vec: Vec<&SuggestedCoin> = Vec::new();
|
let mut filtered_suggested_coin_vec: Vec<&SuggestedCoin> = Vec::new();
|
||||||
let mut is_exist_delete_symbol: bool = false;
|
let mut is_exist_delete_symbol: bool = false;
|
||||||
let mut delete_condition = String::from("WHERE ");
|
let mut delete_condition = String::from("WHERE ");
|
||||||
|
|
||||||
// filtering symbols to buy
|
// filtering symbols to buy
|
||||||
for element in &suggested_coin {
|
for element in &suggested_coin {
|
||||||
if element.already_buy == 0
|
if element.already_buy == 0 && server_epoch - element.registered_server_epoch <= 300_000
|
||||||
&& server_epoch - element.registered_server_epoch <= 300_000
|
|
||||||
// 300_000 (300 secs = 5 mins)
|
// 300_000 (300 secs = 5 mins)
|
||||||
{
|
{
|
||||||
filtered_suggested_coin_vec.push(element);
|
filtered_suggested_coin_vec.push(element);
|
||||||
} else if server_epoch - element.registered_server_epoch >= 5_400_000 { // 30mins * 3
|
} else if server_epoch - element.registered_server_epoch >= 5_400_000 {
|
||||||
|
// 30mins * 3
|
||||||
delete_condition.push_str("id = ");
|
delete_condition.push_str("id = ");
|
||||||
delete_condition.push_str(element.id.to_string().as_str());
|
delete_condition.push_str(element.id.to_string().as_str());
|
||||||
delete_condition.push_str(" OR ");
|
delete_condition.push_str(" OR ");
|
||||||
|
|
@ -255,14 +255,13 @@ pub async fn buy_coin(
|
||||||
.iter()
|
.iter()
|
||||||
.position(|TradeFee| TradeFee.symbol == element.symbol);
|
.position(|TradeFee| TradeFee.symbol == element.symbol);
|
||||||
|
|
||||||
if exchange_info_result.is_some()
|
if exchange_info_result.is_some() && trade_fee_result.is_some() {
|
||||||
&& trade_fee_result.is_some()
|
let lot_step_size =
|
||||||
{
|
exchange_info_vec[exchange_info_result.unwrap()].stepsize;
|
||||||
let lot_step_size = exchange_info_vec[exchange_info_result.unwrap()].stepsize;
|
|
||||||
let tick_size = exchange_info_vec[exchange_info_result.unwrap()].ticksize;
|
let tick_size = exchange_info_vec[exchange_info_result.unwrap()].ticksize;
|
||||||
let base_commission_precision = exchange_info_vec[exchange_info_result
|
let base_commission_precision = exchange_info_vec
|
||||||
.unwrap()]
|
[exchange_info_result.unwrap()]
|
||||||
.base_commission_precision;
|
.base_commission_precision;
|
||||||
let trade_fee = trade_fee_vec[trade_fee_result.unwrap()].takercommission;
|
let trade_fee = trade_fee_vec[trade_fee_result.unwrap()].takercommission;
|
||||||
|
|
||||||
// buy the suggested coin and transfer it into [buy_ordered_coin_list]
|
// buy the suggested coin and transfer it into [buy_ordered_coin_list]
|
||||||
|
|
@ -272,7 +271,7 @@ pub async fn buy_coin(
|
||||||
lot_step_size.normalize().scale(),
|
lot_step_size.normalize().scale(),
|
||||||
RoundingStrategy::ToZero,
|
RoundingStrategy::ToZero,
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut base_qty_fee_adjusted = Decimal::new(0, 8);
|
let mut base_qty_fee_adjusted = Decimal::new(0, 8);
|
||||||
base_qty_fee_adjusted =
|
base_qty_fee_adjusted =
|
||||||
decimal_mul(base_qty_ordered, decimal_sub(dec!(1), trade_fee))
|
decimal_mul(base_qty_ordered, decimal_sub(dec!(1), trade_fee))
|
||||||
|
|
@ -280,7 +279,7 @@ pub async fn buy_coin(
|
||||||
base_commission_precision,
|
base_commission_precision,
|
||||||
RoundingStrategy::ToZero,
|
RoundingStrategy::ToZero,
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut used_usdt = Decimal::new(0, 8);
|
let mut used_usdt = Decimal::new(0, 8);
|
||||||
used_usdt = decimal_mul(base_qty_ordered, element.suggested_price)
|
used_usdt = decimal_mul(base_qty_ordered, element.suggested_price)
|
||||||
.round_dp_with_strategy(
|
.round_dp_with_strategy(
|
||||||
|
|
@ -301,7 +300,7 @@ pub async fn buy_coin(
|
||||||
.to_f64()
|
.to_f64()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
* 100.0;
|
* 100.0;
|
||||||
|
|
||||||
// order the symbol based on base_qty_ordered and current_price
|
// order the symbol based on base_qty_ordered and current_price
|
||||||
limit_order_buy(
|
limit_order_buy(
|
||||||
element,
|
element,
|
||||||
|
|
@ -343,7 +342,7 @@ pub async fn buy_coin(
|
||||||
.unwrap();
|
.unwrap();
|
||||||
println!("Delete suggested coin list");
|
println!("Delete suggested coin list");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,11 +11,11 @@ use crate::URL_TEST;
|
||||||
// use crates
|
// use crates
|
||||||
use crate::coex::assets_managing_team::*;
|
use crate::coex::assets_managing_team::*;
|
||||||
use crate::coex::exchange_team::*;
|
use crate::coex::exchange_team::*;
|
||||||
use crate::strategy_team::{AllData, TimeData};
|
|
||||||
use crate::coin_health_check_team::request_others::{CoinPriceData, ExchangeInfo, TradeFee};
|
use crate::coin_health_check_team::request_others::{CoinPriceData, ExchangeInfo, TradeFee};
|
||||||
use crate::database_control::*;
|
use crate::database_control::*;
|
||||||
use crate::decimal_funcs::*;
|
use crate::decimal_funcs::*;
|
||||||
use crate::signal_association::signal_decision::*;
|
use crate::signal_association::signal_decision::*;
|
||||||
|
use crate::strategy_team::{AllData, TimeData};
|
||||||
use crate::value_estimation_team::datapoints::price_data::RealtimePriceData;
|
use crate::value_estimation_team::datapoints::price_data::RealtimePriceData;
|
||||||
use crate::value_estimation_team::indicators::ema::EmaData;
|
use crate::value_estimation_team::indicators::ema::EmaData;
|
||||||
use crate::value_estimation_team::indicators::sma::SmaData;
|
use crate::value_estimation_team::indicators::sma::SmaData;
|
||||||
|
|
@ -589,7 +589,7 @@ async fn update_repeat_task(
|
||||||
let trade_fee_result = trade_fee_vec
|
let trade_fee_result = trade_fee_vec
|
||||||
.iter()
|
.iter()
|
||||||
.position(|TradeFee| TradeFee.symbol == element.symbol);
|
.position(|TradeFee| TradeFee.symbol == element.symbol);
|
||||||
|
|
||||||
if price_index_option.is_some()
|
if price_index_option.is_some()
|
||||||
&& lot_step_size_result.is_some()
|
&& lot_step_size_result.is_some()
|
||||||
&& quote_commission_precision_result.is_some()
|
&& quote_commission_precision_result.is_some()
|
||||||
|
|
@ -605,30 +605,36 @@ async fn update_repeat_task(
|
||||||
// to get quote_commission_precision
|
// to get quote_commission_precision
|
||||||
let trade_fee = trade_fee_vec[trade_fee_result.unwrap()].takercommission;
|
let trade_fee = trade_fee_vec[trade_fee_result.unwrap()].takercommission;
|
||||||
let lot_step_size = exchange_info_vec[lot_step_size_result.unwrap()].stepsize;
|
let lot_step_size = exchange_info_vec[lot_step_size_result.unwrap()].stepsize;
|
||||||
let quote_commission_precision = exchange_info_vec[quote_commission_precision_result
|
let quote_commission_precision = exchange_info_vec
|
||||||
.unwrap()]
|
[quote_commission_precision_result.unwrap()]
|
||||||
.quote_commission_precision;
|
.quote_commission_precision;
|
||||||
let base_qty_to_be_ordered = element.base_qty_fee_adjusted.round_dp_with_strategy(
|
let base_qty_to_be_ordered =
|
||||||
lot_step_size.normalize().scale(),
|
element.base_qty_fee_adjusted.round_dp_with_strategy(
|
||||||
RoundingStrategy::ToZero,
|
lot_step_size.normalize().scale(),
|
||||||
);
|
RoundingStrategy::ToZero,
|
||||||
|
);
|
||||||
let expected_get_usdt = decimal_mul(
|
let expected_get_usdt = decimal_mul(
|
||||||
decimal_mul(base_qty_to_be_ordered, price)
|
decimal_mul(base_qty_to_be_ordered, price).round_dp_with_strategy(
|
||||||
.round_dp_with_strategy(quote_commission_precision, RoundingStrategy::ToZero),
|
quote_commission_precision,
|
||||||
|
RoundingStrategy::ToZero,
|
||||||
|
),
|
||||||
decimal_sub(dec!(1), trade_fee),
|
decimal_sub(dec!(1), trade_fee),
|
||||||
);
|
);
|
||||||
let pure_profit_percent =
|
let pure_profit_percent = ((expected_get_usdt.to_f64().unwrap()
|
||||||
((expected_get_usdt.to_f64().unwrap() / element.used_usdt.to_f64().unwrap()) - 1.0)
|
/ element.used_usdt.to_f64().unwrap())
|
||||||
* 100.0;
|
- 1.0)
|
||||||
|
* 100.0;
|
||||||
|
|
||||||
update_record_build.push(element.id.to_string()); // id
|
update_record_build.push(element.id.to_string()); // id
|
||||||
update_record_build.push(price.to_string()); // current_price
|
update_record_build.push(price.to_string()); // current_price
|
||||||
update_record_build.push(expected_get_usdt.to_string()); //expected_get_usdt
|
update_record_build.push(expected_get_usdt.to_string()); //expected_get_usdt
|
||||||
update_record_build.push(decimal_sub(expected_get_usdt, element.used_usdt).to_string()); // expected_usdt_profit
|
update_record_build
|
||||||
|
.push(decimal_sub(expected_get_usdt, element.used_usdt).to_string()); // expected_usdt_profit
|
||||||
update_record_build.push(pure_profit_percent.to_string()); // pure_profit_percent
|
update_record_build.push(pure_profit_percent.to_string()); // pure_profit_percent
|
||||||
|
|
||||||
if element.minimum_profit_percent > pure_profit_percent {
|
if element.minimum_profit_percent > pure_profit_percent {
|
||||||
update_record_build.push(pure_profit_percent.to_string()); // minimum_profit_percent
|
update_record_build.push(pure_profit_percent.to_string());
|
||||||
|
// minimum_profit_percent
|
||||||
} else if pure_profit_percent >= 0.0 {
|
} else if pure_profit_percent >= 0.0 {
|
||||||
update_record_build.push(0.0.to_string()); // minimum_profit_percent
|
update_record_build.push(0.0.to_string()); // minimum_profit_percent
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -637,7 +643,8 @@ async fn update_repeat_task(
|
||||||
}
|
}
|
||||||
|
|
||||||
if element.maximum_profit_percent < pure_profit_percent {
|
if element.maximum_profit_percent < pure_profit_percent {
|
||||||
update_record_build.push(pure_profit_percent.to_string()); // maximum_profit_percent
|
update_record_build.push(pure_profit_percent.to_string());
|
||||||
|
// maximum_profit_percent
|
||||||
} else if pure_profit_percent <= 0.0 {
|
} else if pure_profit_percent <= 0.0 {
|
||||||
update_record_build.push(0.0.to_string()); // maximum_profit_percent
|
update_record_build.push(0.0.to_string()); // maximum_profit_percent
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -2089,7 +2096,9 @@ async fn get_timestamp() -> String {
|
||||||
}
|
}
|
||||||
|
|
||||||
// parameter 0: select all registerers
|
// parameter 0: select all registerers
|
||||||
pub async fn select_filled_buy_orders(registerer: u32) -> Result<Vec<BuyOrderedCoinList>, Box<dyn std::error::Error + Send + Sync>> {
|
pub async fn select_filled_buy_orders(
|
||||||
|
registerer: u32,
|
||||||
|
) -> Result<Vec<BuyOrderedCoinList>, Box<dyn std::error::Error + Send + Sync>> {
|
||||||
let select_table_name = String::from("buy_ordered_coin_list");
|
let select_table_name = String::from("buy_ordered_coin_list");
|
||||||
let select_columns = String::from("*");
|
let select_columns = String::from("*");
|
||||||
let mut select_condition_build = String::from("WHERE (status = 'FILLED' or status = 'SIMUL')");
|
let mut select_condition_build = String::from("WHERE (status = 'FILLED' or status = 'SIMUL')");
|
||||||
|
|
@ -2115,7 +2124,6 @@ pub async fn select_filled_buy_orders(registerer: u32) -> Result<Vec<BuyOrderedC
|
||||||
eprint!("select_filled_buy_order() error!");
|
eprint!("select_filled_buy_order() error!");
|
||||||
Err("error")?
|
Err("error")?
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// select open buy orders (NEW, Partially Filled)
|
// select open buy orders (NEW, Partially Filled)
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
use crate::coin_health_check_team::{request_candles::*, request_others::ExchangeInfo};
|
use crate::coin_health_check_team::{request_candles::*, request_others::ExchangeInfo};
|
||||||
|
use crate::decimal_funcs::*;
|
||||||
use crate::RunningMode::*;
|
use crate::RunningMode::*;
|
||||||
use crate::{database_control::*, RUNNING_MODE};
|
use crate::{database_control::*, RUNNING_MODE};
|
||||||
use hex::ToHex;
|
use hex::ToHex;
|
||||||
|
|
@ -6,7 +7,6 @@ use hmac_sha256::HMAC;
|
||||||
use reqwest::{Client, ClientBuilder, Response};
|
use reqwest::{Client, ClientBuilder, Response};
|
||||||
use rust_decimal::{prelude::ToPrimitive, Decimal};
|
use rust_decimal::{prelude::ToPrimitive, Decimal};
|
||||||
use rust_decimal_macros::dec;
|
use rust_decimal_macros::dec;
|
||||||
use crate::decimal_funcs::*;
|
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
use sqlx::{Error, FromRow};
|
use sqlx::{Error, FromRow};
|
||||||
|
|
@ -26,12 +26,15 @@ pub async fn initialize_valid_usde_trade() -> Result<(), Box<dyn std::error::Err
|
||||||
struct UsdtTrades {
|
struct UsdtTrades {
|
||||||
symbol: String,
|
symbol: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut usdt_trades = UsdtTrades { symbol: String::new()};
|
let mut usdt_trades = UsdtTrades {
|
||||||
|
symbol: String::new(),
|
||||||
|
};
|
||||||
|
|
||||||
let fetch_table_name = String::from("all_24h_change");
|
let fetch_table_name = String::from("all_24h_change");
|
||||||
let column_name = String::from("symbol");
|
let column_name = String::from("symbol");
|
||||||
let mut condition_build = String::from("WHERE symbol LIKE '%USDT' AND symbol NOT LIKE '%DOWNUSDT'");
|
let mut condition_build =
|
||||||
|
String::from("WHERE symbol LIKE '%USDT' AND symbol NOT LIKE '%DOWNUSDT'");
|
||||||
condition_build.push_str(" AND symbol NOT LIKE '%UPUSDT' AND firstId >= 0 AND lastId >= 0");
|
condition_build.push_str(" AND symbol NOT LIKE '%UPUSDT' AND firstId >= 0 AND lastId >= 0");
|
||||||
condition_build.push_str(" AND bidPrice > 0");
|
condition_build.push_str(" AND bidPrice > 0");
|
||||||
condition_build.push_str(" AND bidQty > 0");
|
condition_build.push_str(" AND bidQty > 0");
|
||||||
|
|
@ -58,11 +61,12 @@ pub async fn initialize_valid_usde_trade() -> Result<(), Box<dyn std::error::Err
|
||||||
condition_build.push_str(" AND symbol NOT LIKE 'BTCSTUSDT'");
|
condition_build.push_str(" AND symbol NOT LIKE 'BTCSTUSDT'");
|
||||||
condition_build.push_str(" AND symbol NOT LIKE 'ACAUSDT'");
|
condition_build.push_str(" AND symbol NOT LIKE 'ACAUSDT'");
|
||||||
condition_build.push_str(" AND symbol NOT LIKE 'ANCUSDT'");
|
condition_build.push_str(" AND symbol NOT LIKE 'ANCUSDT'");
|
||||||
|
|
||||||
let condition = Some(condition_build);
|
let condition = Some(condition_build);
|
||||||
|
|
||||||
// get valid usdt trades
|
// get valid usdt trades
|
||||||
let usdt_trades = select_record(&fetch_table_name, &column_name, &condition, &usdt_trades).await?;
|
let usdt_trades =
|
||||||
|
select_record(&fetch_table_name, &column_name, &condition, &usdt_trades).await?;
|
||||||
|
|
||||||
// update valid usdt trades
|
// update valid usdt trades
|
||||||
let table_name = String::from("valid_usdt_trades");
|
let table_name = String::from("valid_usdt_trades");
|
||||||
|
|
@ -87,14 +91,18 @@ pub async fn collect_valid_usde_trade(
|
||||||
#[derive(Debug, FromRow)]
|
#[derive(Debug, FromRow)]
|
||||||
struct UsdtTrades {
|
struct UsdtTrades {
|
||||||
symbol: String,
|
symbol: String,
|
||||||
weightedavgprice: f64
|
weightedavgprice: f64,
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut usdt_trades = UsdtTrades { symbol: String::new(), weightedavgprice:0.0 };
|
let mut usdt_trades = UsdtTrades {
|
||||||
|
symbol: String::new(),
|
||||||
|
weightedavgprice: 0.0,
|
||||||
|
};
|
||||||
|
|
||||||
let fetch_table_name = String::from("all_24h_change");
|
let fetch_table_name = String::from("all_24h_change");
|
||||||
let column_name = String::from("symbol, weightedAvgPrice");
|
let column_name = String::from("symbol, weightedAvgPrice");
|
||||||
let mut condition_build = String::from("WHERE symbol LIKE '%USDT' AND symbol NOT LIKE '%DOWNUSDT'");
|
let mut condition_build =
|
||||||
|
String::from("WHERE symbol LIKE '%USDT' AND symbol NOT LIKE '%DOWNUSDT'");
|
||||||
condition_build.push_str(" AND symbol NOT LIKE '%UPUSDT' AND firstId >= 0 AND lastId >= 0");
|
condition_build.push_str(" AND symbol NOT LIKE '%UPUSDT' AND firstId >= 0 AND lastId >= 0");
|
||||||
condition_build.push_str(" AND bidPrice > 0");
|
condition_build.push_str(" AND bidPrice > 0");
|
||||||
condition_build.push_str(" AND bidQty > 0");
|
condition_build.push_str(" AND bidQty > 0");
|
||||||
|
|
@ -122,11 +130,12 @@ pub async fn collect_valid_usde_trade(
|
||||||
condition_build.push_str(" AND symbol NOT LIKE 'BTCSTUSDT'");
|
condition_build.push_str(" AND symbol NOT LIKE 'BTCSTUSDT'");
|
||||||
condition_build.push_str(" AND symbol NOT LIKE 'ACAUSDT'");
|
condition_build.push_str(" AND symbol NOT LIKE 'ACAUSDT'");
|
||||||
condition_build.push_str(" AND symbol NOT LIKE 'ANCUSDT'");
|
condition_build.push_str(" AND symbol NOT LIKE 'ANCUSDT'");
|
||||||
|
|
||||||
let condition = Some(condition_build);
|
let condition = Some(condition_build);
|
||||||
|
|
||||||
// get valid usdt trades
|
// get valid usdt trades
|
||||||
let usdt_trades = select_record(&fetch_table_name, &column_name, &condition, &usdt_trades).await?;
|
let usdt_trades =
|
||||||
|
select_record(&fetch_table_name, &column_name, &condition, &usdt_trades).await?;
|
||||||
|
|
||||||
// filtering usdt trades
|
// filtering usdt trades
|
||||||
let mut filtered_usdt_trades: Vec<String> = Vec::new();
|
let mut filtered_usdt_trades: Vec<String> = Vec::new();
|
||||||
|
|
@ -136,13 +145,15 @@ pub async fn collect_valid_usde_trade(
|
||||||
let step_size_result = exchange_info_vec
|
let step_size_result = exchange_info_vec
|
||||||
.iter()
|
.iter()
|
||||||
.position(|ExchangeInfo| ExchangeInfo.symbol == usdt_trade.symbol);
|
.position(|ExchangeInfo| ExchangeInfo.symbol == usdt_trade.symbol);
|
||||||
|
|
||||||
if step_size_result.is_some() {
|
if step_size_result.is_some() {
|
||||||
let avg_price: Decimal = rust_decimal::prelude::FromPrimitive::from_f64(usdt_trade.weightedavgprice).unwrap();
|
let avg_price: Decimal =
|
||||||
|
rust_decimal::prelude::FromPrimitive::from_f64(usdt_trade.weightedavgprice)
|
||||||
|
.unwrap();
|
||||||
let step_size = exchange_info_vec[step_size_result.unwrap()].stepsize;
|
let step_size = exchange_info_vec[step_size_result.unwrap()].stepsize;
|
||||||
let step_price = decimal_mul(step_size, avg_price);
|
let step_price = decimal_mul(step_size, avg_price);
|
||||||
let unit_trade_usdt = crate::coex::assets_managing_team::get_unit_trade_usdt().await;
|
let unit_trade_usdt = crate::coex::assets_managing_team::get_unit_trade_usdt().await;
|
||||||
|
|
||||||
// exclude USDT trades whose step_price is over than 1% of unit_trade_usdt
|
// exclude USDT trades whose step_price is over than 1% of unit_trade_usdt
|
||||||
if step_price > decimal_mul(unit_trade_usdt, dec!(0.01)) {
|
if step_price > decimal_mul(unit_trade_usdt, dec!(0.01)) {
|
||||||
excluded_usdt_trades.push(usdt_trade.symbol.clone());
|
excluded_usdt_trades.push(usdt_trade.symbol.clone());
|
||||||
|
|
@ -151,7 +162,7 @@ pub async fn collect_valid_usde_trade(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// update valid usdt trades
|
// update valid usdt trades
|
||||||
let table_name = String::from("valid_usdt_trades");
|
let table_name = String::from("valid_usdt_trades");
|
||||||
let columns = vec!["symbol"];
|
let columns = vec!["symbol"];
|
||||||
|
|
@ -164,7 +175,7 @@ pub async fn collect_valid_usde_trade(
|
||||||
*valid_usdt_trade_vec = filtered_usdt_trades;
|
*valid_usdt_trade_vec = filtered_usdt_trades;
|
||||||
delete_all_rows(&table_name).await?;
|
delete_all_rows(&table_name).await?;
|
||||||
insert_records(&table_name, &columns, &value_wrapper).await?;
|
insert_records(&table_name, &columns, &value_wrapper).await?;
|
||||||
|
|
||||||
// update stop usdt trades
|
// update stop usdt trades
|
||||||
let table_name = String::from("stop_usdt_trades");
|
let table_name = String::from("stop_usdt_trades");
|
||||||
let columns = vec!["symbol"];
|
let columns = vec!["symbol"];
|
||||||
|
|
|
||||||
|
|
@ -689,7 +689,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut conn_result = sqlx::mysql::MySqlConnection::connect(DB_URL).await;
|
let mut conn_result = sqlx::mysql::MySqlConnection::connect(DB_URL).await;
|
||||||
|
|
||||||
//retry connection until it will be done.
|
//retry connection until it will be done.
|
||||||
while conn_result.is_err() {
|
while conn_result.is_err() {
|
||||||
sleep(Duration::from_millis(200)).await;
|
sleep(Duration::from_millis(200)).await;
|
||||||
|
|
@ -700,7 +700,7 @@ where
|
||||||
// let mut query_result: Vec<T> = sqlx::query_as::<_, T>(&query).fetch_all(&mut conn).await?;
|
// let mut query_result: Vec<T> = sqlx::query_as::<_, T>(&query).fetch_all(&mut conn).await?;
|
||||||
let mut query_result = sqlx::query_as::<_, T>(&query).fetch_all(&mut conn).await;
|
let mut query_result = sqlx::query_as::<_, T>(&query).fetch_all(&mut conn).await;
|
||||||
let mut query_result_vec: Vec<T> = Vec::new();
|
let mut query_result_vec: Vec<T> = Vec::new();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
match query_result {
|
match query_result {
|
||||||
Ok(T) => {
|
Ok(T) => {
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
use crate::coex::assets_managing_team;
|
use crate::coex::assets_managing_team;
|
||||||
use crate::coex::order_team;
|
use crate::coex::order_team;
|
||||||
use crate::coex::order_team::{BuyOrderedCoinList, SellOrderedCoinList};
|
use crate::coex::order_team::{BuyOrderedCoinList, SellOrderedCoinList};
|
||||||
use crate::coin_health_check_team::*;
|
|
||||||
use crate::coin_health_check_team::request_others::ExchangeInfo;
|
use crate::coin_health_check_team::request_others::ExchangeInfo;
|
||||||
|
use crate::coin_health_check_team::*;
|
||||||
use crate::database_control::*;
|
use crate::database_control::*;
|
||||||
use crate::time_checking_team::{UserTime, *};
|
use crate::time_checking_team::{UserTime, *};
|
||||||
use crate::RunningMode::*;
|
use crate::RunningMode::*;
|
||||||
|
|
@ -15,7 +15,6 @@ use sqlx::FromRow;
|
||||||
use std::{io, io::Write, path::Path, process::Stdio};
|
use std::{io, io::Write, path::Path, process::Stdio};
|
||||||
use tokio::{fs::*, io::ErrorKind, process::Command, task::JoinHandle, time::*};
|
use tokio::{fs::*, io::ErrorKind, process::Command, task::JoinHandle, time::*};
|
||||||
|
|
||||||
|
|
||||||
const STRATEGIST_NUMBER: u32 = 16;
|
const STRATEGIST_NUMBER: u32 = 16;
|
||||||
|
|
||||||
pub async fn initialization() {
|
pub async fn initialization() {
|
||||||
|
|
@ -240,8 +239,8 @@ async fn initialize_database() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delete_all_rows(&table_name)
|
delete_all_rows(&table_name)
|
||||||
.await
|
.await
|
||||||
.expect("Failed to delete rows!");
|
.expect("Failed to delete rows!");
|
||||||
println!("Ok");
|
println!("Ok");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -270,8 +269,8 @@ async fn initialize_database() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delete_all_rows(&table_name)
|
delete_all_rows(&table_name)
|
||||||
.await
|
.await
|
||||||
.expect("Failed to delete rows!");
|
.expect("Failed to delete rows!");
|
||||||
|
|
||||||
monitors::initialize_valid_usde_trade().await;
|
monitors::initialize_valid_usde_trade().await;
|
||||||
println!("Ok");
|
println!("Ok");
|
||||||
|
|
@ -983,7 +982,7 @@ async fn initialize_database() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if RUNNING_MODE == SIMUL {
|
if RUNNING_MODE == SIMUL {
|
||||||
assets_managing_team::add_extra_usdt(dec!(2200.0)).await;
|
assets_managing_team::add_extra_usdt(dec!(10000000000.0)).await;
|
||||||
assets_managing_team::update_current_total_usdt().await;
|
assets_managing_team::update_current_total_usdt().await;
|
||||||
} else {
|
} else {
|
||||||
let mut table_name = String::new();
|
let mut table_name = String::new();
|
||||||
|
|
@ -1428,7 +1427,7 @@ async fn initialize_database() {
|
||||||
sleep(Duration::from_millis(10)).await;
|
sleep(Duration::from_millis(10)).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// else {
|
// else {
|
||||||
// delete_all_rows(&table_name)
|
// delete_all_rows(&table_name)
|
||||||
// .await
|
// .await
|
||||||
|
|
|
||||||
|
|
@ -28,9 +28,9 @@ pub mod coex;
|
||||||
pub mod coin_health_check_team;
|
pub mod coin_health_check_team;
|
||||||
pub mod database_control;
|
pub mod database_control;
|
||||||
pub mod decimal_funcs;
|
pub mod decimal_funcs;
|
||||||
|
pub mod initialization;
|
||||||
pub mod server_health_check_team;
|
pub mod server_health_check_team;
|
||||||
pub mod signal_association;
|
pub mod signal_association;
|
||||||
|
pub mod strategy_team;
|
||||||
pub mod time_checking_team;
|
pub mod time_checking_team;
|
||||||
pub mod value_estimation_team;
|
pub mod value_estimation_team;
|
||||||
pub mod strategy_team;
|
|
||||||
pub mod initialization;
|
|
||||||
|
|
|
||||||
73
src/main.rs
73
src/main.rs
|
|
@ -1,11 +1,11 @@
|
||||||
#![allow(unused)]
|
#![allow(unused)]
|
||||||
#![allow(warnings)]
|
#![allow(warnings)]
|
||||||
|
|
||||||
use crate::strategy_team::AllData;
|
|
||||||
use crate::coin_health_check_team::*;
|
use crate::coin_health_check_team::*;
|
||||||
use crate::request_candles::CandleData;
|
use crate::request_candles::CandleData;
|
||||||
use crate::request_others::{CoinPriceData, ExchangeInfo, TradeFee};
|
use crate::request_others::{CoinPriceData, ExchangeInfo, TradeFee};
|
||||||
use crate::server_health_check_team::ServerHealth;
|
use crate::server_health_check_team::ServerHealth;
|
||||||
|
use crate::strategy_team::AllData;
|
||||||
use crate::time_checking_team::UserTime;
|
use crate::time_checking_team::UserTime;
|
||||||
use crate::value_estimation_team::datapoints::price_data::RealtimePriceData;
|
use crate::value_estimation_team::datapoints::price_data::RealtimePriceData;
|
||||||
use reqwest::{Client, ClientBuilder};
|
use reqwest::{Client, ClientBuilder};
|
||||||
|
|
@ -204,7 +204,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
println!("*** REAL MODE ***");
|
println!("*** REAL MODE ***");
|
||||||
} else if RUNNING_MODE == RunningMode::TEST {
|
} else if RUNNING_MODE == RunningMode::TEST {
|
||||||
println!("*** TEST MODE ***");
|
println!("*** TEST MODE ***");
|
||||||
} else if RUNNING_MODE == RunningMode::SIMUL {
|
} else if RUNNING_MODE == RunningMode::SIMUL {
|
||||||
println!("*** SIMULATION MODE ***");
|
println!("*** SIMULATION MODE ***");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -238,7 +238,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
if RUNNING_MODE == REAL || RUNNING_MODE == SIMUL {
|
if RUNNING_MODE == REAL || RUNNING_MODE == SIMUL {
|
||||||
let mut elapsed_time = instant.elapsed().as_secs();
|
let mut elapsed_time = instant.elapsed().as_secs();
|
||||||
let mut remaining_time: u64 = 60 - elapsed_time;
|
let mut remaining_time: u64 = 60 - elapsed_time;
|
||||||
|
|
||||||
while remaining_time > 0 && 60 > remaining_time {
|
while remaining_time > 0 && 60 > remaining_time {
|
||||||
print!("\rstart tradingbot in {} seconds", remaining_time);
|
print!("\rstart tradingbot in {} seconds", remaining_time);
|
||||||
io::stdout().flush();
|
io::stdout().flush();
|
||||||
|
|
@ -503,7 +503,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Ok(T) => {
|
Ok(T) => {
|
||||||
tx_tradefee_vec.send_modify(|vec| *vec = tradefee_vec_temp);
|
tx_tradefee_vec.send_modify(|vec| *vec = tradefee_vec_temp);
|
||||||
|
|
@ -552,13 +552,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Ok(T) => {
|
Ok(T) => {
|
||||||
tx_exchange_info_data.send_modify(|vec| *vec = exchange_info_data_temp);
|
tx_exchange_info_data.send_modify(|vec| *vec = exchange_info_data_temp);
|
||||||
tx_task3
|
tx_task3.send(3).expect("The mpsc channel has been closed.");
|
||||||
.send(3)
|
|
||||||
.expect("The mpsc channel has been closed.");
|
|
||||||
}
|
}
|
||||||
Err(E) => {}
|
Err(E) => {}
|
||||||
}
|
}
|
||||||
|
|
@ -566,11 +564,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Task#4: request 24h price changes,
|
// Task#4: request 24h price changes,
|
||||||
// pick valid USDT Trades,
|
// pick valid USDT Trades,
|
||||||
// filtering stop USDT Trades,
|
// filtering stop USDT Trades,
|
||||||
// monitor total_24h_change_profit_index,
|
// monitor total_24h_change_profit_index,
|
||||||
// usdt_24h_change_profit_index,
|
// usdt_24h_change_profit_index,
|
||||||
// total_price_down_dist_index
|
// total_price_down_dist_index
|
||||||
tokio::task::spawn(async move {
|
tokio::task::spawn(async move {
|
||||||
sleep(Duration::from_secs(10)).await;
|
sleep(Duration::from_secs(10)).await;
|
||||||
|
|
@ -586,8 +584,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
Ok(T) => {
|
Ok(T) => {
|
||||||
let exchange_info_vec = rx5_exchange_info_data.borrow().clone();
|
let exchange_info_vec = rx5_exchange_info_data.borrow().clone();
|
||||||
let mut valid_usdt_trade_vec_temp: Vec<String> = Vec::new();
|
let mut valid_usdt_trade_vec_temp: Vec<String> = Vec::new();
|
||||||
let result =
|
let result = monitors::collect_valid_usde_trade(
|
||||||
monitors::collect_valid_usde_trade(&mut valid_usdt_trade_vec_temp, &exchange_info_vec).await;
|
&mut valid_usdt_trade_vec_temp,
|
||||||
|
&exchange_info_vec,
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Ok(T) => {
|
Ok(T) => {
|
||||||
|
|
@ -716,7 +717,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
if tx_rt_price_30m_vec.is_closed() {
|
if tx_rt_price_30m_vec.is_closed() {
|
||||||
eprintln!("tx_rt_price_30m_vec has been closed!");
|
eprintln!("tx_rt_price_30m_vec has been closed!");
|
||||||
} else {
|
} else {
|
||||||
tx_rt_price_30m_vec.send_modify(|vec| *vec = rt_price_30m_vec_write_temp);
|
tx_rt_price_30m_vec
|
||||||
|
.send_modify(|vec| *vec = rt_price_30m_vec_write_temp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(E) => {}
|
Err(E) => {}
|
||||||
|
|
@ -813,7 +815,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
|
||||||
// sleep as much as the loop recurs per 10 seconds, expecting child threads will have finished within 10 seconds.
|
// sleep as much as the loop recurs per 10 seconds, expecting child threads will have finished within 10 seconds.
|
||||||
elapsed_time = instant.elapsed().as_millis();
|
elapsed_time = instant.elapsed().as_millis();
|
||||||
if 30_000 > elapsed_time { // 10_000 for major trade
|
if 30_000 > elapsed_time {
|
||||||
|
// 10_000 for major trade
|
||||||
sleep(Duration::from_millis((30_000 - elapsed_time) as u64)).await;
|
sleep(Duration::from_millis((30_000 - elapsed_time) as u64)).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -827,8 +830,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let instant = Instant::now();
|
let instant = Instant::now();
|
||||||
let mut candle_30m_vec_temp: Vec<(String, Vec<CandleData>)> = Vec::new();
|
let mut candle_30m_vec_temp: Vec<(String, Vec<CandleData>)> = Vec::new();
|
||||||
let result =
|
let result =
|
||||||
|
request_candles::fetch_candle_delay(&interval, &mut candle_30m_vec_temp).await;
|
||||||
request_candles::fetch_candle_delay(&interval, &mut candle_30m_vec_temp).await;
|
|
||||||
// request_candles::fetch_candle_parallel(&interval, &mut candle_30m_vec_temp).await;
|
// request_candles::fetch_candle_parallel(&interval, &mut candle_30m_vec_temp).await;
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
|
|
@ -840,7 +842,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
}
|
}
|
||||||
// sleep as much as the loop recurs per 60 seconds, expecting child threads will have finished within 60 seconds.
|
// sleep as much as the loop recurs per 60 seconds, expecting child threads will have finished within 60 seconds.
|
||||||
elapsed_time = instant.elapsed().as_millis();
|
elapsed_time = instant.elapsed().as_millis();
|
||||||
if 60_000 > elapsed_time { //60_000
|
if 60_000 > elapsed_time {
|
||||||
|
//60_000
|
||||||
sleep(Duration::from_millis((60_000 - elapsed_time) as u64)).await;
|
sleep(Duration::from_millis((60_000 - elapsed_time) as u64)).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1015,7 +1018,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
all_data.rt_price_1w_vec = rx3_rt_price_1w_vec.borrow().clone();
|
all_data.rt_price_1w_vec = rx3_rt_price_1w_vec.borrow().clone();
|
||||||
all_data.rt_price_1mon_vec = rx3_rt_price_1mon_vec.borrow().clone();
|
all_data.rt_price_1mon_vec = rx3_rt_price_1mon_vec.borrow().clone();
|
||||||
|
|
||||||
let result = strategy_team::strategy_manager::execute_list_up_for_buy(&all_data).await;
|
let result =
|
||||||
|
strategy_team::strategy_manager::execute_list_up_for_buy(&all_data).await;
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Ok(T) => {
|
Ok(T) => {
|
||||||
|
|
@ -1090,7 +1094,12 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
all_data.rt_price_1w_vec = rx4_rt_price_1w_vec.borrow().clone();
|
all_data.rt_price_1w_vec = rx4_rt_price_1w_vec.borrow().clone();
|
||||||
all_data.rt_price_1mon_vec = rx4_rt_price_1mon_vec.borrow().clone();
|
all_data.rt_price_1mon_vec = rx4_rt_price_1mon_vec.borrow().clone();
|
||||||
|
|
||||||
let result = strategy_team::strategy_manager::execute_list_up_for_sell(&all_data, &exchange_info_vec, &trade_fee_vec).await;
|
let result = strategy_team::strategy_manager::execute_list_up_for_sell(
|
||||||
|
&all_data,
|
||||||
|
&exchange_info_vec,
|
||||||
|
&trade_fee_vec,
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Ok(T) => {
|
Ok(T) => {
|
||||||
|
|
@ -1110,7 +1119,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Task#18: monitoring pre-suggested coins
|
// Task#18: monitoring pre-suggested coins
|
||||||
tokio::task::spawn(async move {
|
tokio::task::spawn(async move {
|
||||||
|
|
@ -1143,17 +1152,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
if RUNNING_MODE == REAL || RUNNING_MODE == SIMUL || RUNNING_MODE == TEST {
|
if RUNNING_MODE == REAL || RUNNING_MODE == SIMUL || RUNNING_MODE == TEST {
|
||||||
tokio::task::spawn(async move {
|
tokio::task::spawn(async move {
|
||||||
sleep(Duration::from_secs(30)).await;
|
sleep(Duration::from_secs(30)).await;
|
||||||
|
|
||||||
let mut elapsed_time = 0;
|
let mut elapsed_time = 0;
|
||||||
loop {
|
loop {
|
||||||
let instant = Instant::now();
|
let instant = Instant::now();
|
||||||
let exchange_info_vec = rx_exchange_info_data.borrow().clone();
|
let exchange_info_vec = rx_exchange_info_data.borrow().clone();
|
||||||
let trade_fee_vec = rx_tradefee_vec.borrow().clone();
|
let trade_fee_vec = rx_tradefee_vec.borrow().clone();
|
||||||
let result = coex::exchange_team::buy_coin(
|
let result =
|
||||||
&exchange_info_vec,
|
coex::exchange_team::buy_coin(&exchange_info_vec, &trade_fee_vec).await;
|
||||||
&trade_fee_vec,
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
|
|
||||||
// send Task#0 a message to notify running on
|
// send Task#0 a message to notify running on
|
||||||
match result {
|
match result {
|
||||||
|
|
@ -1183,11 +1189,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let exchange_info_vec = rx_exchange_info_data.borrow().clone();
|
let exchange_info_vec = rx_exchange_info_data.borrow().clone();
|
||||||
let trade_fee_vec = rx_tradefee_vec.borrow().clone();
|
let trade_fee_vec = rx_tradefee_vec.borrow().clone();
|
||||||
// let result = coex::exchange_team::buy_coin_for_test(&client, &coin_price_vec, &exchange_info_vec, &trade_fee_vec).await;
|
// let result = coex::exchange_team::buy_coin_for_test(&client, &coin_price_vec, &exchange_info_vec, &trade_fee_vec).await;
|
||||||
let result = coex::exchange_team::buy_coin(
|
let result = coex::exchange_team::buy_coin(&exchange_info_vec, &trade_fee_vec).await;
|
||||||
&exchange_info_vec,
|
|
||||||
&trade_fee_vec,
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
|
|
||||||
// send Task#0 a message to notify running on
|
// send Task#0 a message to notify running on
|
||||||
match result {
|
match result {
|
||||||
|
|
@ -1431,8 +1433,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let mut elapsed_time = 0;
|
let mut elapsed_time = 0;
|
||||||
loop {
|
loop {
|
||||||
let instant = Instant::now();
|
let instant = Instant::now();
|
||||||
let result =
|
let result = coex::assets_managing_team::update_kelly_criterion().await;
|
||||||
coex::assets_managing_team::update_kelly_criterion().await;
|
|
||||||
|
|
||||||
// send Task#0 a message to notify running on
|
// send Task#0 a message to notify running on
|
||||||
match result {
|
match result {
|
||||||
|
|
|
||||||
|
|
@ -40,14 +40,11 @@ pub async fn market_cap_index() -> Result<(), Box<dyn std::error::Error + Send +
|
||||||
|
|
||||||
// JSON Parsing
|
// JSON Parsing
|
||||||
let mut v: Value = serde_json::from_str(text.as_str()).unwrap();
|
let mut v: Value = serde_json::from_str(text.as_str()).unwrap();
|
||||||
|
|
||||||
if v
|
if v.as_object().unwrap().get("data").is_none() {
|
||||||
.as_object()
|
|
||||||
.unwrap()
|
|
||||||
.get("data").is_none() {
|
|
||||||
return Err("Err")?;
|
return Err("Err")?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut into_vec = v
|
let mut into_vec = v
|
||||||
.as_object()
|
.as_object()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
|
||||||
|
|
@ -1,31 +1,31 @@
|
||||||
pub mod strategy_manager;
|
|
||||||
pub mod strategy_001;
|
pub mod strategy_001;
|
||||||
pub mod strategy_002;
|
pub mod strategy_002;
|
||||||
pub mod strategy_003;
|
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_manager;
|
||||||
|
|
||||||
use std::{sync::Arc};
|
use crate::coex::order_team::{limit_order_sell, select_filled_buy_orders};
|
||||||
|
use crate::coin_health_check_team::request_others::{ExchangeInfo, TradeFee};
|
||||||
use crate::database_control::*;
|
use crate::database_control::*;
|
||||||
use crate::value_estimation_team::datapoints::price_data::RealtimePriceData;
|
use crate::value_estimation_team::datapoints::price_data::RealtimePriceData;
|
||||||
use crate::value_estimation_team::indicators::macd::{ema_macd, EmaMacd};
|
|
||||||
use crate::value_estimation_team::indicators::rsi::{rsi, RsiData};
|
|
||||||
use crate::value_estimation_team::indicators::sma::{sma, SmaData};
|
|
||||||
use crate::value_estimation_team::indicators::ema::{ema, EmaData};
|
|
||||||
use crate::value_estimation_team::indicators::bollingerband::{bollingerband, BollingerBandData};
|
use crate::value_estimation_team::indicators::bollingerband::{bollingerband, BollingerBandData};
|
||||||
use crate::value_estimation_team::indicators::stoch_rsi::{stoch_rsi, StochRsiData};
|
use crate::value_estimation_team::indicators::ema::{ema, EmaData};
|
||||||
use crate::value_estimation_team::indicators::supertrend::{supertrend, SupertrendData};
|
|
||||||
use crate::value_estimation_team::indicators::heatmap_volume::{
|
use crate::value_estimation_team::indicators::heatmap_volume::{
|
||||||
heatmap_volume, HeatMapLevel, HeatmapVolumeData,
|
heatmap_volume, HeatMapLevel, HeatmapVolumeData,
|
||||||
};
|
};
|
||||||
use crate::coex::order_team::{limit_order_sell, select_filled_buy_orders};
|
use crate::value_estimation_team::indicators::macd::{ema_macd, EmaMacd};
|
||||||
use crate::coin_health_check_team::request_others::{ExchangeInfo, TradeFee};
|
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 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};
|
||||||
use rust_decimal_macros::dec;
|
use rust_decimal_macros::dec;
|
||||||
use sqlx::FromRow;
|
use sqlx::FromRow;
|
||||||
|
use std::sync::Arc;
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@
|
||||||
// let valid_symbol_vec_c = alldata.valid_symbol_vec.clone();
|
// let valid_symbol_vec_c = alldata.valid_symbol_vec.clone();
|
||||||
// for symbol in valid_symbol_vec_c {
|
// for symbol in valid_symbol_vec_c {
|
||||||
// let mut opclo_30m_vec: Vec<RealtimePriceData> = Vec::new();
|
// let mut opclo_30m_vec: Vec<RealtimePriceData> = Vec::new();
|
||||||
|
|
||||||
// let rt_price_30m_vec_c = alldata.rt_price_30m_vec.clone();
|
// let rt_price_30m_vec_c = alldata.rt_price_30m_vec.clone();
|
||||||
// let filtered_2nd_symbols_arc_c = Arc::clone(&filtered_2nd_symbols_arc);
|
// let filtered_2nd_symbols_arc_c = Arc::clone(&filtered_2nd_symbols_arc);
|
||||||
// task_vec.push(tokio::spawn(async move {
|
// task_vec.push(tokio::spawn(async move {
|
||||||
|
|
@ -200,13 +200,13 @@
|
||||||
// let rt_price_30m_option = alldata.rt_price_30m_vec.iter().position(|x| *x.0 == element.0);
|
// let rt_price_30m_option = alldata.rt_price_30m_vec.iter().position(|x| *x.0 == element.0);
|
||||||
// let element_c = element.clone();
|
// let element_c = element.clone();
|
||||||
// let filtered_5th_symbols_arc_c = Arc::clone(&filtered_5th_symbols_arc);
|
// let filtered_5th_symbols_arc_c = Arc::clone(&filtered_5th_symbols_arc);
|
||||||
|
|
||||||
// if rt_price_30m_option.is_some() {
|
// if rt_price_30m_option.is_some() {
|
||||||
// let mut rt_price_30m_vec_c = alldata.rt_price_30m_vec[rt_price_30m_option.unwrap()].1.clone();
|
// let mut rt_price_30m_vec_c = alldata.rt_price_30m_vec[rt_price_30m_option.unwrap()].1.clone();
|
||||||
// let current_price = get_current_price(&element_c.0, &alldata.rt_price_30m_vec)
|
// let current_price = get_current_price(&element_c.0, &alldata.rt_price_30m_vec)
|
||||||
// .await
|
// .await
|
||||||
// .unwrap();
|
// .unwrap();
|
||||||
|
|
||||||
// task_vec.push(tokio::spawn(async move {
|
// task_vec.push(tokio::spawn(async move {
|
||||||
// if rt_price_30m_vec_c.len() >= 21 {
|
// if rt_price_30m_vec_c.len() >= 21 {
|
||||||
// rt_price_30m_vec_c.pop();
|
// rt_price_30m_vec_c.pop();
|
||||||
|
|
@ -314,7 +314,7 @@
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// // 7th filtering: heatmap volume(MA length 10, std length 10, 30m close price), the current candle should be over than high at least.
|
// // 7th filtering: heatmap volume(MA length 10, std length 10, 30m close price), the current candle should be over than high at least.
|
||||||
// let mut filtered_8th_symbols: Vec<(String, i64)> = Vec::new(); // (symbol, closetime)
|
// let mut filtered_8th_symbols: Vec<(String, i64)> = Vec::new(); // (symbol, closetime)
|
||||||
// for element in filtered_7th_symbols {
|
// for element in filtered_7th_symbols {
|
||||||
|
|
@ -340,7 +340,7 @@
|
||||||
// if heatmap_search_result.is_ok() {
|
// if heatmap_search_result.is_ok() {
|
||||||
// if heatmap_volume_vec[heatmap_search_result.unwrap()].heatmap_level
|
// if heatmap_volume_vec[heatmap_search_result.unwrap()].heatmap_level
|
||||||
// == HeatMapLevel::Medium
|
// == HeatMapLevel::Medium
|
||||||
// ||
|
// ||
|
||||||
// heatmap_volume_vec[heatmap_search_result.unwrap()].heatmap_level
|
// heatmap_volume_vec[heatmap_search_result.unwrap()].heatmap_level
|
||||||
// == HeatMapLevel::High
|
// == HeatMapLevel::High
|
||||||
// || heatmap_volume_vec[heatmap_search_result.unwrap()].heatmap_level
|
// || heatmap_volume_vec[heatmap_search_result.unwrap()].heatmap_level
|
||||||
|
|
@ -421,4 +421,4 @@
|
||||||
// insert_pre_suggested_coins(1, false, &a, alldata).await;
|
// insert_pre_suggested_coins(1, false, &a, alldata).await;
|
||||||
|
|
||||||
// Ok(())
|
// Ok(())
|
||||||
// }
|
// }
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@
|
||||||
// let valid_symbol_vec_c = alldata.valid_symbol_vec.clone();
|
// let valid_symbol_vec_c = alldata.valid_symbol_vec.clone();
|
||||||
// for symbol in valid_symbol_vec_c {
|
// for symbol in valid_symbol_vec_c {
|
||||||
// let mut opclo_30m_vec: Vec<RealtimePriceData> = Vec::new();
|
// let mut opclo_30m_vec: Vec<RealtimePriceData> = Vec::new();
|
||||||
|
|
||||||
// let rt_price_30m_vec_c = alldata.rt_price_30m_vec.clone();
|
// let rt_price_30m_vec_c = alldata.rt_price_30m_vec.clone();
|
||||||
// let filtered_2nd_symbols_arc_c = Arc::clone(&filtered_2nd_symbols_arc);
|
// let filtered_2nd_symbols_arc_c = Arc::clone(&filtered_2nd_symbols_arc);
|
||||||
// task_vec.push(tokio::spawn(async move {
|
// task_vec.push(tokio::spawn(async move {
|
||||||
|
|
@ -139,7 +139,7 @@
|
||||||
// if ema30_search_result.is_ok() && ema150_search_result.is_ok() {
|
// if ema30_search_result.is_ok() && ema150_search_result.is_ok() {
|
||||||
// if ema30_30m_vec_c[ema30_search_result.unwrap()-3].ema_value > ema150_30m_vec_c[ema150_search_result.unwrap()-3].ema_value &&
|
// if ema30_30m_vec_c[ema30_search_result.unwrap()-3].ema_value > ema150_30m_vec_c[ema150_search_result.unwrap()-3].ema_value &&
|
||||||
// ema30_30m_vec_c[ema30_search_result.unwrap()-2].ema_value > ema150_30m_vec_c[ema150_search_result.unwrap()-2].ema_value &&
|
// ema30_30m_vec_c[ema30_search_result.unwrap()-2].ema_value > ema150_30m_vec_c[ema150_search_result.unwrap()-2].ema_value &&
|
||||||
// ema30_30m_vec_c[ema30_search_result.unwrap()-1].ema_value > ema150_30m_vec_c[ema150_search_result.unwrap()-1].ema_value &&
|
// ema30_30m_vec_c[ema30_search_result.unwrap()-1].ema_value > ema150_30m_vec_c[ema150_search_result.unwrap()-1].ema_value &&
|
||||||
// ema30_30m_vec_c[ema30_search_result.unwrap()].ema_value > ema150_30m_vec_c[ema150_search_result.unwrap()].ema_value &&
|
// ema30_30m_vec_c[ema30_search_result.unwrap()].ema_value > ema150_30m_vec_c[ema150_search_result.unwrap()].ema_value &&
|
||||||
// ema30_30m_vec_c[ema30_search_result.unwrap()].ema_value > ema30_30m_vec_c[ema30_search_result.unwrap()-1].ema_value &&
|
// ema30_30m_vec_c[ema30_search_result.unwrap()].ema_value > ema30_30m_vec_c[ema30_search_result.unwrap()-1].ema_value &&
|
||||||
// ema30_30m_vec_c[ema30_search_result.unwrap()-1].ema_value > ema30_30m_vec_c[ema30_search_result.unwrap()-2].ema_value &&
|
// ema30_30m_vec_c[ema30_search_result.unwrap()-1].ema_value > ema30_30m_vec_c[ema30_search_result.unwrap()-2].ema_value &&
|
||||||
|
|
@ -183,7 +183,7 @@
|
||||||
// }| close_time,
|
// }| close_time,
|
||||||
// );
|
// );
|
||||||
// if stoch_rsi_search_result.is_ok() {
|
// if stoch_rsi_search_result.is_ok() {
|
||||||
// if stoch_rsi10_30m_vec[stoch_rsi_search_result.unwrap()].k <= 5.0 &&
|
// if stoch_rsi10_30m_vec[stoch_rsi_search_result.unwrap()].k <= 5.0 &&
|
||||||
// stoch_rsi10_30m_vec[stoch_rsi_search_result.unwrap()].d <= 5.0 &&
|
// stoch_rsi10_30m_vec[stoch_rsi_search_result.unwrap()].d <= 5.0 &&
|
||||||
// stoch_rsi10_30m_vec[stoch_rsi_search_result.unwrap()-1].k <= 5.0 {
|
// stoch_rsi10_30m_vec[stoch_rsi_search_result.unwrap()-1].k <= 5.0 {
|
||||||
// filtered_5th_symbols.push(element);
|
// filtered_5th_symbols.push(element);
|
||||||
|
|
@ -192,7 +192,7 @@
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// // 7th filtering: heatmap volume(MA length 10, std length 10, 30m close price), the current candle should be over than high at least.
|
// // 7th filtering: heatmap volume(MA length 10, std length 10, 30m close price), the current candle should be over than high at least.
|
||||||
// let mut filtered_6th_symbols: Vec<(String, i64)> = Vec::new(); // (symbol, closetime)
|
// let mut filtered_6th_symbols: Vec<(String, i64)> = Vec::new(); // (symbol, closetime)
|
||||||
// for element in filtered_5th_symbols {
|
// for element in filtered_5th_symbols {
|
||||||
|
|
@ -216,10 +216,10 @@
|
||||||
// }| *close_time,
|
// }| *close_time,
|
||||||
// );
|
// );
|
||||||
// if heatmap_search_result.is_ok() {
|
// if heatmap_search_result.is_ok() {
|
||||||
// if
|
// if
|
||||||
// // heatmap_volume_vec[heatmap_search_result.unwrap()].heatmap_level
|
// // heatmap_volume_vec[heatmap_search_result.unwrap()].heatmap_level
|
||||||
// // == HeatMapLevel::Medium
|
// // == HeatMapLevel::Medium
|
||||||
// // ||
|
// // ||
|
||||||
// heatmap_volume_vec[heatmap_search_result.unwrap()].heatmap_level
|
// heatmap_volume_vec[heatmap_search_result.unwrap()].heatmap_level
|
||||||
// == HeatMapLevel::High
|
// == HeatMapLevel::High
|
||||||
// || heatmap_volume_vec[heatmap_search_result.unwrap()].heatmap_level
|
// || heatmap_volume_vec[heatmap_search_result.unwrap()].heatmap_level
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,8 @@
|
||||||
use super::{limit_order_sell, AllData, RealtimePriceData, Mutex, Arc, try_join_all, exists_record, StochRsiData, EmaData, SupertrendData, RsiData, stoch_rsi, ema, rsi, supertrend, select_filled_buy_orders, ExchangeInfo, TradeFee, Client, ClientBuilder, dec, RoundingStrategy};
|
use super::{
|
||||||
|
dec, ema, exists_record, limit_order_sell, rsi, select_filled_buy_orders, stoch_rsi,
|
||||||
|
supertrend, try_join_all, AllData, Arc, Client, ClientBuilder, EmaData, ExchangeInfo, Mutex,
|
||||||
|
RealtimePriceData, RoundingStrategy, RsiData, StochRsiData, SupertrendData, TradeFee,
|
||||||
|
};
|
||||||
|
|
||||||
pub async fn list_up_for_buy(
|
pub async fn list_up_for_buy(
|
||||||
alldata: &AllData,
|
alldata: &AllData,
|
||||||
|
|
@ -105,18 +109,10 @@ pub async fn list_up_for_buy(
|
||||||
|
|
||||||
// 3rd filtering: EMA30 > EMA 150
|
// 3rd filtering: EMA30 > EMA 150
|
||||||
let filtered_3rd_symbols_c = filtered_3rd_symbols_arc.lock().await.clone();
|
let filtered_3rd_symbols_c = filtered_3rd_symbols_arc.lock().await.clone();
|
||||||
let ema30_30m_data: Vec<(String, Vec<EmaData>)> = ema(
|
let ema30_30m_data: Vec<(String, Vec<EmaData>)> =
|
||||||
30,
|
ema(30, &alldata.rt_price_30m_vec, &filtered_3rd_symbols_c).await?;
|
||||||
&alldata.rt_price_30m_vec,
|
let ema150_30m_data: Vec<(String, Vec<EmaData>)> =
|
||||||
&filtered_3rd_symbols_c,
|
ema(150, &alldata.rt_price_30m_vec, &filtered_3rd_symbols_c).await?;
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
let ema150_30m_data: Vec<(String, Vec<EmaData>)> = ema(
|
|
||||||
150,
|
|
||||||
&alldata.rt_price_30m_vec,
|
|
||||||
&filtered_3rd_symbols_c,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
let mut task_vec = Vec::new();
|
let mut task_vec = Vec::new();
|
||||||
let mut filtered_4th_symbols: Vec<(String, i64)> = Vec::new();
|
let mut filtered_4th_symbols: Vec<(String, i64)> = Vec::new();
|
||||||
|
|
@ -144,26 +140,33 @@ pub async fn list_up_for_buy(
|
||||||
let ema30_search_result = ema30_30m_vec_c.binary_search_by_key(
|
let ema30_search_result = ema30_30m_vec_c.binary_search_by_key(
|
||||||
&element_c.1,
|
&element_c.1,
|
||||||
|&EmaData {
|
|&EmaData {
|
||||||
ema_value,
|
ema_value,
|
||||||
close_time,
|
close_time,
|
||||||
}| close_time,
|
}| close_time,
|
||||||
);
|
);
|
||||||
let ema150_search_result = ema150_30m_vec_c.binary_search_by_key(
|
let ema150_search_result = ema150_30m_vec_c.binary_search_by_key(
|
||||||
&element_c.1,
|
&element_c.1,
|
||||||
|&EmaData {
|
|&EmaData {
|
||||||
ema_value,
|
ema_value,
|
||||||
close_time,
|
close_time,
|
||||||
}| close_time,
|
}| close_time,
|
||||||
);
|
);
|
||||||
|
|
||||||
if ema30_search_result.is_ok() && ema150_search_result.is_ok() {
|
if ema30_search_result.is_ok() && ema150_search_result.is_ok() {
|
||||||
if ema30_30m_vec_c[ema30_search_result.unwrap()-3].ema_value > ema150_30m_vec_c[ema150_search_result.unwrap()-3].ema_value &&
|
if ema30_30m_vec_c[ema30_search_result.unwrap() - 3].ema_value
|
||||||
ema30_30m_vec_c[ema30_search_result.unwrap()-2].ema_value > ema150_30m_vec_c[ema150_search_result.unwrap()-2].ema_value &&
|
> ema150_30m_vec_c[ema150_search_result.unwrap() - 3].ema_value
|
||||||
ema30_30m_vec_c[ema30_search_result.unwrap()-1].ema_value > ema150_30m_vec_c[ema150_search_result.unwrap()-1].ema_value &&
|
&& ema30_30m_vec_c[ema30_search_result.unwrap() - 2].ema_value
|
||||||
ema30_30m_vec_c[ema30_search_result.unwrap()].ema_value > ema150_30m_vec_c[ema150_search_result.unwrap()].ema_value &&
|
> ema150_30m_vec_c[ema150_search_result.unwrap() - 2].ema_value
|
||||||
ema30_30m_vec_c[ema30_search_result.unwrap()].ema_value > ema30_30m_vec_c[ema30_search_result.unwrap()-1].ema_value &&
|
&& ema30_30m_vec_c[ema30_search_result.unwrap() - 1].ema_value
|
||||||
ema30_30m_vec_c[ema30_search_result.unwrap()-1].ema_value > ema30_30m_vec_c[ema30_search_result.unwrap()-2].ema_value &&
|
> ema150_30m_vec_c[ema150_search_result.unwrap() - 1].ema_value
|
||||||
ema30_30m_vec_c[ema30_search_result.unwrap()-2].ema_value > ema30_30m_vec_c[ema30_search_result.unwrap()-3].ema_value
|
&& ema30_30m_vec_c[ema30_search_result.unwrap()].ema_value
|
||||||
|
> ema150_30m_vec_c[ema150_search_result.unwrap()].ema_value
|
||||||
|
&& ema30_30m_vec_c[ema30_search_result.unwrap()].ema_value
|
||||||
|
> ema30_30m_vec_c[ema30_search_result.unwrap() - 1].ema_value
|
||||||
|
&& ema30_30m_vec_c[ema30_search_result.unwrap() - 1].ema_value
|
||||||
|
> ema30_30m_vec_c[ema30_search_result.unwrap() - 2].ema_value
|
||||||
|
&& ema30_30m_vec_c[ema30_search_result.unwrap() - 2].ema_value
|
||||||
|
> ema30_30m_vec_c[ema30_search_result.unwrap() - 3].ema_value
|
||||||
{
|
{
|
||||||
let mut filtered_4th_symbols_lock =
|
let mut filtered_4th_symbols_lock =
|
||||||
filtered_4th_symbols_arc_c.lock().await;
|
filtered_4th_symbols_arc_c.lock().await;
|
||||||
|
|
@ -176,14 +179,10 @@ pub async fn list_up_for_buy(
|
||||||
}
|
}
|
||||||
try_join_all(task_vec).await?;
|
try_join_all(task_vec).await?;
|
||||||
|
|
||||||
// 4th filtering: StochRSI (RSI length: 10, Stoch length: 10, smooth k: 3, smooth d: 3) 20 > k > kn-1 > kn-2 > kn-3,
|
// 4th filtering: StochRSI (RSI length: 10, Stoch length: 10, smooth k: 3, smooth d: 3) 20 > k > kn-1 > kn-2 > kn-3,
|
||||||
let filtered_4th_symbol_c = filtered_4th_symbols_arc.lock().await.clone();
|
let filtered_4th_symbol_c = filtered_4th_symbols_arc.lock().await.clone();
|
||||||
let mut rsi10_30m_data: Vec<(String, Vec<RsiData>)> = rsi(
|
let mut rsi10_30m_data: Vec<(String, Vec<RsiData>)> =
|
||||||
10,
|
rsi(10, &alldata.rt_price_30m_vec, &filtered_4th_symbol_c).await?;
|
||||||
&alldata.rt_price_30m_vec,
|
|
||||||
&filtered_4th_symbol_c,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
let stoch_rsi_data = stoch_rsi(&rsi10_30m_data, 10, 3, 3).await?;
|
let stoch_rsi_data = stoch_rsi(&rsi10_30m_data, 10, 3, 3).await?;
|
||||||
let mut stoch_rsi10_30m_vec: Vec<StochRsiData> = Vec::new();
|
let mut stoch_rsi10_30m_vec: Vec<StochRsiData> = Vec::new();
|
||||||
let mut filtered_5th_symbols: Vec<(String, i64)> = Vec::new(); // (symbol, closetime)
|
let mut filtered_5th_symbols: Vec<(String, i64)> = Vec::new(); // (symbol, closetime)
|
||||||
|
|
@ -194,19 +193,19 @@ pub async fn list_up_for_buy(
|
||||||
stoch_rsi10_30m_vec = stoch_rsi_data[stoch_rsi10_30m_option.unwrap()].1.clone();
|
stoch_rsi10_30m_vec = stoch_rsi_data[stoch_rsi10_30m_option.unwrap()].1.clone();
|
||||||
|
|
||||||
if stoch_rsi10_30m_vec.len() >= 3 {
|
if stoch_rsi10_30m_vec.len() >= 3 {
|
||||||
let stoch_rsi_search_result = stoch_rsi10_30m_vec.binary_search_by_key(
|
let stoch_rsi_search_result = stoch_rsi10_30m_vec
|
||||||
&element.1,
|
.binary_search_by_key(&element.1, |&StochRsiData { k, d, close_time }| {
|
||||||
|&StochRsiData {
|
close_time
|
||||||
k,
|
});
|
||||||
d,
|
|
||||||
close_time,
|
|
||||||
}| close_time,
|
|
||||||
);
|
|
||||||
if stoch_rsi_search_result.is_ok() {
|
if stoch_rsi_search_result.is_ok() {
|
||||||
if 10.0 > stoch_rsi10_30m_vec[stoch_rsi_search_result.unwrap()].k &&
|
if 10.0 > stoch_rsi10_30m_vec[stoch_rsi_search_result.unwrap()].k
|
||||||
stoch_rsi10_30m_vec[stoch_rsi_search_result.unwrap()].k > stoch_rsi10_30m_vec[stoch_rsi_search_result.unwrap()-1].k &&
|
&& stoch_rsi10_30m_vec[stoch_rsi_search_result.unwrap()].k
|
||||||
stoch_rsi10_30m_vec[stoch_rsi_search_result.unwrap()-1].k <= stoch_rsi10_30m_vec[stoch_rsi_search_result.unwrap()-2].k &&
|
> stoch_rsi10_30m_vec[stoch_rsi_search_result.unwrap() - 1].k
|
||||||
stoch_rsi10_30m_vec[stoch_rsi_search_result.unwrap()-2].k <= stoch_rsi10_30m_vec[stoch_rsi_search_result.unwrap()-3].k {
|
&& stoch_rsi10_30m_vec[stoch_rsi_search_result.unwrap() - 1].k
|
||||||
|
<= stoch_rsi10_30m_vec[stoch_rsi_search_result.unwrap() - 2].k
|
||||||
|
&& stoch_rsi10_30m_vec[stoch_rsi_search_result.unwrap() - 2].k
|
||||||
|
<= stoch_rsi10_30m_vec[stoch_rsi_search_result.unwrap() - 3].k
|
||||||
|
{
|
||||||
filtered_5th_symbols.push(element);
|
filtered_5th_symbols.push(element);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -252,7 +251,7 @@ pub async fn list_up_for_buy(
|
||||||
try_join_all(task_vec).await?;
|
try_join_all(task_vec).await?;
|
||||||
|
|
||||||
// TODO: abnormal price filtering (too high current price)
|
// TODO: abnormal price filtering (too high current price)
|
||||||
|
|
||||||
// 6th filtering condition: MACD
|
// 6th filtering condition: MACD
|
||||||
// let mut opclo_30m_vec: Vec<RealtimePriceData> = Vec::new();
|
// let mut opclo_30m_vec: Vec<RealtimePriceData> = Vec::new();
|
||||||
// let mut ema3_1d_vec: &Vec<EmaData> = &Vec::new();
|
// let mut ema3_1d_vec: &Vec<EmaData> = &Vec::new();
|
||||||
|
|
@ -333,13 +332,15 @@ pub async fn list_up_for_sell(
|
||||||
let mut opclo_30m_vec = all_data.rt_price_30m_vec[opclo_30m_option.unwrap()]
|
let mut opclo_30m_vec = all_data.rt_price_30m_vec[opclo_30m_option.unwrap()]
|
||||||
.1
|
.1
|
||||||
.clone();
|
.clone();
|
||||||
|
|
||||||
opclo_30m_vec.pop();
|
opclo_30m_vec.pop();
|
||||||
opclo_30m_vec.reverse();
|
opclo_30m_vec.reverse();
|
||||||
let mut opclo_sample_length: usize = 50; // 50 candle samsples
|
let mut opclo_sample_length: usize = 50; // 50 candle samsples
|
||||||
let nbr_of_exclusive: usize = 5;
|
let nbr_of_exclusive: usize = 5;
|
||||||
opclo_30m_vec.truncate(opclo_sample_length);
|
opclo_30m_vec.truncate(opclo_sample_length);
|
||||||
opclo_30m_vec.sort_by(|a, b| (a.high_price-a.low_price).total_cmp(&(b.high_price-b.low_price)));
|
opclo_30m_vec.sort_by(|a, b| {
|
||||||
|
(a.high_price - a.low_price).total_cmp(&(b.high_price - b.low_price))
|
||||||
|
});
|
||||||
opclo_30m_vec.truncate(opclo_sample_length - nbr_of_exclusive);
|
opclo_30m_vec.truncate(opclo_sample_length - nbr_of_exclusive);
|
||||||
opclo_sample_length -= nbr_of_exclusive;
|
opclo_sample_length -= nbr_of_exclusive;
|
||||||
|
|
||||||
|
|
@ -367,13 +368,14 @@ pub async fn list_up_for_sell(
|
||||||
// let target_profit_percent = average_amplitude + (standard_deviation_amplitude * (average_ratio_amp_body));
|
// let target_profit_percent = average_amplitude + (standard_deviation_amplitude * (average_ratio_amp_body));
|
||||||
let target_profit_percent = |multiplier: f64| -> f64 {
|
let target_profit_percent = |multiplier: f64| -> f64 {
|
||||||
if multiplier < 0.0 {
|
if multiplier < 0.0 {
|
||||||
((average_amplitude) * multiplier) - (standard_deviation_amplitude * 2.0) // 2.0 sigma (recommand: 0.5 ~ 2.0(patient & greedy))
|
((average_amplitude) * multiplier)
|
||||||
|
- (standard_deviation_amplitude * 2.0) // 2.0 sigma (recommand: 0.5 ~ 2.0(patient & greedy))
|
||||||
} else {
|
} else {
|
||||||
((average_amplitude) * multiplier) + (standard_deviation_amplitude * 2.0) // 2.0 sigma (recommand: 0.5 ~ 2.0(patient & greedy))
|
((average_amplitude) * multiplier)
|
||||||
|
+ (standard_deviation_amplitude * 2.0) // 2.0 sigma (recommand: 0.5 ~ 2.0(patient & greedy))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
if element.is_long == 0 || element.is_long == 1 {
|
if element.is_long == 0 || element.is_long == 1 {
|
||||||
if element.pure_profit_percent >= 0.0 {
|
if element.pure_profit_percent >= 0.0 {
|
||||||
let mut is_sell = false;
|
let mut is_sell = false;
|
||||||
|
|
@ -382,19 +384,14 @@ pub async fn list_up_for_sell(
|
||||||
{
|
{
|
||||||
println!(
|
println!(
|
||||||
"Selling {} 500% target_profit_percent: {:.3}",
|
"Selling {} 500% target_profit_percent: {:.3}",
|
||||||
element.symbol,
|
element.symbol, element.pure_profit_percent
|
||||||
element.pure_profit_percent
|
|
||||||
);
|
);
|
||||||
is_sell = true;
|
is_sell = true;
|
||||||
} else if element.pure_profit_percent >= 7.0
|
} else if element.pure_profit_percent >= 7.0 {
|
||||||
{
|
println!("Selling {} 7% profit_percent", element.symbol);
|
||||||
println!(
|
|
||||||
"Selling {} 7% profit_percent",
|
|
||||||
element.symbol
|
|
||||||
);
|
|
||||||
is_sell = true;
|
is_sell = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if is_sell == true {
|
if is_sell == true {
|
||||||
// let mut sell_price_ahead: Decimal = Decimal::new(14, 8);
|
// let mut sell_price_ahead: Decimal = Decimal::new(14, 8);
|
||||||
// sell_price_ahead = decimal_mul(decimal_add(decimal_mul(decimal_mul(rust_decimal::Decimal::from_f64(element.pure_profit_percent).unwrap(), dec!(0.01)), dec!(0.97)), dec!(1)), element.buy_price).round_dp_with_strategy(2, RoundingStrategy::ToZero);
|
// sell_price_ahead = decimal_mul(decimal_add(decimal_mul(decimal_mul(rust_decimal::Decimal::from_f64(element.pure_profit_percent).unwrap(), dec!(0.01)), dec!(0.97)), dec!(1)), element.buy_price).round_dp_with_strategy(2, RoundingStrategy::ToZero);
|
||||||
|
|
@ -410,25 +407,21 @@ pub async fn list_up_for_sell(
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let mut is_sell = false;
|
let mut is_sell = false;
|
||||||
if element.pure_profit_percent <= target_profit_percent(-2.5) - 0.2 // -0.2 means about total trade fees.
|
if element.pure_profit_percent <= target_profit_percent(-2.5) - 0.2
|
||||||
{
|
// -0.2 means about total trade fees.
|
||||||
println!(
|
|
||||||
"Selling {} -250% target_profit_percent: {:.3}",
|
|
||||||
element.symbol,
|
|
||||||
element.pure_profit_percent
|
|
||||||
);
|
|
||||||
is_sell = true;
|
|
||||||
} else if element.pure_profit_percent <= -5.0
|
|
||||||
{
|
{
|
||||||
println!(
|
println!(
|
||||||
"selling {} -5.0% profit",
|
"Selling {} -250% target_profit_percent: {:.3}",
|
||||||
element.symbol
|
element.symbol, element.pure_profit_percent
|
||||||
);
|
);
|
||||||
is_sell = true;
|
is_sell = true;
|
||||||
|
} else if element.pure_profit_percent <= -5.0 {
|
||||||
|
println!("selling {} -5.0% profit", element.symbol);
|
||||||
|
is_sell = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if is_sell == true {
|
if is_sell == true {
|
||||||
limit_order_sell(
|
limit_order_sell(
|
||||||
&element,
|
&element,
|
||||||
element.current_price,
|
element.current_price,
|
||||||
base_qty_to_be_ordered,
|
base_qty_to_be_ordered,
|
||||||
|
|
@ -446,4 +439,4 @@ pub async fn list_up_for_sell(
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -163,7 +163,7 @@
|
||||||
// ema30_30m_vec_c[ema30_search_result.unwrap()-4].ema_value < ema150_30m_vec_c[ema150_search_result.unwrap()-4].ema_value &&
|
// ema30_30m_vec_c[ema30_search_result.unwrap()-4].ema_value < ema150_30m_vec_c[ema150_search_result.unwrap()-4].ema_value &&
|
||||||
// ema30_30m_vec_c[ema30_search_result.unwrap()-3].ema_value < ema150_30m_vec_c[ema150_search_result.unwrap()-3].ema_value &&
|
// ema30_30m_vec_c[ema30_search_result.unwrap()-3].ema_value < ema150_30m_vec_c[ema150_search_result.unwrap()-3].ema_value &&
|
||||||
// ema30_30m_vec_c[ema30_search_result.unwrap()-2].ema_value < ema150_30m_vec_c[ema150_search_result.unwrap()-2].ema_value &&
|
// ema30_30m_vec_c[ema30_search_result.unwrap()-2].ema_value < ema150_30m_vec_c[ema150_search_result.unwrap()-2].ema_value &&
|
||||||
// ema30_30m_vec_c[ema30_search_result.unwrap()-1].ema_value < ema150_30m_vec_c[ema150_search_result.unwrap()-1].ema_value &&
|
// ema30_30m_vec_c[ema30_search_result.unwrap()-1].ema_value < ema150_30m_vec_c[ema150_search_result.unwrap()-1].ema_value &&
|
||||||
// ema30_30m_vec_c[ema30_search_result.unwrap()].ema_value >= ema150_30m_vec_c[ema150_search_result.unwrap()].ema_value &&
|
// ema30_30m_vec_c[ema30_search_result.unwrap()].ema_value >= ema150_30m_vec_c[ema150_search_result.unwrap()].ema_value &&
|
||||||
// ema30_30m_vec_c[ema30_search_result.unwrap()].ema_value > ema30_30m_vec_c[ema30_search_result.unwrap()-1].ema_value &&
|
// ema30_30m_vec_c[ema30_search_result.unwrap()].ema_value > ema30_30m_vec_c[ema30_search_result.unwrap()-1].ema_value &&
|
||||||
// ema30_30m_vec_c[ema30_search_result.unwrap()-1].ema_value > ema30_30m_vec_c[ema30_search_result.unwrap()-2].ema_value &&
|
// ema30_30m_vec_c[ema30_search_result.unwrap()-1].ema_value > ema30_30m_vec_c[ema30_search_result.unwrap()-2].ema_value &&
|
||||||
|
|
@ -206,15 +206,15 @@
|
||||||
// if heatmap_search_result.is_ok() {
|
// if heatmap_search_result.is_ok() {
|
||||||
// if (heatmap_volume_vec[heatmap_search_result.unwrap()].heatmap_level
|
// if (heatmap_volume_vec[heatmap_search_result.unwrap()].heatmap_level
|
||||||
// == HeatMapLevel::Low
|
// == HeatMapLevel::Low
|
||||||
// ||
|
// ||
|
||||||
// heatmap_volume_vec[heatmap_search_result.unwrap()].heatmap_level
|
// heatmap_volume_vec[heatmap_search_result.unwrap()].heatmap_level
|
||||||
// == HeatMapLevel::Normal) &&
|
// == HeatMapLevel::Normal) &&
|
||||||
// (heatmap_volume_vec[heatmap_search_result.unwrap()-1].heatmap_level
|
// (heatmap_volume_vec[heatmap_search_result.unwrap()-1].heatmap_level
|
||||||
// == HeatMapLevel::Low
|
// == HeatMapLevel::Low
|
||||||
// ||
|
// ||
|
||||||
// heatmap_volume_vec[heatmap_search_result.unwrap()-1].heatmap_level
|
// heatmap_volume_vec[heatmap_search_result.unwrap()-1].heatmap_level
|
||||||
// == HeatMapLevel::Normal
|
// == HeatMapLevel::Normal
|
||||||
// )
|
// )
|
||||||
// {
|
// {
|
||||||
// filtered_5th_symbols.push(element);
|
// filtered_5th_symbols.push(element);
|
||||||
// }
|
// }
|
||||||
|
|
@ -265,4 +265,4 @@
|
||||||
// insert_pre_suggested_coins(4, false, &a, alldata).await;
|
// insert_pre_suggested_coins(4, false, &a, alldata).await;
|
||||||
|
|
||||||
// Ok(())
|
// Ok(())
|
||||||
// }
|
// }
|
||||||
|
|
|
||||||
|
|
@ -126,19 +126,19 @@
|
||||||
// if heatmap_search_result.is_ok() {
|
// if heatmap_search_result.is_ok() {
|
||||||
// if (heatmap_volume_vec[heatmap_search_result.unwrap()].heatmap_level
|
// if (heatmap_volume_vec[heatmap_search_result.unwrap()].heatmap_level
|
||||||
// == HeatMapLevel::Low
|
// == HeatMapLevel::Low
|
||||||
// ||
|
// ||
|
||||||
// heatmap_volume_vec[heatmap_search_result.unwrap()].heatmap_level
|
// heatmap_volume_vec[heatmap_search_result.unwrap()].heatmap_level
|
||||||
// == HeatMapLevel::Normal) &&
|
// == HeatMapLevel::Normal) &&
|
||||||
// (heatmap_volume_vec[heatmap_search_result.unwrap()-1].heatmap_level
|
// (heatmap_volume_vec[heatmap_search_result.unwrap()-1].heatmap_level
|
||||||
// == HeatMapLevel::Low
|
// == HeatMapLevel::Low
|
||||||
// ||
|
// ||
|
||||||
// heatmap_volume_vec[heatmap_search_result.unwrap()-1].heatmap_level
|
// heatmap_volume_vec[heatmap_search_result.unwrap()-1].heatmap_level
|
||||||
// == HeatMapLevel::Normal) &&
|
// == HeatMapLevel::Normal) &&
|
||||||
// (heatmap_volume_vec[heatmap_search_result.unwrap()-2].heatmap_level
|
// (heatmap_volume_vec[heatmap_search_result.unwrap()-2].heatmap_level
|
||||||
// == HeatMapLevel::Low
|
// == HeatMapLevel::Low
|
||||||
// ||
|
// ||
|
||||||
// heatmap_volume_vec[heatmap_search_result.unwrap()-2].heatmap_level
|
// heatmap_volume_vec[heatmap_search_result.unwrap()-2].heatmap_level
|
||||||
// == HeatMapLevel::Normal)
|
// == HeatMapLevel::Normal)
|
||||||
// {
|
// {
|
||||||
// filtered_4th_symbols.push(element);
|
// filtered_4th_symbols.push(element);
|
||||||
// }
|
// }
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@
|
||||||
// let valid_symbol_vec_c = alldata.valid_symbol_vec.clone();
|
// let valid_symbol_vec_c = alldata.valid_symbol_vec.clone();
|
||||||
// for symbol in valid_symbol_vec_c {
|
// for symbol in valid_symbol_vec_c {
|
||||||
// let mut opclo_30m_vec: Vec<RealtimePriceData> = Vec::new();
|
// let mut opclo_30m_vec: Vec<RealtimePriceData> = Vec::new();
|
||||||
|
|
||||||
// let rt_price_30m_vec_c = alldata.rt_price_30m_vec.clone();
|
// let rt_price_30m_vec_c = alldata.rt_price_30m_vec.clone();
|
||||||
// let filtered_2nd_symbols_arc_c = Arc::clone(&filtered_2nd_symbols_arc);
|
// let filtered_2nd_symbols_arc_c = Arc::clone(&filtered_2nd_symbols_arc);
|
||||||
// task_vec.push(tokio::spawn(async move {
|
// task_vec.push(tokio::spawn(async move {
|
||||||
|
|
@ -82,7 +82,7 @@
|
||||||
// }
|
// }
|
||||||
// try_join_all(task_vec).await?;
|
// try_join_all(task_vec).await?;
|
||||||
|
|
||||||
// // 6th filtering: StochRSI (RSI length: 10, Stoch length: 10, smooth k: 3, smooth d: 3) smooth kn > kn-1
|
// // 6th filtering: StochRSI (RSI length: 10, Stoch length: 10, smooth k: 3, smooth d: 3) smooth kn > kn-1
|
||||||
// let filtered_3rd_symbol_c = filtered_3rd_symbols_arc.lock().await.clone();
|
// let filtered_3rd_symbol_c = filtered_3rd_symbols_arc.lock().await.clone();
|
||||||
// let mut rsi10_1d_data: Vec<(String, Vec<RsiData>)> = rsi(
|
// let mut rsi10_1d_data: Vec<(String, Vec<RsiData>)> = rsi(
|
||||||
// 10,
|
// 10,
|
||||||
|
|
@ -110,7 +110,7 @@
|
||||||
// );
|
// );
|
||||||
// if stoch_rsi_search_result.is_ok() {
|
// if stoch_rsi_search_result.is_ok() {
|
||||||
// if stoch_rsi10_1d_vec[stoch_rsi_search_result.unwrap()].k > stoch_rsi10_1d_vec[stoch_rsi_search_result.unwrap()-1].k &&
|
// if stoch_rsi10_1d_vec[stoch_rsi_search_result.unwrap()].k > stoch_rsi10_1d_vec[stoch_rsi_search_result.unwrap()-1].k &&
|
||||||
// stoch_rsi10_1d_vec[stoch_rsi_search_result.unwrap()].k < 90.0 &&
|
// stoch_rsi10_1d_vec[stoch_rsi_search_result.unwrap()].k < 90.0 &&
|
||||||
// stoch_rsi10_1d_vec[stoch_rsi_search_result.unwrap()-1].k > 10.0 {
|
// stoch_rsi10_1d_vec[stoch_rsi_search_result.unwrap()-1].k > 10.0 {
|
||||||
// filtered_4th_symbols.push(element);
|
// filtered_4th_symbols.push(element);
|
||||||
// }
|
// }
|
||||||
|
|
@ -200,4 +200,4 @@
|
||||||
// insert_pre_suggested_coins(6, true, &a, alldata).await;
|
// insert_pre_suggested_coins(6, true, &a, alldata).await;
|
||||||
|
|
||||||
// Ok(())
|
// Ok(())
|
||||||
// }
|
// }
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,12 @@ use rust_decimal::prelude::ToPrimitive;
|
||||||
use rust_decimal::Decimal;
|
use rust_decimal::Decimal;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
use tokio::time::{sleep, Duration, Instant};
|
use super::{
|
||||||
|
exists_record, insert_one_record, try_select_record, AllData, ExchangeInfo, FromRow,
|
||||||
|
RealtimePriceData, TradeFee,
|
||||||
|
};
|
||||||
use crate::signal_association::signal_decision::*;
|
use crate::signal_association::signal_decision::*;
|
||||||
use super::{AllData, RealtimePriceData, exists_record, try_select_record, insert_one_record, FromRow, ExchangeInfo, TradeFee};
|
use tokio::time::{sleep, Duration, Instant};
|
||||||
|
|
||||||
#[derive(Debug, FromRow)]
|
#[derive(Debug, FromRow)]
|
||||||
struct ServerEpoch {
|
struct ServerEpoch {
|
||||||
|
|
@ -41,10 +44,14 @@ pub async fn execute_list_up_for_buy(
|
||||||
pub async fn execute_list_up_for_sell(
|
pub async fn execute_list_up_for_sell(
|
||||||
all_data: &AllData,
|
all_data: &AllData,
|
||||||
exchange_info_vec: &Vec<ExchangeInfo>,
|
exchange_info_vec: &Vec<ExchangeInfo>,
|
||||||
trade_fee_vec: &Vec<TradeFee>
|
trade_fee_vec: &Vec<TradeFee>,
|
||||||
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||||
|
crate::strategy_team::strategy_003::list_up_for_sell(
|
||||||
crate::strategy_team::strategy_003::list_up_for_sell(all_data, exchange_info_vec, trade_fee_vec).await?;
|
all_data,
|
||||||
|
exchange_info_vec,
|
||||||
|
trade_fee_vec,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
@ -271,7 +278,7 @@ pub async fn insert_pre_suggested_coins(
|
||||||
0.0.to_string(), // maximum_profit_percent
|
0.0.to_string(), // maximum_profit_percent
|
||||||
registerer.to_string(), // registerer
|
registerer.to_string(), // registerer
|
||||||
];
|
];
|
||||||
|
|
||||||
if is_long == true {
|
if is_long == true {
|
||||||
insert_values.push(1.to_string()); // is_long
|
insert_values.push(1.to_string()); // is_long
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -555,7 +562,7 @@ pub async fn insert_pre_suggested_coins(
|
||||||
0.0.to_string(), // maximum_profit_percent
|
0.0.to_string(), // maximum_profit_percent
|
||||||
registerer.to_string(), // registerer
|
registerer.to_string(), // registerer
|
||||||
];
|
];
|
||||||
|
|
||||||
if is_long == true {
|
if is_long == true {
|
||||||
insert_values.push(1.to_string()); // is_long
|
insert_values.push(1.to_string()); // is_long
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -649,4 +656,3 @@ pub async fn insert_pre_suggested_coins(
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
pub mod price_data;
|
pub mod price_data;
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,10 @@
|
||||||
use crate::database_control::*;
|
use crate::database_control::*;
|
||||||
use crate::value_estimation_team::datapoints::price_data::RealtimePriceData;
|
use crate::value_estimation_team::datapoints::price_data::RealtimePriceData;
|
||||||
use csv::{DeserializeRecordsIter, StringRecord};
|
use csv::{DeserializeRecordsIter, StringRecord};
|
||||||
|
use futures::future::try_join_all;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use sqlx::FromRow;
|
use sqlx::FromRow;
|
||||||
use std::f64::NAN;
|
use std::f64::NAN;
|
||||||
use futures::future::try_join_all;
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::{fs::*, io::AsyncWriteExt, sync::Mutex, time::*};
|
use tokio::{fs::*, io::AsyncWriteExt, sync::Mutex, time::*};
|
||||||
|
|
||||||
|
|
@ -36,10 +36,9 @@ pub async fn rsi(
|
||||||
|
|
||||||
let mut rsi_data_wrapper: Vec<(String, Vec<RsiData>)> = Vec::new();
|
let mut rsi_data_wrapper: Vec<(String, Vec<RsiData>)> = Vec::new();
|
||||||
let mut rsi_data_wrapper_arc = Arc::new(Mutex::new(rsi_data_wrapper));
|
let mut rsi_data_wrapper_arc = Arc::new(Mutex::new(rsi_data_wrapper));
|
||||||
|
|
||||||
let mut task_vec = Vec::new();
|
let mut task_vec = Vec::new();
|
||||||
for element in filtered_symbols {
|
for element in filtered_symbols {
|
||||||
|
|
||||||
let element_c = element.clone();
|
let element_c = element.clone();
|
||||||
let rsi_data_wrapper_arc_c = Arc::clone(&rsi_data_wrapper_arc);
|
let rsi_data_wrapper_arc_c = Arc::clone(&rsi_data_wrapper_arc);
|
||||||
let symbol_search_result = input_rt_data.iter().position(|x| x.0 == *element_c.0);
|
let symbol_search_result = input_rt_data.iter().position(|x| x.0 == *element_c.0);
|
||||||
|
|
@ -135,8 +134,8 @@ pub async fn rsi(
|
||||||
prev_avg_ups = current_avg_ups;
|
prev_avg_ups = current_avg_ups;
|
||||||
prev_avg_downs = current_avg_downs;
|
prev_avg_downs = current_avg_downs;
|
||||||
|
|
||||||
let rs =
|
let rs = current_avg_ups.unwrap()
|
||||||
current_avg_ups.unwrap() / (current_avg_downs.unwrap() + 0.00000001); // 0.00000001 is used to avoid division by 0
|
/ (current_avg_downs.unwrap() + 0.00000001); // 0.00000001 is used to avoid division by 0
|
||||||
|
|
||||||
let rsi = 100.0 - (100.0 / (1.0 + rs));
|
let rsi = 100.0 - (100.0 / (1.0 + rs));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,10 @@
|
||||||
use crate::database_control::*;
|
use crate::database_control::*;
|
||||||
use crate::value_estimation_team::indicators::rsi::RsiData;
|
use crate::value_estimation_team::indicators::rsi::RsiData;
|
||||||
use csv::{DeserializeRecordsIter, StringRecord};
|
use csv::{DeserializeRecordsIter, StringRecord};
|
||||||
|
use futures::{future::try_join_all, lock::Mutex};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use sqlx::FromRow;
|
use sqlx::FromRow;
|
||||||
use std::f64::NAN;
|
use std::f64::NAN;
|
||||||
use futures::{future::try_join_all, lock::Mutex};
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::{fs::*, io::AsyncWriteExt, time::*};
|
use tokio::{fs::*, io::AsyncWriteExt, time::*};
|
||||||
|
|
||||||
|
|
@ -55,14 +55,17 @@ pub async fn stoch_rsi(
|
||||||
let mut stoch_rsi_data_vec: Vec<StochRsiData> = Vec::new();
|
let mut stoch_rsi_data_vec: Vec<StochRsiData> = Vec::new();
|
||||||
|
|
||||||
if stoch_rsi_length == 0 || smooth_k == 0 || smooth_d == 0 {
|
if stoch_rsi_length == 0 || smooth_k == 0 || smooth_d == 0 {
|
||||||
panic!("stoch_rsi_length or smooth_k or smooth_d can't be 0! stoch_rsi_length: {}, k:{}, d:{}", stoch_rsi_length, smooth_k, smooth_d);
|
panic!(
|
||||||
|
"stoch_rsi_length or smooth_k or smooth_d can't be 0! stoch_rsi_length: {}, k:{}, d:{}",
|
||||||
|
stoch_rsi_length, smooth_k, smooth_d
|
||||||
|
);
|
||||||
}
|
}
|
||||||
let mut task_vec = Vec::new();
|
let mut task_vec = Vec::new();
|
||||||
for element in input_rsi_data {
|
for element in input_rsi_data {
|
||||||
let mut stoch_rsi_data = StochRsiData::new();
|
let mut stoch_rsi_data = StochRsiData::new();
|
||||||
let mut stoch_rsi_k_data = StochRsiKData::new();
|
let mut stoch_rsi_k_data = StochRsiKData::new();
|
||||||
let stoch_rsi_data_wrapper_arc_c = Arc::clone(&stoch_rsi_data_wrapper_arc);
|
let stoch_rsi_data_wrapper_arc_c = Arc::clone(&stoch_rsi_data_wrapper_arc);
|
||||||
|
|
||||||
let element_c = element.clone();
|
let element_c = element.clone();
|
||||||
task_vec.push(tokio::spawn(async move {
|
task_vec.push(tokio::spawn(async move {
|
||||||
let mut stoch_rsi_data_vec: Vec<StochRsiData> = Vec::new();
|
let mut stoch_rsi_data_vec: Vec<StochRsiData> = Vec::new();
|
||||||
|
|
@ -70,9 +73,10 @@ pub async fn stoch_rsi(
|
||||||
let mut stoch_rsi_vec: Vec<RsiData> = Vec::new();
|
let mut stoch_rsi_vec: Vec<RsiData> = Vec::new();
|
||||||
let mut stoch_rsi = RsiData::new();
|
let mut stoch_rsi = RsiData::new();
|
||||||
|
|
||||||
if element_c.1.len() >= stoch_rsi_length &&
|
if element_c.1.len() >= stoch_rsi_length
|
||||||
element_c.1.len() >= smooth_k &&
|
&& element_c.1.len() >= smooth_k
|
||||||
element_c.1.len() >= smooth_d {
|
&& element_c.1.len() >= smooth_d
|
||||||
|
{
|
||||||
let mut read_data_vec = element_c.1;
|
let mut read_data_vec = element_c.1;
|
||||||
let window_iter = read_data_vec.windows(stoch_rsi_length);
|
let window_iter = read_data_vec.windows(stoch_rsi_length);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,2 @@
|
||||||
pub mod datapoints;
|
pub mod datapoints;
|
||||||
pub mod indicators;
|
pub mod indicators;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user