Quick Start#

Installation#

To get started with the package, you can install it using pip.

pip install autofold

Setting Up the API Key#

After installing the package, you’ll need to set up your API key. You should set this key as an environment variable, named MANIFOLD_API_KEY.

Unix/Linux/macOS#

If you’re using a Unix-like operating system, you can set the environment variable in your shell session using the export command:

export MANIFOLD_API_KEY="your_api_key_here"

You may also want to add this command to your .bashrc or .zshrc file to ensure the variable is set whenever you open a new terminal window.

Windows#

On Windows, you can set an environment variable using the setx command:

setx MANIFOLD_API_KEY "your_api_key_here"

Note that this will set the environment variable permanently but it won’t affect currently open command prompts. You’ll need to restart any open command prompts or open a new one to see the change.

Quick Start#

AutomationBot#

The AutomationBot is responsible for starting, stopping and maintaining threads and connections to the manifold API, manifold database and manifold subscriber. Additionally, AutomationBot is reponsible for maintaining, adding, removing, starting and stopping automations. This class provides everything you need to start writing automations.

Initialization#

Create an instance of the AutomationBot class.

automation_bot = AutomationBot()

Instantiate your automation. (Details on automations in the next section)

my_automation = MyStrategy()

Register your automation with the bot

automation_bot.register_automation(my_automation, "my_strategy")

Start the bot

automation_bot.start()

Optionally add something blocking to prevent the main thread from exiting and put a stop() call after.

input('Press any key to stop')
automation_bot.stop()

Automations#

You can easily add your own automations by implementing a subclass of Automation:

class Automation(ABC):

   def __init__(self, db_name: str=""):
      '''
      Initializer for the automation class.

      :param str db_name: Required. The name of the database file to use, without the extension.


      Attributes:
      -----------
      - ``automation_bot``: The ManifoldBot instance.
      - ``manifold_api``: The ManifoldAPI instance extracted from automation_bot.
      - ``manifold_db_reader``: The ManifoldDatabaseReader instance extracted from automation_bot.
      - ``manifold_subscriber``: The ManifoldSubscriber instance extracted from automation_bot.
      - ``db``: The TinyDB instance for this automation.
      '''
      self.db_name = db_name

   @abstractmethod
   def start(self, *args, **kwargs):
      '''
      Abstract method to start the automation.

      .. note::
         This method must be implemented in subclasses.

      :param args: Additional positional arguments.
      :param kwargs: Additional keyword arguments.
      '''
      pass

   @abstractmethod
   def stop(self, *args, **kwargs):
      '''
      Abstract method to stop the automation.

      .. note::
         This method must be implemented in subclasses.

      :param args: Additional positional arguments.
      :param kwargs: Additional keyword arguments.
      '''
      pass

Warning

Automations MUST be registered with the bot for the object attributes to be set. This must be done before you run the automation.

Note

All child classes of automation are provided a local tinydb for non-volatile storage if needed. Note that tinydb is NOT threadsafe; proper access safety should be used when accessing data between automations. Feel free to use your own storage medium as you see fit.

An instance of AutomationBot, ManifoldAPI, ManifoldDatabaseReader and ManifoldSubscriber is provided to each automation.

When the AutomationBot is started, by default it will call the run() function for each automation. Likewise, when the program gets a shutdown signal it will call the stop() function for each automation.

An example automation is available in automations/bet_automation.py