Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Autonomous stocks trading script

License

NotificationsYou must be signed in to change notification settings

ilcardella/TradingBot

Repository files navigation

Build StatusDocumentation StatusDocker Pulls

This is an attempt to create an autonomous market trading script using the IGREST API and any other available data source for market prices.

TradingBot is meant to be a "forever running" process that keepsanalysing the markets taking actions whether some conditions are met.It is halfway from an academic project and a real useful piece ofsoftware, I guess I will see how it goes :)

The main goal of this project is to provide the capability towrite a custom trading strategy with the minimum effort.TradingBot handles all the boring stuff.

All the credits for theWeightedAvgPeak strategy goes to GitHub user @tg12.

Dependencies

  • Python 3.6+
  • Poetry (only for development)
  • Docker (optional)

View filepyproject.toml for the full list of required python packages.

Install

First if you have not done yet, install python:

sudo apt-get updatesudo apt-get install python3

Clone this repo and installTradingBot by running the following command fromthe repository root folder

make install-system

Setup

Login to your IG Dashboard

  • Obtain an API KEY from the settings panel
  • If using the demo account, create demo credentials
  • Take note of your spread betting account ID (demo or real)
  • (Optional) Visit AlphaVantage website:https://www.alphavantage.co and request a free api key
  • Insert these info in a file called.credentials

This must be in json format

{"username":"username","password":"password","api_key":"apikey","account_id":"accountId","av_api_key":"apiKey"}
  • Copy the.credentials file into the${HOME}/.TradingBot/config folder
  • Revoke permissions to read the file
cd configsudo chmod 600 ${HOME}/.TradingBot/config/.credentials

Market source

There are different ways to define which markets to analyse with TradinbgBot. You can select your preferred option in the configuration file under themarket_source section:

  • Local file

You can create a fileepic_ids.txt containg IG epics of the companies you want to monitor.You need to copy this file into the${HOME}/.TradingBot/data folder.

  • Watchlist

You can use an IG watchlist, TradingBot will analyse every market added to the selected watchlist

  • API

TradingBot navigates the IG markets dynamically using the available API call to fetch epic ids.

Configuration file

The configuration file is in theconfig folder and it contains several configurable parameter to personalisehow TradingBot work. It is important to setup this file appropriately in order to avoid unexpected behaviours.

Start TradingBot

You can start TradingBot with

trading_bot

You can start it in detached mode letting it run in the background with

nohup trading_bot >/dev/null 2>&1 &

Close all the open positions

trading_bot --close-positions [-c]

Stop TradingBot

To stop a TradingBot instance running in the background

ps -ef | grep trading_bot | xargs kill -9

Uninstall

You can usepip to uninstallTradingBot:

sudo pip3 uninstall TradingBot

Development

TheMakefile is the entrypoint for any development action.Poetry handles the dependency management and thepyproject.toml contains the requiredpython packages.

Installpoetry and create the virtual environment:

cd /path/to/repositorymake install

Test

You can run the test from the workspace with:

make test

Documentation

The Sphinx documentation contains further details about each TradingBot modulewith source code documentation of each class member.Explanation is provided regarding how to create your own Strategy and how to integrateit with the system.

Read the documentation at:

https://tradingbot.readthedocs.io

You can build it locally with:

make docs

The generated html files will be indocs/_build/html.

Automate

NOTE: TradingBot monitors the market opening hours and suspend the trading when the market is closed. Generally you should NOT need a cron job!

You can set up the crontab job to run and kill TradinBot at specific times.The only configuration required is to edit the crontab file adding the preferred schedule:

crontab -e

As an example this will start TradingBot at 8:00 in the morning and will stop it at 16:35 in the afternoon, every week day (Mon to Fri):

00 08** 1-5 trading_bot35 16** 1-5kill -9$(ps| grep trading_bot| grep -v grep| awk'{ print $1 }')

NOTE: Remember to set the correct timezone in your machine!

Docker

You can run TradingBot in aDocker container.

The Docker images are configured with a default TradingBot configuration and itdoes not have any.credentials files.You must mount these files when running the Docker container

Pull

The Docker images are available in the officialDocker Hub.CurrentlyTradingBot supports bothamd64 andarm64 architectures.You can pull the Docker image directly from the Docker Hub.Latest version:

docker pull ilcardella/tradingbot:latest

Tagged version:

docker pull ilcardella/tradingbot:v2.0.0

Build

You can build the Docker image yourself using theDockerfile in thedocker folder:

cd /path/to/repomake docker

Run

As mentioned above, it's important that you configure TradingBot before starting it.Once the image is available you can runTradingBot in a Docker container mounting the configuration files:

docker run -d \    -v /path/to/trading_bot.toml:/.TradingBot/config/trading_bot.toml \    -v /path/to/.credentials:/.TradingBot/config/.credentials \    tradingbot:latest

You can also mount the log folder to store the logs on the host adding-v /host/folder:/.TradingBot/log

Contributing

Any contribution or suggestion is welcome, please follow the suggested workflow.

Pull Requests

To add a new feature or to resolve a bug, create a feature branch from themaster branch.

Commit your changes and if possible add unit/integration test cases.Eventually push your branch and create a Pull Request againstmaster.

If you instead find problems or you have ideas and suggestions for futureimprovements, please open an Issue. Thanks for the support!

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp