I'm not very interested by you "speaker" strategy ... for now... but maybe one day it could be useful...
I tried to play with a Python wrapper for TA-Lib
http://ta-lib.org/http://mrjbq7.github.io/ta-lib/this wrapper is total...
you just need to install cython, TA-Lib, and this wrapper
I just did a test strategy for now
"""
trading robot breadboard
"""
import goxapi
import datetime
import numpy as np
import talib
#import pandas as pd
class Strategy(goxapi.BaseObject):
# pylint: disable=C0111,W0613,R0201
def __init__(self, gox):
goxapi.BaseObject.__init__(self)
self.signal_debug.connect(gox.signal_debug)
gox.signal_keypress.connect(self.slot_keypress)
gox.signal_strategy_unload.connect(self.slot_before_unload)
gox.signal_ticker.connect(self.slot_tick)
gox.signal_depth.connect(self.slot_depth)
gox.signal_trade.connect(self.slot_trade)
gox.signal_userorder.connect(self.slot_userorder)
gox.orderbook.signal_owns_changed.connect(self.slot_owns_changed)
gox.signal_wallet.connect(self.slot_wallet_changed)
gox.signal_orderlag.connect(self.slot_orderlag)
self.gox = gox
self.name = "%s.%s" % \
(self.__class__.__module__, self.__class__.__name__)
self.debug("%s loaded" % self.name)
self.is_lagging = True
def __del__(self):
self.debug("%s unloaded" % self.name)
def slot_before_unload(self, _sender, _data):
self.debug("%s before unload" % self.name)
def slot_keypress(self, gox, (key)):
if key == ord("t"):
#self.debug("Test")
len_hist = gox.history.length()
self.debug("Test history with {N} candles".format(N=len_hist))
#z = np.zeros(len)
#self.df = pd.DataFrame(z)
#opn = np.array(gox.history.candles)
#iterable = (gox.history.candles[i].tim for i in range(len_hist))
#a_tim = np.fromiter(iterable, ???)
rng = range(len_hist)
iterable = (gox.history.candles[i].opn for i in rng)
a_opn = np.fromiter(iterable, np.float)
iterable = (gox.history.candles[i].hig for i in rng)
a_hig = np.fromiter(iterable, np.float)
iterable = (gox.history.candles[i].low for i in rng)
a_low = np.fromiter(iterable, np.float)
iterable = (gox.history.candles[i].cls for i in rng)
a_cls = np.fromiter(iterable, np.float)
iterable = (gox.history.candles[i].vol for i in rng)
a_vol = np.fromiter(iterable, np.float)
a_sma = talib.SMA(a_opn)
"""
self.tim = tim
self.opn = opn
self.hig = hig
self.low = low
self.cls = cls
self.vol = vol
"""
#self.debug(gox.history.candles[len-1].cls)
#self.debug(self.df)
self.debug(a_opn)
#self.debug(a_sma)
else:
self.debug("someone pressed the %s key" % chr(key))
def slot_tick(self, gox, (bid, ask)):
pass
def slot_depth(self, gox, (typ, price, volume, total_volume)):
pass
def slot_trade(self, gox, (date, price, volume, typ, own)):
"""a trade message has been received. Note that this might come
before the orderbook.owns list has been updated, don't rely on the
own orders and wallet already having been updated when this fires."""
pass
def slot_userorder(self, gox, (price, volume, typ, oid, status)):
"""this comes directly from the API and owns list might not yet be
updated, if you need the new owns list then use slot_owns_changed"""
pass
def slot_owns_changed(self, orderbook, _dummy):
"""this comes *after* userorder and orderbook.owns is updated already"""
pass
def slot_wallet_changed(self, gox, _dummy):
"""this comes after the wallet has been updated"""
pass
def slot_orderlag(self, dummy_sender, (usec, text)):
"""slot for order_lag messages"""
lag = datetime.timedelta(microseconds=usec)
lag_max = datetime.timedelta(seconds=60)
#self.debug(usec)
if lag>lag_max:
self.debug("MtGox is lagging {lag}".format(lag=lag))
self.is_lagging = True
else:
self.is_lagging = False
I was very surprised to see that candles are stored in a list...
why not using a Numpy Array ?
It will much efficient to implement indicators on top of a Numpy array than on top
of a Python list.
You should add a length for array as Numpy arrays have a fixed size (contrary to python list).
I was also surprised to see output for price such as
2013-04-26 18:02:23,152:DEBUG:test_strategy.Strategy:[ 13399024. 13590000. 13680000. 13610000. 13649999. 13680000.
In my mind (but I ever said something similar) in strategy" I should have "real" values.
I think that a "layer" is actually missing but I don't know how to implement it.