-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
57 lines (46 loc) · 1.77 KB
/
main.cpp
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
#include <bits/stdc++.h>
#include <jsoncpp/json/json.h>
#include <fstream>
#include "functions.h"
#include "curl_function.h"
using namespace std;
int main() {
string ticker;
cout << "\nEnter Ticker symbol of a company: ";
cin >> ticker;
while (true) {
Json::Value config;
ifstream config_file("config.json", ifstream::binary);
if (!config_file.is_open()) {
cerr << "Failed to open config file." << endl;
return 1;
}
config_file >> config;
config_file.close();
string api_key = config["api_key"].asString();
string name, exchange, currency, ans;
float open, high, low, close, volume, change, price;
int amount;
price = stof(get_price(ticker, api_key));
Json::Value stock_data = get_stock_quote(ticker, api_key);
if (!stock_data.empty()) {
name = stock_data["name"].asString();
exchange = stock_data["exchange"].asString();
currency = stock_data["currency"].asString();
open = stof(stock_data["open"].asString());
high = stof(stock_data["high"].asString());
low = stof(stock_data["low"].asString());
close = stof(stock_data["close"].asString());
volume = stof(stock_data["volume"].asString());
change = stof(stock_data["change"].asString());
} else {
cerr << "Failed to fetch stock quote." << endl;
return 1;
}
print_data(name, exchange, currency, open, high, low, close, volume, change, price);
ProfitLoss(open, close, name);
Sendsignal(price, high, low, ans, amount);
this_thread::sleep_for(chrono::milliseconds(3000));
}
return 0;
}