Skip to content

Commit

Permalink
Merge pull request #3 from whittlem/main
Browse files Browse the repository at this point in the history
merge the upstream changes
  • Loading branch information
lazydroid authored Jun 17, 2021
2 parents b32c5d3 + 6969ffe commit 58cfebe
Show file tree
Hide file tree
Showing 7 changed files with 285 additions and 130 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ Upgrade version:
Upgrade library dependancies (if required):
- python3 -m pip install -r requirements.txt -U

## [2.31.1] - 2021-06-13

### Changed

-- Create default config if missing, avoid creating empty config

## [2.31.0] - 2021-06-13

### Changed
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[![Docker](https://github.com/whittlem/pycryptobot/actions/workflows/container.yml/badge.svg)](https://github.com/whittlem/pycryptobot/actions/workflows/container.yml/badge.svg) [![Tests](https://github.com/whittlem/pycryptobot/actions/workflows/unit-tests.yml/badge.svg)](https://github.com/whittlem/pycryptobot/actions/workflows/unit-tests.yml/badge.svg)

# Python Crypto Bot v2.32.0 (pycryptobot)
# Python Crypto Bot v2.35.0 (pycryptobot)

## Join our chat on Telegram

Expand Down
254 changes: 133 additions & 121 deletions models/ConfigBuilder.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""config.json Configuration Builder"""

from os.path import isfile
from json import dumps
from json import dump
from re import compile as re_compile
from sys import exit as sys_exit

Expand All @@ -20,29 +20,35 @@ def init(self) -> None:

config = {}

choice = input("Do you have API keys for the Coinbase Pro exchange (1=yes, 2=no:default)? ")
choice = input("Do you want to use the Coinbase Pro exchange (1=yes, 2=no:default)? ")
if choice == '1':
self._c = 1
config['coinbasepro'] = {}
config['coinbasepro']['api_url'] = 'https://api.pro.coinbase.com'

while 'api_key' not in config['coinbasepro']:
api_key = input("What is your Coinbase Pro API Key? ")
p = re_compile(r"^[a-f0-9]{32,32}$")
if p.match(api_key):
config['coinbasepro']['api_key'] = api_key

while 'api_secret' not in config['coinbasepro']:
api_secret = input("What is your Coinbase Pro API Secret? ")
p = re_compile(r"^[A-z0-9+\/]+==$")
if p.match(api_secret):
config['coinbasepro']['api_secret'] = api_secret

while 'api_passphrase' not in config['coinbasepro']:
api_passphrase = input("What is your Coinbase Pro API Passphrase? ")
p = re_compile(r"^[a-z0-9]{10,11}$")
if p.match(api_passphrase):
config['coinbasepro']['api_passphrase'] = api_passphrase
choice = input("Do you have API keys for the Coinbase Pro exchange (1=yes, 2=no:default)? ")
if choice == '1':
while 'api_key' not in config['coinbasepro']:
api_key = input("What is your Coinbase Pro API Key? ")
p = re_compile(r"^[a-f0-9]{32,32}$")
if p.match(api_key):
config['coinbasepro']['api_key'] = api_key

while 'api_secret' not in config['coinbasepro']:
api_secret = input("What is your Coinbase Pro API Secret? ")
p = re_compile(r"^[A-z0-9+\/]+==$")
if p.match(api_secret):
config['coinbasepro']['api_secret'] = api_secret

while 'api_passphrase' not in config['coinbasepro']:
api_passphrase = input("What is your Coinbase Pro API Passphrase? ")
p = re_compile(r"^[a-z0-9]{10,11}$")
if p.match(api_passphrase):
config['coinbasepro']['api_passphrase'] = api_passphrase
else:
config['coinbasepro']['api_key'] = '<fill in>'
config['coinbasepro']['api_secret'] = '<fill in>'
config['coinbasepro']['api_passphrase'] = '<fill in>'

config['coinbasepro']['config'] = {}

Expand Down Expand Up @@ -73,23 +79,28 @@ def init(self) -> None:
config['coinbasepro']['config']['live'] = 0


choice = input("Do you have API keys for the Binance exchange (1=yes, 2=no:default)? ")
choice = input("Do you want to use the Binance exchange (1=yes, 2=no:default)? ")
if choice == '1':
self._b = 1
config['binance'] = {}
config['binance']['api_url'] = 'https://api.binance.com'

while 'api_key' not in config['binance']:
api_key = input("What is your Binance API Key? ")
p = re_compile(r"^[A-z0-9]{64,64}$")
if p.match(api_key):
config['binance']['api_key'] = api_key

while 'api_secret' not in config['binance']:
api_secret = input("What is your Binance API Secret? ")
p = re_compile(r"^[A-z0-9]{64,64}$")
if p.match(api_secret):
config['binance']['api_secret'] = api_secret
choice = input("Do you have API keys for the Binance exchange (1=yes, 2=no:default)? ")
if choice == '1':
while 'api_key' not in config['binance']:
api_key = input("What is your Binance API Key? ")
p = re_compile(r"^[A-z0-9]{64,64}$")
if p.match(api_key):
config['binance']['api_key'] = api_key

while 'api_secret' not in config['binance']:
api_secret = input("What is your Binance API Secret? ")
p = re_compile(r"^[A-z0-9]{64,64}$")
if p.match(api_secret):
config['binance']['api_secret'] = api_secret
else:
config['binance']['api_key'] = '<fill in>'
config['binance']['api_secret'] = '<fill in>'

config['binance']['config'] = {}

Expand Down Expand Up @@ -118,93 +129,94 @@ def init(self) -> None:
else:
config['binance']['config']['live'] = 0

choice = input("Do you have a Telegram Token and Client ID (1=yes, 2=no:default)? ")
if choice == '1':
self._t = 1
config['telegram'] = {}

while 'token' not in config['telegram']:
token = input("What is your Telegram token? ")
p = re_compile(r"^\d{1,10}:[A-z0-9-_]{35,35}$")
if p.match(token):
config['telegram']['token'] = token

while 'client_id' not in config['telegram']:
client_id = input("What is your Telegram client ID? ")
p = re_compile(r"^-*\d{7,10}$")
if p.match(client_id):
config['telegram']['client_id'] = client_id

choice = input("Do you want to ever sell at a loss even to minimise losses (1:yes, 2=no:default)? ")
if choice == '1':
if self._c == 1:
config['coinbasepro']['config']['sellatloss'] = 1
if self._b == 1:
config['binance']['config']['sellatloss'] = 1

choice = input("Do you want to sell at the next resistance? (1:yes:default, 2=no)? ")
if choice != '2':
if self._c == 1:
config['coinbasepro']['config']['sellatresistance'] = 1
if self._b == 1:
config['binance']['config']['sellatresistance'] = 1

choice = input("Do you only want to trade in a bull market SMA50 > SMA200? (1:yes, 2=no:default)? ")
if choice != '1':
if self._c == 1:
config['coinbasepro']['config']['disablebullonly'] = 1
if self._b == 1:
config['binance']['config']['disablebullonly'] = 1

choice = input("Do you want to avoid buying when the price is too high? (1:yes:default, 2=no)? ")
if choice != '2':
if self._c == 1:
config['coinbasepro']['config']['disablebuynearhigh'] = 1
if self._b == 1:
config['binance']['config']['disablebuynearhigh'] = 1

choice = input("Do you want to disable the On-Balance Volume (OBV) technical indicator on buys? (1:yes:default, 2=no)? ")
if choice != '2':
if self._c == 1:
config['coinbasepro']['config']['disablebuyobv'] = 1
if self._b == 1:
config['binance']['config']['disablebuyobv'] = 1

choice = input("Do you want to disable the Elder-Ray Index on buys? (1:yes:default, 2=no)? ")
if choice != '2':
if self._c == 1:
config['coinbasepro']['config']['disablebuyelderray'] = 1
if self._b == 1:
config['binance']['config']['disablebuyelderray'] = 1

choice = input("Do you want to disable saving the CSV tracker on buy and sell events? (1:yes:default, 2=no)? ")
if choice != '2':
if self._c == 1:
config['coinbasepro']['config']['disabletracker'] = 1
if self._b == 1:
config['binance']['config']['disabletracker'] = 1

choice = input("Do you want to disable writing to the log file? (1:yes, 2=no:default)? ")
if choice != '2':
if self._c == 1:
config['coinbasepro']['config']['disablelog'] = 1
if self._b == 1:
config['binance']['config']['disablelog'] = 1

choice = input("Do you want the bot to auto restart itself on failure? (1:yes:default, 2=no)? ")
if choice != '2':
if self._c == 1:
config['coinbasepro']['config']['autorestart'] = 1
if self._b == 1:
config['binance']['config']['autorestart'] = 1

try:
config_json = dumps(config, indent=4)
fh = open('./config.json', 'w')
fh.write(config_json)
print("config.json saved!")
fh.close()
except Exception as err:
print(err)

return None
if self._b == 1 or self._c == 1:
choice = input("Do you have a Telegram Token and Client ID (1=yes, 2=no:default)? ")
if choice == '1':
self._t = 1
config['telegram'] = {}

while 'token' not in config['telegram']:
token = input("What is your Telegram token? ")
p = re_compile(r"^\d{1,10}:[A-z0-9-_]{35,35}$")
if p.match(token):
config['telegram']['token'] = token

while 'client_id' not in config['telegram']:
client_id = input("What is your Telegram client ID? ")
p = re_compile(r"^-*\d{7,10}$")
if p.match(client_id):
config['telegram']['client_id'] = client_id

choice = input("Do you want to ever sell at a loss even to minimise losses (1:yes, 2=no:default)? ")
if choice == '1':
if self._c == 1:
config['coinbasepro']['config']['sellatloss'] = 1
if self._b == 1:
config['binance']['config']['sellatloss'] = 1

choice = input("Do you want to sell at the next resistance? (1:yes:default, 2=no)? ")
if choice != '2':
if self._c == 1:
config['coinbasepro']['config']['sellatresistance'] = 1
if self._b == 1:
config['binance']['config']['sellatresistance'] = 1

choice = input("Do you only want to trade in a bull market SMA50 > SMA200? (1:yes, 2=no:default)? ")
if choice != '1':
if self._c == 1:
config['coinbasepro']['config']['disablebullonly'] = 1
if self._b == 1:
config['binance']['config']['disablebullonly'] = 1

choice = input("Do you want to avoid buying when the price is too high? (1:yes:default, 2=no)? ")
if choice != '2':
if self._c == 1:
config['coinbasepro']['config']['disablebuynearhigh'] = 1
if self._b == 1:
config['binance']['config']['disablebuynearhigh'] = 1

choice = input("Do you want to disable the On-Balance Volume (OBV) technical indicator on buys? (1:yes:default, 2=no)? ")
if choice != '2':
if self._c == 1:
config['coinbasepro']['config']['disablebuyobv'] = 1
if self._b == 1:
config['binance']['config']['disablebuyobv'] = 1

choice = input("Do you want to disable the Elder-Ray Index on buys? (1:yes:default, 2=no)? ")
if choice != '2':
if self._c == 1:
config['coinbasepro']['config']['disablebuyelderray'] = 1
if self._b == 1:
config['binance']['config']['disablebuyelderray'] = 1

choice = input("Do you want to disable saving the CSV tracker on buy and sell events? (1:yes:default, 2=no)? ")
if choice != '2':
if self._c == 1:
config['coinbasepro']['config']['disabletracker'] = 1
if self._b == 1:
config['binance']['config']['disabletracker'] = 1

choice = input("Do you want to disable writing to the log file? (1:yes, 2=no:default)? ")
if choice != '2':
if self._c == 1:
config['coinbasepro']['config']['disablelog'] = 1
if self._b == 1:
config['binance']['config']['disablelog'] = 1

choice = input("Do you want the bot to auto restart itself on failure? (1:yes:default, 2=no)? ")
if choice != '2':
if self._c == 1:
config['coinbasepro']['config']['autorestart'] = 1
if self._b == 1:
config['binance']['config']['autorestart'] = 1

try:
with open('./config.json', 'w') as fout :
dump(config, fout, indent=4)
print("config.json saved!")
except Exception as err:
print(err)
else:
print('You have to select the exchange you want to use.')

return None
7 changes: 6 additions & 1 deletion models/PyCryptoBot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import argparse
import json
import math
import os
import random
import re
import sys
Expand Down Expand Up @@ -53,6 +54,7 @@ def parse_arguments():
# optional options
parser.add_argument('--sellatresistance', action="store_true", help="sell at resistance or upper fibonacci band")
parser.add_argument('--autorestart', action="store_true", help="Auto restart the bot in case of exception")
parser.add_argument('--stats', action="store_true", help="display summary of completed trades")

# disable defaults
parser.add_argument('--disablebullonly', action="store_true", help="disable only buying in bull market")
Expand Down Expand Up @@ -172,7 +174,7 @@ def __init__(self, exchange='coinbasepro', filename='config.json'):
self.ema1226_6h_cache = None
self.sma50200_1h_cache = None

if args['init']:
if args['init'] or (filename == 'config.json' and not os.path.isfile(filename)):
# config builder
cb = ConfigBuilder()
cb.init()
Expand Down Expand Up @@ -569,6 +571,9 @@ def sellAtResistance(self) -> bool:

def autoRestart(self) -> bool:
return self.autorestart

def getStats(self) -> bool:
return self.stats

def getLastAction(self):
return self.last_action
Expand Down
7 changes: 7 additions & 0 deletions models/config/default_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ def defaultConfigParse(app, config):
app.autorestart = bool(config['autorestart'])
else:
raise TypeError('autorestart must be of type int')

if 'stats' in config:
if isinstance(config['stats'], int):
if bool(config['stats']):
app.stats = True
else:
raise TypeError('stats must be of type int')

if 'sellatloss' in config:
if isinstance(config['sellatloss'], int):
Expand Down
Loading

0 comments on commit 58cfebe

Please sign in to comment.