FinceptTerminal is a modern finance application offering advanced market analytics, investment research, and economic data tools, designed for interactive exploration and data-driven decision-making in a user-friendly environment.
C++ ai-agentsalgorithmic-tradingbloomberg-terminalcppfinancefinancial-marketsfintechgood-first-issueinvestmentinvestment-researchmachine-learningopensourcepythonqtquantitative-financestock-markettrading
// src/services/geopolitics/GeopoliticsService.h
#pragma once
#include "datahub/Producer.h"
#include "services/geopolitics/GeopoliticsTypes.h"
#include <QHash>
#include <QObject>
#include <functional>
namespace fincept::services::geo {
/// Singleton service for geopolitics data — news events API + HDX Python + trade analysis.
class GeopoliticsService : public QObject, public fincept::datahub::Producer {
Q_OBJECT
public:
static GeopoliticsService& instance();
/// Register with the hub + install geopolitics:* policies. Idempotent.
void ensure_registered_with_hub();
// ── fincept::datahub::Producer ─────────────────────────────────────────
QStringList topic_patterns() const override;
void refresh(const QStringList& topics) override;
int max_requests_per_sec() const override;
// ── Conflict Monitor (HTTP API) ─────────────────────────────────────────
//
// The Fincept news-events endpoint now supports pagination + extra
// filters echoed in `filters_applied`. `limit` maps to events_per_page,
// `page` is 1-indexed. `source`, `date_from`, `date_to` are forwarded
// verbatim — server validates and ignores empty values.
void fetch_events(const QString& country = {}, const QString& city = {}, const QString& category = {},
int limit = 100, int page = 1, const QString& source = {}, const QString& date_from = {},
const QString& date_to = {});
void fetch_unique_countries();
void fetch_unique_categories();
void fetch_unique_cities();
// ── HDX Humanitarian Data (Python) ──────────────────────────────────────
void search_hdx_conflicts();
void search_hdx_humanitarian();
void search_hdx_by_country(const QString& country);
void search_hdx_by_topic(const QString& topic);
void search_hdx_advanced(const QString& query);
// ── Trade Analysis (Python) ─────────────────────────────────────────────
void analyze_trade_benefits(const QJsonObject& params);
void analyze_trade_restrictions(const QJsonObject& params);
/// Trading-bloc integration (trade creation vs diversion) — script mode `trading_blocs`.
void analyze_trading_blocs(const QJsonObject& params);
/// Impact of removing trade barriers (FDI / employment / GDP) — script mode `barrier_removal`.
void analyze_barrier_removal(const QJsonObject& params);
// ── Geolocation (Python) ────────────────────────────────────────────────
void extract_geolocations(const QStringList& headlines);
signals:
void events_loaded(fincept::services::geo::EventsPage page);
void countries_loaded(QVector<fincept::services::geo::UniqueCountry> countries);
void categories_loaded(QVector<fincept::services::geo::UniqueCategory> categories);
void cities_loaded(QStringList cities);
void hdx_results_loaded(QString context, QVector<fincept::services::geo::HDXDataset> datasets);
void trade_result_ready(QString context, QJsonObject data);
void geolocation_ready(QJsonObject data);
void error_occurred(QString context, QString message);
private:
explicit GeopoliticsService(QObject* parent = nullptr);
Q_DISABLE_COPY(GeopoliticsService)
void run_python(const QString& script, const QStringList& args, const QString& context,
std::function<void(bool, const QString&)> cb);
// Every news-events call (events page or reference list) costs API credits.
/// Hub TTL for the shared `geopolitics:events` topic — the source updates ~every 30 min.
static constexpr int kEventsHubTtlSec = 30 * 60;
/// Countries / categories / cities lists (CacheManager + hub TTL).
static constexpr int kRefDataTtlSec = 6 * 60 * 60;
void publish_hdx_result(const QString& context, const QVector<fincept::services::geo::HDXDataset>& datasets);
bool hub_registered_ = false;
};
} // namespace fincept::services::geo