Package: trading-bots
Trading Bots 🤖A simple framework for bootstrapping yourCrypto Trading Botson Python 3.6+Disclaimer:Still at an early stage of development. Rapidly evolving APIs.Trading-Botsis a general purposemini-frameworkfor developing analgorithmic trading botoncrypto currencies, thus it makes no assumption of your trading goals.InstallationRequirementsmacOS, Windows or LinuxPython 3.6 or 3.7To install Trading-Bots, simply usepoetry(orpip, of course):poetry add trading-botsRemember to activate the virtual environmentpoetry shellGetting startedLet's learn by example creating a simple bot that fetches yourBitcoinbalance onBuda.com!We'll assume you have Trading-Bots installed already, and your virtual environment is active.Create a projectIf this is your first time, you’ll have to take care of some initial setup. Namely, you’ll need to
auto-generate some code that establishes a Trading-Bots project.From the command line, cd into a directory where you’d like to store your bots, then run the following command:bots-admin startproject

TRADING BOTS 🤖
===============

Name [MyAwesomeProject]: MyProject
Directory [.]: .This will create amy_projectdirectory in your current directory.Let’s look at whatstartprojectcreated:root/
    bots.py
    secrets.yml
    settings.yml
    my_project/
        __init__.pyThese files are:The outerroot/directory is just a container for your project. Its name doesn't matter to Trading-Bots; you can rename it to anything you like.bots.py: A handy CLI that lets you interact with this Trading-Bots project in various ways.secrets.yml: A configuration file to store your project secrets like API keys and walletsDON'T SHARE YOUR SECRETS WITH ANYONE!settings.yml: Global settings for this project.The innermy_project/directory is the actual Python package for your project.my_project/__init__.py: An empty file that tells Python that this directory should be considered a Python package.Create a new botNow that your "project" is set up, you're set to start doing work.Let's create a simple bot that fetches yourBitcoinbalance onBuda.com!Each bot you write in Trading-Bots consists of a Python package that follows a certain convention. Trading-Bots comes
with a utility that automatically generates the basic directory structure of a bot, so you can focus on writing code
rather than creating directories.Your bots can live anywhere on your Python path. In this tutorial, we’ll create our bot as a submodule ofmy_project.To create your bot, make sure you're in the same directory asbots.pyand type this command:python bots.py createbot

TRADING BOTS 🤖
===============

Name [MyAwesomeBot]: MyBot
Directory (your projects dir): my_projectThat’ll create a directorymy_bot, which is laid out like this:my_bot/
    __init__.py
    bot.py
    configs/
        default.ymlThis directory structure will house theMyBotbot.You'll also have to"install"your new bot, by adding it to the project'ssettings.ymlfile.settings.ymlinstalled_bots:-my_project.my_bot.bot.MyBotConfigure you Buda.com account'sAPI_KEYandAPI_SECRETontosecrets.ymlcredentials:You can request your API credentials on you account's profile onBuda.comsecrets.ymlcredentials:Buda:key:MY_API_KEYsecret:MY_API_SECRETWrite yout first Bot logicNow let's write the code to fetch the Bitcoin balance onBuda.comimplementing the Bot's algorithm. The Bot's logic resides in themy_project/my_bot/bot.pymodule created by thecreatebotcommand:my_project/my_bot/bot.py# Base class that all Bots must inherit fromfromtrading_bots.botsimportBot# The settings module contains all values from settings.yml and secrets.ymlfromtrading_bots.confimportsettings# API Wrapper for Buda.comfromtrading_api_wrappersimportBudaclassMyBot(Bot):# The label is a unique identifier you assign to your bot on Trading-Botslabel='MyBot'def_setup(self,config):# Get API_KEY and API_SECRET from credentialscredentials=settings.credentials['Buda']key=credentials['key']secret=credentials['secret']# Initialize a Buda Auth clientself.buda=Buda.Auth(key,secret)def_algorithm(self):# Fetch the Bitcoin balance from Buda.combalance=self.buda.balance('BTC')# Log the Bitcoin balanceself.log.info(f'I have{balance.amount.amount}BTC')def_abort(self):# Abort logic, runs on exceptionself.log.error(f'Something went wrong with MyBot!')Bot executionRun the bot!python bots.py run MyBot

TRADING BOTS 🤖
===============

Global settings
- Settings files: None
- Logs file: log.txt

Bot: MyBot
- Config file: default

Starting MyBot 1530691595: 2018-07-04 08:06:35
I have 1.0 BTC
Run time: .9972 seconds
Ending MyBot 1530691595: 2018-07-04 08:06:36Or put it to work in a loop!python bots.py loop MyBot --interval 5

TRADING BOTS 🤖
===============

Global settings
- Settings files: None
- Logs file: log.txt

Bot: MyBot
- Config file: default
- Interval: 5s

Starting MyBot 1530692725: 2018-07-04 08:25:25
I have 1.0 BTC
Run time: 1.3611 seconds
Ending MyBot 1530692725: 2018-07-04 08:25:26

Starting MyBot 1530692735: 2018-07-04 08:25:31
I have 1.0 BTC
Run time: 1.3632 seconds
Ending MyBot 1530692735: 2018-07-04 08:25:32Add more featuresWe can make our Bot a little more modular, let's now fetch our Ethereum balance adding acurrencykey onMyBotdefault config file onmy_project/my_bot/configs/default.yml:my_project/my_bot/configs/default.ymlcurrency:ETHNow use the newcurrencyconfig onMyBotby modifying the Bot's logic:my_project/my_bot/bot.pyfromtrading_bots.botsimportBotfromtrading_bots.confimportsettingsfromtrading_api_wrappersimportBudaclassMyBot(Bot):label='MyBot'def_setup(self,config):# Get currency from configself.currency=config['currency']# Get API_KEY and API_SECRET from credentialscredentials=settings.credentials['Buda']key=credentials['key']secret=credentials['secret']# Initialize a Buda Auth clientself.buda=Buda.Auth(key,secret)def_algorithm(self):# Fetch the currency balance from Buda.combalance=self.buda.balance(self.currency)# Log the currency balanceself.log.info(f'I have{balance.amount.amount}{self.currency}')def_abort(self):# Abort logic, runs on exceptionself.log.error(f'Something went wrong with MyBot!')Run the bot!python bots.py run MyBot

TRADING BOTS 🤖
===============

Global settings
- Settings files: None
- Logs file: log.txt

Bot: MyBot
- Config file: default

Starting MyBot 1530691595: 2018-07-04 08:06:35
I have 5.0 ETH
Run time: .9972 seconds
Ending MyBot 1530691595: 2018-07-04 08:06:36Or put it to work in a loop!python bots.py loop MyBot --interval 10

TRADING BOTS 🤖
===============

Global settings
- Settings files: None
- Logs file: log.txt

Bot: MyBot
- Config file: default
- Interval: 5s

Starting MyBot 1530692725: 2018-07-04 08:25:25
I have 5.0 ETH
Run time: 1.3611 seconds
Ending MyBot 1530692725: 2018-07-04 08:25:26

Starting MyBot 1530692735: 2018-07-04 08:25:31
I have 5.0 ETH
Run time: 1.3632 seconds
Ending MyBot 1530692735: 2018-07-04 08:25:32Bots CLITrading-Bots comes with a handyCLInamed...bots-admin!CommandsStart a projectpython bots.py startprojectTRADINGBOTS🤖===============Name[MyAwesomeProject]:MyProject
Directory[.]:.

Success:'MyProject'projectwassuccessfullycreatedon'.'startprojectcreates a Trading-Bots project directory structure for the given projectNAMEin the current directory.or optionally in the givenDIRECTORY.project_dir/
- project_name/
- bots.py
- secrets.yml
- settings.ymlCreate a botpython bots.py createbotTRADINGBOTS🤖===============Name[MyAwesomeBot]:MyBot
Directory(yourprojectsdir):my_project

Success:'MyBot'botwassuccessfullycreatedon'my_project'createbotcreates a Bot's directory structure for the given botNAMEin the current directory.or optionally in the givenDIRECTORY.project_dir/
- project_name/
- bots.py
- secrets.yml
- settings.ymlAfter creating or a new Bot, you must add it toinstalled_botsonsettings.yml:# settings.ymlinstalled_bots:-trading_bots.mybot.bot.MyBotRun bot oncepython bots.py run BOT [OPTIONS]Run a specifiedBOTby label. Options:-c, --configBot configuration filename (YAML format)-l, --logLog to this file--settingsGlobal settings files (YAML format)pythonbots.pyrunExample

TRADINGBOTS🤖===============Globalsettings
-Settingsfiles:None
-Logsfile:log.txt

Bot:Example
-Configfile:default

StartingExample1530691595:2018-07-0408:06:35
Thisisanexamplebot
Doingworkfor5seconds...
Finished!
Runtime:5.9972seconds
EndingExample1530691595:2018-07-0408:06:40Run bot in a looppython bots.py loop BOT [OPTIONS]Schedule aBOT(by label) to run on an interval. Options:-i, --intervalLoop interval (in seconds).-c, --configBot configuration filename (YAML format)-l, --logLog to this file--settingsGlobal settings files (YAML format)pythonbots.pyloopExample-i5TRADINGBOTS🤖===============Globalsettings
-Settingsfiles:None
-Logsfile:log.txt

Bot:Example
-Configfile:default
-Interval:5s

StartingExample1530692725:2018-07-0408:25:25
Thisisanexamplebot
Doingworkfor5seconds...
Finished!
Runtime:5.3611seconds
EndingExample1530692725:2018-07-0408:25:30

StartingExample1530692735:2018-07-0408:25:35
Thisisanexamplebot
Doingworkfor5seconds...
Finished!
Runtime:5.3632seconds
EndingExample1530692735:2018-07-0408:25:40

...DisclaimerUSE THE SOFTWARE AT YOUR OWN RISK. YOU ARE RESPONSIBLE FOR YOUR OWN MONEY. PAST PERFORMANCE IS NOT NECESSARILY INDICATIVE OF FUTURE RESULTS.THE AUTHORS AND ALL AFFILIATES ASSUME NO RESPONSIBILITY FOR YOUR TRADING RESULTS.