2. Modules
Each section of this document provides the source code documentation of each
component of TradingMate.
2.1. TradingMate
-
class
tradingmate.
TradingMate
(config_filepath: pathlib.Path = PosixPath('/home/docs/.TradingMate/config/config.json'))[source]
Main class that handles the interaction between the User Interface and the
underlying business logic of the application
-
close_view_event
() → None[source]
Callback function to handle close event of the user interface
-
delete_trade_event
(portfolio_id: str, trade_id: str) → None[source]
Callback function to handle delete of a trade
-
get_app_log_filepath
()[source]
Return the full filepath of the log file of application current session
-
get_portfolios
() → List[tradingmate.model.portfolio.Portfolio][source]
Return the list of active portfolios
-
get_settings_event
()[source]
Callback to handle request to show the settings panel
-
manual_refresh_event
(portfolio_id: str) → None[source]
Callback function to handle refresh data request
-
new_trade_event
(new_trade: tradingmate.model.trade.Trade, portfolio_id: str) → None[source]
Callback function to handle new trade event
-
open_portfolio_event
(filepath: pathlib.Path) → None[source]
Callback function to handle request to open a new portfolio file
-
save_portfolio_event
(portfolio_id: str, filepath: pathlib.Path) → None[source]
Callback function to handle request to save/export the portfolio
-
save_settings_event
(config)[source]
Callback to save edited settings
-
set_auto_refresh
(enabled: bool, portfolio_id: str) → None[source]
Callback function to handle set/unset of auto refresh data
2.2. Model
The model
module contains the business logic and the data management of
TradingMate.
2.2.1. Holding
-
class
tradingmate.model.
Holding
(symbol: str, quantity: int, open_price: Optional[float] = None)[source]
Represent a current open position for a Market
-
add_quantity
(value: int) → None[source]
Add or subtract (if value is negative) the value to the holding quantity
2.2.2. Portfolio
-
class
tradingmate.model.
Portfolio
(config: tradingmate.model.configuration.ConfigurationManager, trading_log_path: pathlib.Path)[source]
Represent a trading portfolio including cash available and open market positions.
The portfolio is based on a list of trades read from the trading log
-
add_trade
(new_trade: tradingmate.model.trade.Trade) → None[source]
Add a new trade into the Portfolio
-
delete_trade
(trade_id: str) → None[source]
Remove a trade from the Portfolio
-
get_cash_available
() → float[source]
Return the available cash quantity in the portfolio [int]
-
get_cash_deposited
() → float[source]
Return the amount of cash deposited in the portfolio [int]
-
get_holding_last_price
(symbol: str) → Optional[float][source]
Return the last price for the given symbol
-
get_holding_list
() → List[tradingmate.model.holding.Holding][source]
Return a list of Holding instances held in the portfolio sorted alphabetically
-
get_holding_open_price
(symbol: str) → Optional[float][source]
Return the last price for the given symbol
-
get_holding_quantity
(symbol: str) → int[source]
Return the quantity held for the given symbol
-
get_holding_symbols
() → List[str][source]
Return a list containing the holding symbols as [string] sorted alphabetically
-
get_holdings_value
() → Optional[float][source]
Return the value of the holdings held in the portfolio
-
get_id
() → str[source]
Return the portfolio unique id [string]
-
get_name
() → str[source]
Return the portfolio name [string]
-
get_open_positions_pl
() → Optional[float][source]
Return the sum profit/loss in £ of the current open positions
-
get_open_positions_pl_perc
() → Optional[float][source]
Return the sum profit/loss in % of the current open positions
-
get_portfolio_path
() → pathlib.Path[source]
Return the complete filepath of the portfolio
-
get_portfolio_pl
() → Optional[float][source]
Return the profit/loss in £ of the portfolio over the deposited cash
-
get_portfolio_pl_perc
() → Optional[float][source]
Return the profit/loss in % of the portfolio over deposited cash
-
get_total_value
() → Optional[float][source]
Return the value of the whole portfolio as cash + holdings
-
get_trade_history
() → List[tradingmate.model.trade.Trade][source]
Return the trade history as a list
-
has_unsaved_changes
() → bool[source]
Return True if the portfolio has unsaved changes, False othersise
-
save_portfolio
(filepath: pathlib.Path) → None[source]
Save the portfolio at the given filepath
2.2.3. DatabaseHandler
-
class
tradingmate.model.
DatabaseHandler
(config: tradingmate.model.configuration.ConfigurationManager, trading_log_path: pathlib.Path)[source]
Handles the IO operation with the database to handle persistent data
-
add_trade
(trade: tradingmate.model.trade.Trade) → None[source]
Add a trade to the database
-
delete_trade
(trade_id: str) → None[source]
Remove the trade from the trade history
-
get_db_filepath
() → pathlib.Path[source]
Return the database filepath
-
get_trades_list
() → List[tradingmate.model.trade.Trade][source]
Return the list of trades stored in the db
-
get_trading_log_name
() → str[source]
Return the trading log database name
-
read_data
(filepath: pathlib.Path = None)[source]
Read the trade history from the json database and return the list of trades
- filepath: optional, if not set the configured path will be used
-
write_data
(filepath: pathlib.Path = None) → bool[source]
Write the trade history to the database
2.2.4. StockPriceGetter
-
class
tradingmate.model.
StockPriceGetter
(config: tradingmate.model.configuration.ConfigurationManager, update_callback: Callable[[], None])[source]
Worker thread that fetches market live prices from an online source
-
task
() → None[source]
The task done by this thread - override in subclasses
2.2.5. ConfigurationManager
-
class
tradingmate.model.
ConfigurationManager
(config_path: pathlib.Path)[source]
Class that loads the configuration and credentials files exposing
methods to provide the configurable parameters
-
get_alpha_vantage_api_key
() → str[source]
Get the alphavantage api key
-
get_alpha_vantage_base_url
() → str[source]
Get the alphavantage API base URI
-
get_alpha_vantage_polling_period
() → float[source]
Get the alphavantage configured polling period
-
get_configured_stocks_interface
() → str[source]
Get the active configured stock interface
-
get_credentials_path
() → pathlib.Path[source]
Get the filepath of the credentials file
-
get_editable_config
() → Dict[str, Any][source]
Get a dictionary containing the editable configuration parameters
-
get_log_filepath
() → pathlib.Path[source]
Get the filepath of the log file
-
get_polling_period
() → float[source]
Get the application polling period
-
get_trading_database_path
() → List[pathlib.Path][source]
Get the filepath of the trading log file
-
get_yfinance_polling_period
() → float[source]
Get the yfinance configured polling period
-
save_settings
(config: Dict[str, Any]) → bool[source]
Save the edited configuration settings
2.2.6. Trade
-
class
tradingmate.model.
Trade
(date: datetime.datetime, action: tradingmate.utils.enums.Actions, quantity: float, symbol: str, price: float, fee: float, sdr: float, notes: str, id: str = None)[source]
Represent a trade action
2.3. Broker
The broker
module contains the interfaces to connect to the online market brokers
2.3.1. AlphaVantageInterface
-
class
tradingmate.model.broker.
AlphaVantageInterface
(config: tradingmate.model.configuration.ConfigurationManager)[source]
class providing interfaces to request data from AlphaVantage
-
get_prices
(market_id: str, interval: tradingmate.model.broker.alpha_vantage_interface.AVInterval = <AVInterval.DAILY: 'daily'>) → Optional[Dict[str, Dict[str, str]]][source]
Return the price time series of the requested market with the interval
granularity. Return None if the interval is invalid
2.3.2. YFinanceInterface
-
class
tradingmate.model.broker.
YFinanceInterface
(config: tradingmate.model.configuration.ConfigurationManager)[source]
2.3.3. StocksInterface
-
class
tradingmate.model.broker.
StocksInterface
[source]
2.3.4. StocksInterfaceFactory
-
class
tradingmate.model.broker.
StocksInterfaceFactory
(config: tradingmate.model.configuration.ConfigurationManager)[source]
Factory for stocks interface class
2.4. UI
The ui
module contains the components that compose the User Interface
of TradingMate.
2.4.1. DataInterface
-
class
tradingmate.ui.
DataInterface
(client: tradingmate.ui.trading_mate_client.TradingMateClient, data_callback: Callable[[List[tradingmate.model.portfolio.Portfolio]], None])[source]
Thread that periodically requests the most recent data from TradingMate
server notify the parent object through a callback function
-
task
()[source]
The task done by this thread - override in subclasses
2.4.2. TradingMateClient
-
class
tradingmate.ui.
TradingMateClient
(server: tradingmate.trading_mate.TradingMate)[source]
Client interface to the TradingMate business logic
-
get_portfolios
() → List[tradingmate.model.portfolio.Portfolio][source]
Get the loaded portfolios
-
get_settings_event
() → None[source]
Request server to fetch TradingMate settings
-
is_portfolio_auto_refreshing
(portfolio_id: str) → bool[source]
Return True if portfolio has data auto refresh enabled, False otherwise
-
manual_refresh_event
(portfolio_id: str) → None[source]
Request server to refresh portfolio data
-
new_trade_event
(new_trade: tradingmate.model.trade.Trade, portfolio_id: str) → None[source]
Push new trade notification to the server
-
open_portfolio_event
(filepath: pathlib.Path) → None[source]
Request server to open a portfolio
-
save_portfolio_event
(portfolio_id: str, filepath: pathlib.Path) → None[source]
Request server to save a portfolio
-
save_settings_event
(settings: Dict[str, Any]) → None[source]
Request server to save the settings
-
set_auto_refresh_event
(value: bool, portfolio_id: str) → None[source]
Set server to automatically update data for the portfolio
-
stop
() → None[source]
Handle stop event
-
unsaved_changes
() → bool[source]
Request if open portfolios have unsaved changes and return True
2.4.3. GTK
The gtk
module contains the gtk components and widgets of the
graphical interface. They are not documented due to a Sphinx issue when
importing the gi
Python module
2.5. Utils
The utils
module contains all the utlity components.
2.5.1. Enums
-
class
tradingmate.utils.
Actions
[source]
An enumeration.
-
class
tradingmate.utils.
Markets
[source]
An enumeration.
-
class
tradingmate.utils.
Messages
[source]
An enumeration.
2.5.2. TaskThread
-
class
tradingmate.utils.
TaskThread
[source]
Thread that executes a task every N seconds
-
cancel_timeout
()[source]
Cancel the timeout and run the task
-
enable
(enabled: bool) → None[source]
Disable/enable this thread
-
run
() → None[source]
Method representing the thread’s activity.
You may override this method in a subclass. The standard run() method
invokes the callable object passed to the object’s constructor as the
target argument, if any, with sequential and keyword arguments taken
from the args and kwargs arguments, respectively.
-
setInterval
(interval: float) → None[source]
Set the number of seconds we sleep between executing our task
-
shutdown
() → None[source]
Stop this thread
-
task
() → None[source]
The task done by this thread - override in subclasses
2.5.3. Utils
-
class
tradingmate.utils.
Utils
[source]
Class that provides utility functions
-
static
get_install_path
() → str[source]
Returns the installation path of TradingMate
-
static
load_json_file
(filepath: pathlib.Path) → Any[source]
Load a JSON formatted file from the given filepath
- filepath The filepath including filename and extension
- Return a dictionary of the loaded json
-
static
write_json_file
(filepath: pathlib.Path, data: Any) → bool[source]
Write a python dict object into a file with json formatting
-filepath The filepath
-data The python dict to write
- Return True if succed, False otherwise