88#include " aos/sliding_window_storage/c_sliding_window_storage.h"
99#include " aos/strategy/i_strategy.h"
1010#include " aos/strategy/strategy.h"
11+ #include " aos/strategies/deviation_and_mutual_info/config.h"
12+ #include " aos/hash_utils/decompose_hash.h"
13+ #include " fmtlog.h"
1114
1215namespace aos {
1316namespace strategies {
@@ -18,34 +21,33 @@ class Strategy : public StrategyInterface<HashT, T>{
1821 impl::SlidingWindowStorageAvgDevMinMax<HashT, T> sliding_window_;
1922 impl::MutualInformationCalculator<HashT, T> mi_calculator_;
2023 MarketTripletManagerInterface<HashT>& market_triplet_manager_;
21-
24+ const Config<HashT>& config_;
2225 private:
2326 void InitBuyActions () {
2427 core_strategy_.AddActionsToBuy (
25- [](std::queue<size_t >& queue, size_t hash, const double & value) {
26- if (hash == 1 ) {
28+ [this ](std::queue<HashT >& queue, HashT hash, const T & value) {
29+ if (hash == config_. allowed_asset_hash ) {
2730 logi (" start analise hash:{} value:{}" , hash, value);
2831 queue.push (hash);
2932 }
3033 });
3134
32- core_strategy_.AddActionsToBuy ([this ](std::queue<size_t >& queue, size_t hash,
33- const double & value) {
35+ core_strategy_.AddActionsToBuy ([this ](std::queue<HashT >& queue, HashT hash,
36+ const T & value) {
3437 auto [_, ratio] = sliding_window_.GetDeviationRatio (hash, value);
35- auto dev = sliding_window_.GetDeviation (hash, value);
36- logi (" Buy: hash:{} value:{} dev:{} ratio:{}" , hash, value, dev,
37- ratio);
38+ auto [status_deviation, dev] = sliding_window_.GetDeviation (hash, value);
39+ logi (" Buy: hash:{} value:{} dev:{} ratio:{}" , hash, value, dev, ratio);
3840 if (ratio > 0.001 ) {
3941 queue.push (hash);
4042 }
4143 });
4244
43- core_strategy_.AddActionsToBuy ([this ](std::queue<size_t >& queue, size_t hash,
44- const double & value) {
45+ core_strategy_.AddActionsToBuy ([this ](std::queue<HashT >& queue, HashT hash,
46+ const T & value) {
4547 if (!market_triplet_manager_.HasPair (hash)) return ;
4648 for (const auto & pair : market_triplet_manager_.GetPairs (hash)) {
4749 auto [status, mi] = mi_calculator_.ComputeMutualInformation (
48- sliding_window_, hash, pair, 10 );
50+ sliding_window_, hash, pair, config_. number_bins );
4951 if (status && mi > 2 ) {
5052 logi (" Buy MI ({} <-> {}): {}" , hash, pair, mi);
5153 queue.push (pair);
@@ -54,36 +56,44 @@ class Strategy : public StrategyInterface<HashT, T>{
5456 });
5557
5658 core_strategy_.AddActionsToBuy (
57- [](std::queue<size_t >& queue, size_t hash, const double & value) {
58- logi (" Need buy hash:{} value:{}" , hash, value);
59+ [](std::queue<HashT>& queue, HashT hash, const T& value) {
60+ common::ExchangeId exchange_id_1 = common::ExchangeId::kInvalid ;
61+ aos::NetworkEnvironment network_environment_1;
62+ aos::CategoryRaw category_market_1;
63+ aos::TradingPair trading_pair_1;
64+ aos::DecomposeHash (hash, exchange_id_1, category_market_1,
65+ network_environment_1, trading_pair_1);
66+ logi (" need buy with hash={} with value={} on {} category={} {} {}" ,
67+ hash, value, exchange_id_1, category_market_1, network_environment_1,
68+ trading_pair_1);
5969 });
6070 };
6171 void InitSellActions () {
6272 core_strategy_.AddActionsToSell (
63- [](std::queue<size_t >& queue, size_t hash, const double & value) {
64- if (hash == 1 ) {
73+ [this ](std::queue<HashT >& queue, HashT hash, const T & value) {
74+ if (hash == config_. allowed_asset_hash ) {
6575 logi (" start analise hash:{} value:{}" , hash, value);
6676 queue.push (hash);
6777 }
6878 });
6979
70- core_strategy_.AddActionsToSell ([this ](std::queue<size_t >& queue, size_t hash,
71- const double & value) {
80+ core_strategy_.AddActionsToSell ([this ](std::queue<HashT >& queue, HashT hash,
81+ const T & value) {
7282 auto [_, ratio] = sliding_window_.GetDeviationRatio (hash, value);
73- auto dev = sliding_window_.GetDeviation (hash, value);
83+ auto [status_deviation, dev] = sliding_window_.GetDeviation (hash, value);
7484 logi (" Sell: hash:{} value:{} dev:{} ratio:{}" , hash, value, dev,
7585 ratio);
7686 if (ratio < 0.001 ) {
7787 queue.push (hash);
7888 }
7989 });
8090
81- core_strategy_.AddActionsToSell ([this ](std::queue<size_t >& queue, size_t hash,
82- const double & value) {
91+ core_strategy_.AddActionsToSell ([this ](std::queue<HashT >& queue, HashT hash,
92+ const T & value) {
8393 if (!market_triplet_manager_.HasPair (hash)) return ;
8494 for (const auto & pair : market_triplet_manager_.GetPairs (hash)) {
8595 auto [status, mi] = mi_calculator_.ComputeMutualInformation (
86- sliding_window_, hash, pair, 10 );
96+ sliding_window_, hash, pair, config_. number_bins );
8797 if (status && mi > 2 ) {
8898 logi (" Sell MI ({} <-> {}): {}" , hash, pair, mi);
8999 queue.push (pair);
@@ -92,15 +102,24 @@ class Strategy : public StrategyInterface<HashT, T>{
92102 });
93103
94104 core_strategy_.AddActionsToSell (
95- [](std::queue<size_t >& queue, size_t hash, const double & value) {
96- logi (" Need sell hash:{} value:{}" , hash, value);
105+ [](std::queue<HashT>& queue, HashT hash, const T& value) {
106+ common::ExchangeId exchange_id_1 = common::ExchangeId::kInvalid ;
107+ aos::NetworkEnvironment network_environment_1;
108+ aos::CategoryRaw category_market_1;
109+ aos::TradingPair trading_pair_1;
110+ aos::DecomposeHash (hash, exchange_id_1, category_market_1,
111+ network_environment_1, trading_pair_1);
112+ logi (" need sell with hash={} with value={} on {} category={} {} {}" ,
113+ hash, value, exchange_id_1, category_market_1, network_environment_1,
114+ trading_pair_1);
97115 });
98116 }
99117
100118 public:
101- Strategy (int window_size, MarketTripletManagerInterface<HashT>& market_triplet_manager) :
102- sliding_window_ (window_size),
103- market_triplet_manager_ (market_triplet_manager) {
119+ Strategy (MarketTripletManagerInterface<HashT>& market_triplet_manager, const Config<HashT>& config) :
120+ sliding_window_ (config.window_size),
121+ market_triplet_manager_ (market_triplet_manager),
122+ config_ (config) {
104123 InitBuyActions ();
105124 InitSellActions ();
106125 }
0 commit comments