add README; minor refactoring

This commit is contained in:
gcarq 2017-05-18 01:46:08 +02:00
parent 6dae42d95d
commit d4c409a27f
4 changed files with 63 additions and 22 deletions

1
.gitignore vendored
View File

@ -77,5 +77,6 @@ config.json
preprocessor.py
*.sqlite
.env
.venv
.idea

View File

@ -1,14 +1,52 @@
# marginbot
# freqtrade
Simple High frequency trading bot for crypto currencies.
Currently supported exchanges: bittrex, poloniex (partly implemented)
Cryptocurrency micro trading bot
This software is for educational purposes only.
Don't risk money which you are afraid to lose.
The command interface is accessible via Telegram (not required).
Just register a new bot on https://telegram.me/BotFather
and enter the telegram `token` and your `chat_id` in `config.json`
Persistence is achieved through sqlite.
##### Telegram RPC commands:
* /start: Starts the trader
* /stop: Stops the trader
* /status: Lists all open trades
* /profit: Lists cumulative profit from all finished trades
##### Config
`trade_thresholds` is a JSON object where the key is a duration
in minutes and the value is the minimum profit threshold in
percent whether the bot should sell. See the example below:
```
cd marginbot/
cp config.json.example config.json
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
./main.py
"trade_thresholds": {
"2880": 0.005, # Sell after 48 hours if there is at least 0.5% profit
"1440": 0.01, # Sell after 24 hours if there is at least 1% profit
"720": 0.02, # Sell after 12 hours if there is at least 2% profit
"360": 0.02, # Sell after 6 hours if there is at least 2% profit
"0": 0.025 # Sell immediatly if there is at least 2.5% profit
},
```
Enter your API keys and tokens in `config.json`
The other values should be self-explanatory,
if not feel free to raise a github issue.
##### Prerequisites
* python3
* sqlite
##### Install
```
$ cd freqtrade/
# copy example config. Dont forget to insert your api keys
$ cp config.json.example config.json
$ python -m venv .env
$ source .env/bin/activate
$ pip install -r requirements.txt
$ ./main.py
```

View File

@ -1,4 +1,5 @@
{
"max_open_trades": 3,
"stake_amount": 0.05,
"dry_run": false,
"trade_thresholds": {

27
main.py
View File

@ -18,9 +18,10 @@ from exchange import get_exchange_api
from rpc.telegram import TelegramHandler
from utils import get_conf
__author__ = "gcarq"
__copyright__ = "gcarq 2017"
__license__ = "custom"
__license__ = "GPLv3"
__version__ = "0.5.1"
@ -90,11 +91,13 @@ class TradeThread(threading.Thread):
orders = api_wrapper.get_open_orders(trade.pair)
orders = [o for o in orders if o['id'] == trade.open_order_id]
if orders:
msg = 'There exists an open order for this trade: (total: {}, remaining: {}, type: {}, id: {})' \
.format(round(orders[0]['amount'], 8),
round(orders[0]['remaining'], 8),
orders[0]['type'],
orders[0]['id'])
msg = 'There exists an open order for {}: Order(total={}, remaining={}, type={}, id={})' \
.format(
trade,
round(orders[0]['amount'], 8),
round(orders[0]['remaining'], 8),
orders[0]['type'],
orders[0]['id'])
logger.info(msg)
continue
@ -102,7 +105,7 @@ class TradeThread(threading.Thread):
trade.open_order_id = None
# Check if this trade can be marked as closed
if close_trade_if_fulfilled(trade):
logger.info('No open orders found and trade is fulfilled. Marking as closed ...')
logger.info('No open orders found and trade is fulfilled. Marking {} as closed ...'.format(trade))
continue
# Check if we can sell our current pair
@ -187,11 +190,9 @@ def create_trade(stake_amount: float, exchange):
# Remove currently opened and latest pairs from whitelist
latest_trade = Trade.query.filter(Trade.is_open.is_(False)).order_by(Trade.id.desc()).first()
open_trades = Trade.query.filter(Trade.is_open.is_(True)).all()
if latest_trade and latest_trade.pair in whitelist:
whitelist.remove(latest_trade.pair)
logger.debug('Ignoring {} in pair whitelist'.format(latest_trade.pair))
for trade in open_trades:
trades = Trade.query.filter(Trade.is_open.is_(True)).all()
trades.append(latest_trade)
for trade in trades:
if trade.pair not in whitelist:
continue
whitelist.remove(trade.pair)
@ -220,7 +221,7 @@ def create_trade(stake_amount: float, exchange):
if __name__ == '__main__':
logger.info('Starting marginbot {}'.format(__version__))
logger.info('Starting freqtrade {}'.format(__version__))
TelegramHandler.listen()
while True:
time.sleep(0.5)