crypto_trader
Cryptocurrency Trading Bot API Documentation
Loading...
Searching...
No Matches
crypto_trader::databases::MarketEventsDb Class Reference

#include <market_events_db.h>

Collaboration diagram for crypto_trader::databases::MarketEventsDb:
Collaboration graph

Public Types

using MarketEventsDbPtr = std::shared_ptr<MarketEventsDb>
using Events = std::vector<common::Event>
using SymbolPositionsVec = std::vector<common::SymbolPositions>

Public Member Functions

 MarketEventsDb (const std::string &dbPath)
 ~MarketEventsDb ()
bool init () noexcept(true)
 Initialized the database by setting up performance configurations, running migrations, and starting up an async thread for batch writes.
bool logEvent (const common::Event &event)
 log a single event to the events table. Smartly routes events based on their type to either be logged synchronous or async This method does not throw.
bool logEvents (const std::vector< common::Event > &events)
 log a batch of events to the events table.
std::optional< EventsgetEventsSince (int64_t timestamp) noexcept(true)
 Return a vector containing the Events since the given timestamp. This method does not throw, but returns std::nullopt if something goes wrong.
std::optional< EventsgetEventsBySymbol (const std::string &symbol, int64_t startTs, const std::optional< int64_t > &endTs=std::nullopt) noexcept(true)
 Return a vector containing the Events for a given symbol between the given startTs and endTs. If the optional endTs isn't given, assume endTs = present. This method does not throw, but returns std::nullopt if something goes wrong.
bool logSnapshot (const common::SymbolPositions &snapshot) noexcept(true)
 Write a single snapshot synchronously.
bool logSnapshots (const std::vector< common::SymbolPositions > &snapshots) noexcept(true)
 Write a group of snapshots synchronously in a batch.
std::optional< common::SymbolPositionsgetLatestSnapshot (const std::string &symbol) noexcept(true)
 get latest snapshot for a given symbol
std::optional< SymbolPositionsVecgetLatestSnapshots () noexcept(true)
 get latest snapshot for all symbols

Member Typedef Documentation

◆ Events

◆ MarketEventsDbPtr

◆ SymbolPositionsVec

Constructor & Destructor Documentation

◆ MarketEventsDb()

crypto_trader::databases::MarketEventsDb::MarketEventsDb ( const std::string & dbPath)
explicit

◆ ~MarketEventsDb()

crypto_trader::databases::MarketEventsDb::~MarketEventsDb ( )

Member Function Documentation

◆ getEventsBySymbol()

std::optional< MarketEventsDb::Events > crypto_trader::databases::MarketEventsDb::getEventsBySymbol ( const std::string & symbol,
int64_t startTs,
const std::optional< int64_t > & endTs = std::nullopt )
noexcept

Return a vector containing the Events for a given symbol between the given startTs and endTs. If the optional endTs isn't given, assume endTs = present. This method does not throw, but returns std::nullopt if something goes wrong.

Returns
std::optional<std::vector<Event>>

◆ getEventsSince()

std::optional< MarketEventsDb::Events > crypto_trader::databases::MarketEventsDb::getEventsSince ( int64_t timestamp)
noexcept

Return a vector containing the Events since the given timestamp. This method does not throw, but returns std::nullopt if something goes wrong.

Returns
std::optional<std::vector<Event>>

◆ getLatestSnapshot()

std::optional< common::SymbolPositions > crypto_trader::databases::MarketEventsDb::getLatestSnapshot ( const std::string & symbol)
noexcept

get latest snapshot for a given symbol

Parameters
symbol
Returns
std::optional<common::SymbolPositions>

◆ getLatestSnapshots()

std::optional< MarketEventsDb::SymbolPositionsVec > crypto_trader::databases::MarketEventsDb::getLatestSnapshots ( )
noexcept

get latest snapshot for all symbols

Returns
std::optional<common::SymbolPositions>

◆ init()

bool crypto_trader::databases::MarketEventsDb::init ( )
noexcept

Initialized the database by setting up performance configurations, running migrations, and starting up an async thread for batch writes.

Returns
bool if all succeeded

◆ logEvent()

bool crypto_trader::databases::MarketEventsDb::logEvent ( const common::Event & event)

log a single event to the events table. Smartly routes events based on their type to either be logged synchronous or async This method does not throw.

Returns
bool if successful

◆ logEvents()

bool crypto_trader::databases::MarketEventsDb::logEvents ( const std::vector< common::Event > & events)

log a batch of events to the events table.

Returns
bool if successful

◆ logSnapshot()

bool crypto_trader::databases::MarketEventsDb::logSnapshot ( const common::SymbolPositions & snapshot)
noexcept

Write a single snapshot synchronously.

Parameters
snapshot
Returns
bool on success

◆ logSnapshots()

bool crypto_trader::databases::MarketEventsDb::logSnapshots ( const std::vector< common::SymbolPositions > & snapshots)
noexcept

Write a group of snapshots synchronously in a batch.

Parameters
snapshots
Returns
bool on success

The documentation for this class was generated from the following files: