Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev Merge #67

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 9 additions & 16 deletions marconi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
import os
from marconi.market import RunningMarket
from marconi.brain import Brain, SmartMarket
from marconi.poloniex import wsPoloniex, Coach
from marconi.poloniex import Poloniex, wsPoloniex, Coach, PoloniexError
from marconi.trading import StopLimit, Loaner, Liquidator
from marconi.tools import *

__version__ = '0.1.3'
Expand Down Expand Up @@ -181,26 +181,19 @@ def load(self):
self.markets[m].load(location=os.path.join(self.configDir,
m))

def run(self, train=False):
def run(self):
self._running = True
for m in self.markets:
if train:
self.markets[m].train()
self.markets[m].api.startWebsocket()
self.markets[m].start()

def stop(self):
def stop(self, save=True):
for m in self.markets:
self.markets[m].api.stopWebsocket()
self.markets[m].stop()
if save:
self.save()

def start(self, train=False):
self.run(train)
while self._running:
try:
sleep(2)
except:
self._running = False
break
self.stop()
self.save()
if train:
self.train()
self.run()
45 changes: 24 additions & 21 deletions marconi/market/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from __future__ import print_function
from ..tools import (getMongoColl, time, pd,
pymongo, RD, GR, sleep, Thread, SATOSHI,
TRADE_MIN, getLogger, UTCstr2epoch)
Expand Down Expand Up @@ -76,7 +75,7 @@ def openOrders(self):
""" Get open orders from poloniex """
return self.api.returnOpenOrders(self.pair)

def chart(self, start=False, zoom=False, indica=False, v=False):
def chart(self, start=False, zoom=False, indica=False):
""" returns chart data in a dataframe from mongodb, updates/fills the
data, the date column is the '_id' of each candle entry, and
the date column has been removed. Use 'start' to restrict the amount
Expand All @@ -98,28 +97,26 @@ def chart(self, start=False, zoom=False, indica=False, v=False):
# no entrys found, get all 5min data from poloniex
if not last:
logger.warning('%s collection is empty!', dbcolName)
logger.info('Getting new %s candles from Poloniex...', self.pair)
logger.debug('Getting new %s candles from Poloniex...', self.pair)
new = self.api.returnChartData(self.pair,
period=60 * 5,
start=time() - self.api.YEAR * 13)
else:
logger.info('Getting new %s candles from Poloniex...', self.pair)
logger.debug('Getting new %s candles from Poloniex...', self.pair)
new = self.api.returnChartData(self.pair,
period=60 * 5,
start=int(last['_id']))
# add new candles
updateSize = len(new)
logger.info('Updating %s with %s new entrys!...',
dbcolName, str(updateSize))

if updateSize > 10000:
logger.info('Updating %s with %s new entrys!... This could take some time...',
dbcolName, str(updateSize))
for i in range(updateSize):
if v and not i % 2:
print('%d/%d' % (i + 1, updateSize), end='\r')
db.update_one({'_id': new[i]['date']}, {
"$set": new[i]}, upsert=True)
if v:
print('\n', end='\r')

logger.info('Getting %s chart data from db', self.pair)
logger.debug('Getting %s chart data from db', self.pair)
# make dataframe
df = pd.DataFrame(list(db.find({"_id": {"$gt": start}}
).sort('timestamp', pymongo.ASCENDING)))
Expand All @@ -145,7 +142,7 @@ def chart(self, start=False, zoom=False, indica=False, v=False):

def addIndicators(self, df, indica={}):
# add indicators
logger.info('Adding indicators to %s dataframe', self.pair)
logger.debug('Adding indicators to %s dataframe', self.pair)
# save macd for last if it is defined
macdC = False
if 'macd' in indica:
Expand Down Expand Up @@ -178,8 +175,8 @@ def myTradeHistory(self, query=None):
hist = self.api.returnTradeHistory(self.pair, start=old['date'] - 1)

if len(hist) > 0:
logger.info('%d new %s trade database entries',
len(hist), self.pair)
logger.debug('%d new %s trade database entries',
len(hist), self.pair)

for trade in hist:
_id = trade['globalTradeID']
Expand Down Expand Up @@ -327,17 +324,23 @@ def moveToFront(self, orderNumber, offset=SATOSHI):
rate = float(self.tick['lowestAsk'])
# our order is already the front
if rate == order['rate']:
return order
# update rate
rate += -offset
# move rate higher by offset
rate += offset
# order is not in front
else:
# move rate lower by offset
rate += -offset
if order['type'] == 'buy':
rate = float(self.tick['highestBid'])
# our order is already the front
if rate == order['rate']:
return order
# update rate
rate += offset
logger.info('Moving %s order %s', self.pair, str(orderNumber))
# move rate lower by offset
rate += -offset
# order is not in front
else:
# move rate higher by offset
rate += offset
logger.debug('Moving %s order %s', self.pair, str(orderNumber))
return self.api.moveOrder(orderNumber, rate)


Expand Down
5 changes: 2 additions & 3 deletions marconi/poloniex/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,10 +643,10 @@ def _on_message(self, ws, message):

if message[0] == 1002:
if message[1] == 1:
return logger.info('Subscribed to ticker')
return logger.debug('Subscribed to ticker')

if message[1] == 0:
return logger.info('Unsubscribed to ticker')
return logger.debug('Unsubscribed to ticker')

data = message[2]
data = [float(dat) for dat in data]
Expand Down Expand Up @@ -710,7 +710,6 @@ def startWebsocket(self):
self._t._running = True
self._t.start()
logger.info('Websocket thread started')
logger.debug(self._ws.url)

def stopWebsocket(self):
""" Stop/join the websocket thread """
Expand Down
6 changes: 3 additions & 3 deletions marconi/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
#
# core ---------------------------------------------------------------------
import sys
import os
import logging
import json
from pathlib import Path
from functools import wraps
from math import floor, ceil
from math import pi as PI
Expand Down Expand Up @@ -92,11 +94,9 @@ def GY(text):

def getHomeDir():
try:
from pathlib import Path
return str(Path.home())
except:
from os.path import expanduser
return expanduser("~user")
return os.path.expanduser("~")


getLogger = logging.getLogger
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#
from setuptools import setup
setup(name='marconi',
version='0.1.2',
version='0.1.3',
description='Poloniex API trader for Python 3',
url='https://github.com/s4w3d0ff/marconibot',
author='s4w3d0ff',
Expand Down