-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpredictor.cpp
More file actions
145 lines (133 loc) · 4.62 KB
/
predictor.cpp
File metadata and controls
145 lines (133 loc) · 4.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#include "MarketData/alpha_vantage_fx_provider.h"
#include "MarketData/candle_data_provider.h"
#include "MarketData/dukascopy_cli_provider.h"
#include "Prediction/predictor_engine.h"
#include <cstdlib>
#include <iostream>
#include <string>
namespace
{
std::string default_model_path(CandleTimeframe timeframe)
{
return "Models/gold_digger_" + to_string(timeframe) + ".dat";
}
void print_usage()
{
std::cout << "Usage: predictor [--model PATH] [--instrument SYMBOL] [--timeframe m15|h1|d1]\n"
<< " [--provider dukascopy|alphavantage]\n"
<< " [--dukascopy-command CMD] [--dukascopy-debug-dir DIR]\n"
<< " [--alpha-vantage-api-key KEY] [--alpha-vantage-base-url URL]\n"
<< " [--poll-seconds N] [--availability-delay-seconds N]\n"
<< " [--max-predictions N]\n";
}
}
int main(int argc, char *argv[])
{
PredictorConfig config;
std::string providerName{"dukascopy"};
std::string dukascopyCommand{"npx dukascopy-node -s"};
std::string dukascopyDebugDirectory;
std::string alphaVantageApiKey;
std::string alphaVantageBaseUrl{"https://www.alphavantage.co/query"};
bool modelProvided = false;
if (const char *envCommand = std::getenv("DUKASCOPY_NODE_COMMAND"))
dukascopyCommand = envCommand;
if (const char *envKey = std::getenv("ALPHAVANTAGE_API_KEY"))
alphaVantageApiKey = envKey;
for (int i = 1; i < argc; ++i)
{
const std::string argument = argv[i];
auto require_value = [&](const char *option) -> const char *
{
if (i + 1 >= argc)
{
std::cerr << "Missing value for " << option << '\n';
std::exit(1);
}
return argv[++i];
};
if (argument == "--help")
{
print_usage();
return 0;
}
if (argument == "--model")
{
config.modelFile = require_value("--model");
modelProvided = true;
}
else if (argument == "--instrument")
{
config.instrument = require_value("--instrument");
}
else if (argument == "--timeframe")
{
CandleTimeframe timeframe{};
if (!parse_timeframe(require_value("--timeframe"), timeframe))
{
std::cerr << "Unsupported timeframe. Use m15, h1, or d1.\n";
return 1;
}
config.timeframe = timeframe;
}
else if (argument == "--provider")
{
providerName = require_value("--provider");
}
else if (argument == "--dukascopy-command")
{
dukascopyCommand = require_value("--dukascopy-command");
}
else if (argument == "--dukascopy-debug-dir")
{
dukascopyDebugDirectory = require_value("--dukascopy-debug-dir");
}
else if (argument == "--alpha-vantage-api-key")
{
alphaVantageApiKey = require_value("--alpha-vantage-api-key");
}
else if (argument == "--alpha-vantage-base-url")
{
alphaVantageBaseUrl = require_value("--alpha-vantage-base-url");
}
else if (argument == "--poll-seconds")
{
config.pollInterval = std::chrono::seconds(std::stoll(require_value("--poll-seconds")));
}
else if (argument == "--availability-delay-seconds")
{
config.availabilityDelay = std::chrono::seconds(std::stoll(require_value("--availability-delay-seconds")));
}
else if (argument == "--max-predictions")
{
config.maxPredictions = std::stoull(require_value("--max-predictions"));
}
else
{
std::cerr << "Unknown argument: " << argument << '\n';
print_usage();
return 1;
}
}
if (!modelProvided)
config.modelFile = default_model_path(config.timeframe);
std::unique_ptr<ICandleDataProvider> provider;
if (providerName == "dukascopy")
{
provider = std::make_unique<DukascopyCliDataProvider>(dukascopyCommand, dukascopyDebugDirectory);
}
else if (providerName == "alphavantage")
{
provider = std::make_unique<AlphaVantageFxProvider>(AlphaVantageFxProvider::Config{
alphaVantageApiKey,
alphaVantageBaseUrl,
"compact"});
}
else
{
std::cerr << "Unsupported provider: " << providerName << '\n';
return 1;
}
PredictorEngine predictor(std::move(provider), config);
return predictor.run();
}