πŸ—Ώ TalkyTrader#

TalkyTrader πŸͺ™πŸ—Ώ#

Bot Launcher and API

Talky Trader is an app built with FastAPI tiangolo/fastapi

It allows you to connect to a messaging chat platform to interact with trading module.

tt.app.lifespan(app)[source]#

An asynchronous context manager that manages the lifespan of the application.

Parameters: - app: The application to manage the lifespan of.

Returns: - None

This function creates an event loop, starts a task to run the bot, and yields control to the caller. The caller is responsible for cleaning up any resources after the lifespan of the application has ended.

async tt.app.root(request: Request)[source]#

Get the root endpoint.

Returns:

The HTML response

Return type:

HTMLResponse

Note

If settings.ui_enabled is True, user will be redirected to the UI frontend

async tt.app.health_check()[source]#

End point to know if the API is up and running

async tt.app.webhook(request: Request)[source]#

Webhook endpoint to receive webhook requests with option to forward the data to another endpoint. Webhook endpoint to send order signal generated via http://tradingview.com or anyother platform. Endpoint is /webhook/settings.webhook_secret so in trading view you can add: https://YOURIPorDOMAIN/webhook/123456

Plugins#

class tt.plugins.plugin_manager.PluginManager(plugin_directory=None)[source]#

πŸ”Œ Plugins are the core of Talky Trader, they are loaded at startup, to interact with the trading platform.

Plugin Manager is used to load, start and dispatch message to the plugins

Parameters:
  • plugin_directory (str) – Directory

  • plugins (of) –

Returns:

None

__init__(plugin_directory=None)[source]#
load_plugins(plugin_names=None)[source]#

πŸ”ŒLoad plugins from directory

Parameters:
  • plugin_names (list) – List of plugin names to load

  • None (if) –

  • self.plugin_directory (load all plugins from) –

  • time (You can use this to minimize the load) –

  • CPU. (memory and) –

Returns:

None

Raises:

Exception – If there was an error loading a plugin

load_plugin(module, plugin_name)[source]#

Load a plugin from a module

Parameters:
  • module (Module) – Module

  • plugin_name (str) – Plugin name

Returns:

None

async start_all_plugins()[source]#

Start all plugins Start the scheduler

Returns:

None

async start_plugin(plugin)[source]#

Start a plugin

Parameters:

plugin (Plugin) – Plugin

Returns:

None

async process_message(message)[source]#

Send message to plugins

Parameters:

message (str) – Message

Returns:

None

class tt.plugins.plugin_manager.BasePlugin[source]#

⚑ Base Plugin Class use to be inherited by Talky Plugins especially the scheduling, notification and message handling.

Scheduling is manage via asyncz lib More info: tarsil/asyncz

Parameters:

None –

Returns:

None

__init__()[source]#
async start()[source]#
async stop()[source]#
async send_notification(message)[source]#
should_handle(message)[source]#

Returns True if the plugin should handle the message

Parameters:

message (str) – Message

Returns:

bool

async plugin_notify_schedule_task(user_name=None, frequency=8, function=None)[source]#

Handles task notification every X hours. Defaulted to 8 hours

Parameters:
  • user_name (str) – User name

  • frequency (int) – Frequency

  • function (function) – Function

Returns:

None

async plugin_notify_cron_task(user_name=None, user_day_of_week=None, user_hours=None, user_timezone=None, function=None)[source]#

Handles task cron scheduling for notification default set to Tuesday to Thursday at 6AM, 12PM and 6PM UTC via settings

Parameters:
  • user_name (str) – User name

  • user_day_of_week (str) – Day of week

  • user_hours (str) – Hours

  • user_timezone (str) – Timezone

  • function (function) – Function

Returns:

None

async handle_message(msg)[source]#
should_handle_timeframe()[source]#

Returns True if the current day and time are within the configured trading window. Use to control trading hours for plugins

Returns:

bool

Utils#

talky Utils

async tt.utils.send_notification(msg)[source]#

πŸ’¬ Notification via Apprise. Apprise endpoint URL can be a URL for the chat, a URL to an Apprise config or a URL to the Apprise API endpoint apprise_url = β€œtgram://BOTTOKEN/CHANNEL” apprise_url = β€œdiscord://token1/channel”

Parameters:

msg (str) – Message

Returns:

None

More info caronc/apprise

async tt.utils.run_bot()[source]#

πŸ€– Run the chat bot & the plugins via an asyncio loop.

Returns:

None

More info: mraniki/iamlistening

async tt.utils.start_plugins(plugin_manager)[source]#

πŸ”Œ Start all plugins.

Returns:

None

Refer to chat manager for plugin info

async tt.utils.start_bot(listener, plugin_manager, max_iterations=None)[source]#

πŸ‘‚ Start the chat listener and dispatch messages to plugins

Parameters:
  • listener (Listener) – Listener

  • plugin_manager (PluginManager) – PluginManager

  • max_iterations (int) – Max iterations

Returns:

None

async tt.utils.check_version()[source]#

Asynchronously checks the version of the GitHub repository.

This function sends a GET request to the specified GitHub repository URL and retrieves the latest version of the repository. It then compares the latest version with the current version (__version__) and logs the result.

Parameters:

None –

Returns:

None

UI#

tt.frontend.main.init(fastapi_app: FastAPI) None[source]#

Frontend component activated via settings.ui_enabled = True and using zauberzeug/nicegui

Initializes the UI for the provided fastapi_app instance.

Parameters:

fastapi_app (FastAPI) – The FastAPI application instance to be initialized.

Returns:

None

Note

This function defines a nested function show which is decorated with @ui.page(β€œ/show”, dark=True). The show function displays a label and a video using the ui.label and ui.video functions respectively. It also includes an HTML content that embeds a TradingView widget. The ui.html function is used to display the HTML content.

Finally, the ui.run_with function is called to run the FastAPI application with the provided fastapi_app instance.