Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/conorturner/gekko
Something I probably didn't need to build but did anyway.
https://github.com/conorturner/gekko
Last synced: 4 days ago
JSON representation
Something I probably didn't need to build but did anyway.
- Host: GitHub
- URL: https://github.com/conorturner/gekko
- Owner: conorturner
- Created: 2023-10-12T14:34:02.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2023-11-17T11:52:19.000Z (about 1 year ago)
- Last Synced: 2023-11-17T12:39:55.196Z (about 1 year ago)
- Language: Python
- Size: 216 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Gekko - A Light Weight Online Trading Frameowork for IG Streaming API
## Environment Variables
The following ENV vars must be set: IG_API_KEY, IG_ACCOUNT, IG_USER, IG_PASS.
## Adding a new Strategy
To create a new strategy the Gekko class must be extended and the on_tick abstract method implemented.
An example of a martingale strategy is shown below.```python
from modules.core import Gekkoclass MartingaleGekko(Gekko):
epic: str
current_size = 0.5
current_direction = 'SELL'def __init__(self, epic, ig_service, price_stream, **kwargs):
super(MartingaleGekko, self).__init__(ig_service, price_stream, **kwargs)
self.epic = epicasync def on_tick(self):
now = datetime.datetime.now()
start = now - datetime.timedelta(seconds=self.tick)
rows = self.price_stream.get_records(self.epic, start, now)if len(rows) < 2:
returnif len(self.market.trades) != 0:
deal_id = list(self.market.trades.keys())[0]
profit = self.market.close(deal_id)['profit']
if profit >= 0:
self.current_direction = 'SELL' if self.current_direction == 'BUY' else 'BUY'
self.current_size = max(0.5, self.current_size / 2.0)
else:
self.current_size = min(4.0, self.current_size * 2.0)self.market.open(self.epic, self.current_direction, size=self.current_size)
```## Running the System
Two scripts must be started for the algorithms to begin trading, first multiplex.py is used to proxy the stream of prices from IG, allowing N children to connect to a single stream.
```bash
python3 multiplex.py
```Next the examples can be run using the following command. To add more strategies they must be added to run.py.
```bash
python3 run.py
```