2. Modules

Each section of this document provides the source code documentation of each component of TradingMate.

2.1. TradingMate

class TradingMate.TradingMate[source]

Main class that handles the interaction between the User Interface and the underlying business logic of the whole application

close_view_event()[source]

Callback function to handle close event of the user interface

delete_last_trade_event(portfolio_id)[source]

Callback function to handle delete of last trade request

get_portfolios()[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)[source]

Callback function to handle refresh data request

new_trade_event(new_trade, portfolio_id)[source]

Callback function to handle new trade event

open_portfolio_event(filepath)[source]

Callback function to handle request to open a new portfolio file

save_portfolio_event(portfolio_id, filepath)[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, portfolio_id)[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 Model.Holding.Holding(symbol, quantity, open_price=None)[source]
add_quantity(value)[source]

Add or subtract (if value is negative) the value to the holding quantity

2.2.2. Portfolio

class Model.Portfolio.Portfolio(config, trading_log_path)[source]
add_trade(trade)[source]

Add a trade into the Portfolio

clear()[source]

Reset the Portfolio clearing all data

compute_avg_holding_open_price(symbol, trades_list)[source]

Return the average price paid to open the current positon of the requested stock. Starting from the end of the history log, find the BUY transaction that led to to have the current quantity, compute then the average price of these transactions

get_cash_available()[source]

Return the available cash quantity in the portfolio [int]

get_cash_deposited()[source]

Return the amount of cash deposited in the portfolio [int]

get_holding_last_price(symbol)[source]

Return the last price for the given symbol

get_holding_list()[source]

Return a list of Holding instances held in the portfolio sorted alphabetically

get_holding_open_price(symbol)[source]

Return the last price for the given symbol

get_holding_quantity(symbol)[source]

Return the quantity held for the given symbol

get_holding_symbols()[source]

Return a list containing the holding symbols as [string] sorted alphabetically

get_holdings_value()[source]

Return the value of the holdings held in the portfolio

get_id()[source]

Return the portfolio unique id [string]

get_name()[source]

Return the portfolio name [string]

get_open_positions_pl()[source]

Return the sum profit/loss in £ of the current open positions

get_open_positions_pl_perc()[source]

Return the sum profit/loss in % of the current open positions

get_portfolio_pl()[source]

Return the profit/loss in £ of the portfolio over the deposited cash

get_portfolio_pl_perc()[source]

Return the profit/loss in % of the portfolio over deposited cash

get_total_value()[source]

Return the value of the whole portfolio as cash + holdings

get_trade_history()[source]

Return the trade history as a list

has_unsaved_changes()[source]

Return True if the portfolio has unsaved changes, False othersise

is_trade_valid(newTrade)[source]

Validate the new Trade request against the current Portfolio

reload()[source]

Load the portfolio from the database trade list

remove_last_trade()[source]

Remove the last trade from the Portfolio

save_portfolio(filepath)[source]

Save the portfolio at the given filepath

2.2.3. DatabaseHandler

class Model.DatabaseHandler.DatabaseHandler(config, trading_log_path)[source]

Handles the IO operation with the database to handle persistent data

add_trade(trade)[source]

Add a trade to the database

get_db_filepath()[source]

Return the database filepath

get_trades_list()[source]

Return the list of trades stored in the db

get_trading_log_name()[source]

Return the trading log database name

read_data(filepath=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

remove_last_trade()[source]

Remove the last trade from the trade history

write_data(filepath=None)[source]

Write the trade history to the database

2.2.4. StockPriceGetter

class Model.StockPriceGetter.StockPriceGetter(config, onNewPriceDataCallback)[source]
convert_market_to_alphavantage(symbol)[source]

Convert the market (LSE, etc.) into the alphavantage market compatible string i.e.: the LSE needs to be converted to LON

task()[source]

The task done by this thread - override in subclasses

2.3. UI

The UI module contains the components that compose the User Interface of TradingMate.

2.3.1. View

class UI.View.View(server)[source]
start()[source]

Start the User Interface

update_portfolio_tab(portfolio)[source]

Update the portfolio tab with the recent data

2.3.2. ShareTradingFrame

class UI.ShareTradingFrame.ShareTradingFrame(parent, portfolio_id)[source]

2.3.3. AddTradeDialogWindow

class UI.AddTradeDialogWindow.AddTradeDialogWindow(master, confirmCallback)[source]

2.3.4. WarningWindow

class UI.WarningWindow.WarningWindow(master, title, message)[source]

2.3.5. Widgets

class UI.Widgets.DatePicker(master, dateSelected)[source]
focus_set()[source]

Direct input focus to this widget.

If the application currently does not have the focus this widget will get the focus if the application gets the focus through the window manager.

2.4. Utils

The Utils module contains all the utlity components.

2.4.1. ConfigurationManager

class Utils.ConfigurationManager.ConfigurationManager(config_path)[source]

Class that loads the configuration and credentials json files exposing static methods to provide the configurable parameters

get_alpha_vantage_api_key()[source]

Get the alphavantage api key

get_alpha_vantage_base_url()[source]

Get the alphavantage API base URI

get_alpha_vantage_polling_period()[source]

Get the alphavantage configured polling period

get_credentials_path()[source]

Get the filepath of the credentials file

get_editable_config()[source]

Get a dictionary containing the editable configuration parameters

get_trading_database_path()[source]

Get the filepath of the trading log file

save_settings(config)[source]

Save the edited configuration settings

2.4.2. TaskThread

class Utils.TaskThread.TaskThread[source]

Thread that executes a task every N seconds

cancel_timeout()[source]

Cancel the timeout and run the task

enable(enabled)[source]

Disable/enable this thread

run()[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)[source]

Set the number of seconds we sleep between executing our task

shutdown()[source]

Stop this thread

task()[source]

The task done by this thread - override in subclasses

2.4.3. Trade

class Utils.Trade.Trade(date_string, action, quantity, symbol, price, fee, sdr, notes)[source]

2.4.4. Utils

class Utils.Utils.Callbacks[source]

An enumeration.

class Utils.Utils.Actions[source]

An enumeration.

class Utils.Utils.Messages[source]

An enumeration.

class Utils.Utils.Markets[source]

An enumeration.