crypto_trader
Cryptocurrency Trading Bot API Documentation
Loading...
Searching...
No Matches
crypto_trader::executors::PaperTradingExecutor< T > Class Template Reference

A concrete implementation of the Executor protocol for paper (simulated) trading. More...

#include <paper_trading_executor.h>

Inheritance diagram for crypto_trader::executors::PaperTradingExecutor< T >:
Inheritance graph
Collaboration diagram for crypto_trader::executors::PaperTradingExecutor< T >:
Collaboration graph

Public Member Functions

 PaperTradingExecutor (const PaperTradingExecutorConfig &config, traders::EventPositionManager &positionManager)
 Constructs a PaperTradingExecutor.
 ~PaperTradingExecutor ()=default
 Destructor for PaperTradingExecutor.
common::TradeResult buy (const std::string_view &product, double quantity) override
 Executes a simulated buy order.
common::TradeResult sell (const std::string_view &product, double quantity) override
 Executes a simulated sell order.
double getBalance (const std::string_view &currency) const override
 Gets the current balance of a currency.
std::optional< double > getPosition (const std::string_view &product) const override
 Gets the current position for a given product.
void processTickerData (const std::string_view &product, double price, const T::Timestamp &timestamp) override
 Processes new ticker data to update internal market prices.
double getRealizedPnl (const std::string_view &product) const
 Gets the total realized Profit and Loss for the configured product.
double balance () const
 Returns the current cash balance.
std::optional< double > pnl (const std::string_view &product, bool realize) const
 Returns either the realized or unrealized PnL for the given product.
std::optional< double > getAverageCostBasis (const std::string_view &product) const
 Gets the average cost basis for a given product.
Public Member Functions inherited from crypto_trader::protocols::Executor< T >
virtual ~Executor ()=default
 Destructor for the Executor interface.

Detailed Description

template<common::MarketData T>
class crypto_trader::executors::PaperTradingExecutor< T >

A concrete implementation of the Executor protocol for paper (simulated) trading.

This executor manages an internal cash balance and positions, simulating trade executions without interacting with real exchanges.

Template Parameters
TThe MarketData type that the executor processes.

Constructor & Destructor Documentation

◆ PaperTradingExecutor()

template<common::MarketData T>
crypto_trader::executors::PaperTradingExecutor< T >::PaperTradingExecutor ( const PaperTradingExecutorConfig & config,
traders::EventPositionManager & positionManager )

Constructs a PaperTradingExecutor.

Parameters
configThe configuration for the executor.
positionManagerA reference to the EventPositionManager for tracking positions.

◆ ~PaperTradingExecutor()

template<common::MarketData T>
crypto_trader::executors::PaperTradingExecutor< T >::~PaperTradingExecutor ( )
default

Destructor for PaperTradingExecutor.

Member Function Documentation

◆ balance()

template<common::MarketData T>
double crypto_trader::executors::PaperTradingExecutor< T >::balance ( ) const

Returns the current cash balance.

Returns
The current balance.

◆ buy()

template<common::MarketData T>
common::TradeResult crypto_trader::executors::PaperTradingExecutor< T >::buy ( const std::string_view & product,
double quantity )
overridevirtual

Executes a simulated buy order.

Parameters
productThe symbol of the product to buy.
quantityThe amount of the product to buy.
Returns
The result of the simulated trade.

Implements crypto_trader::protocols::Executor< T >.

◆ getAverageCostBasis()

template<common::MarketData T>
std::optional< double > crypto_trader::executors::PaperTradingExecutor< T >::getAverageCostBasis ( const std::string_view & product) const

Gets the average cost basis for a given product.

Parameters
productThe symbol of the product.
Returns
An optional containing the average cost basis, or empty if no position.

◆ getBalance()

template<common::MarketData T>
double crypto_trader::executors::PaperTradingExecutor< T >::getBalance ( const std::string_view & currency) const
overridevirtual

Gets the current balance of a currency.

Parameters
currencyThe symbol of the currency (e.g., "USD").
Returns
The current balance.

Implements crypto_trader::protocols::Executor< T >.

◆ getPosition()

template<common::MarketData T>
std::optional< double > crypto_trader::executors::PaperTradingExecutor< T >::getPosition ( const std::string_view & product) const
overridevirtual

Gets the current position for a given product.

Parameters
productThe symbol of the product.
Returns
An optional containing the quantity held, or empty if no position.

Implements crypto_trader::protocols::Executor< T >.

◆ getRealizedPnl()

template<common::MarketData T>
double crypto_trader::executors::PaperTradingExecutor< T >::getRealizedPnl ( const std::string_view & product) const

Gets the total realized Profit and Loss for the configured product.

Parameters
productThe symbol of the product.
Returns
The total realized PnL.

◆ pnl()

template<common::MarketData T>
std::optional< double > crypto_trader::executors::PaperTradingExecutor< T >::pnl ( const std::string_view & product,
bool realize ) const

Returns either the realized or unrealized PnL for the given product.

Parameters
productThe symbol of the product.
realizeIf true, returns realized PnL; otherwise, returns unrealized PnL.
Returns
An optional containing the PnL, or empty if not applicable.

◆ processTickerData()

template<common::MarketData T>
void crypto_trader::executors::PaperTradingExecutor< T >::processTickerData ( const std::string_view & product,
double price,
const T::Timestamp & timestamp )
overridevirtual

Processes new ticker data to update internal market prices.

Parameters
productThe symbol of the product for the ticker.
priceThe latest price of the product.
timestampThe timestamp of the ticker data.

Implements crypto_trader::protocols::Executor< T >.

◆ sell()

template<common::MarketData T>
common::TradeResult crypto_trader::executors::PaperTradingExecutor< T >::sell ( const std::string_view & product,
double quantity )
overridevirtual

Executes a simulated sell order.

Parameters
productThe symbol of the product to sell.
quantityThe amount of the product to sell.
Returns
The result of the simulated trade.

Implements crypto_trader::protocols::Executor< T >.


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