wilfried
Sr. Member
Offline
Activity: 288
Merit: 250
ManualMiner
|
|
May 01, 2013, 01:35:10 PM |
|
hy i started to look into goxbot and i must admit, i dont get anything, but anyway i will reach the goal of my own little bot. plz help! in my strategy module i got (copied most of it of the 50/50-balance boot) import strategy import goxapi
class Strategy(strategy.Strategy):
"""a protfolio rebalancing bot""" def __init__(self, gox): strategy.Strategy.__init__(self, gox) self.temp_halt = False
def slot_before_unload(self, _sender, _data): pass
def slot_keypress(self, gox, (key)): if key == ord("b"): self.debug("canceling all rebalancing orders")
If key "b" is pressed goxtool displays: someone pressed key b, But it doesnt display "canceling all rebalancing orders". so, how to write messages to the log output? btw: is there an easy way to get rid of the Winconsole output in the main window? I am running tail on the log in a second window, so its just superfluid for me?
|
|
|
|
MtQuid
Newbie
Offline
Activity: 24
Merit: 0
|
|
May 01, 2013, 01:52:09 PM |
|
hy i started to look into goxbot and i must admit, i dont get anything, but anyway i will reach the goal of my own little bot. plz help! in my strategy module i got (copied most of it of the 50/50-balance boot) import strategy import goxapi
class Strategy(strategy.Strategy):
"""a protfolio rebalancing bot""" def __init__(self, gox): strategy.Strategy.__init__(self, gox) self.temp_halt = False
def slot_before_unload(self, _sender, _data): pass
def slot_keypress(self, gox, (key)): if key == ord("b"): self.debug("canceling all rebalancing orders")
If key "b" is pressed goxtool displays: someone pressed key b, But it doesnt display "canceling all rebalancing orders". so, how to write messages to the log output? btw: is there an easy way to get rid of the Winconsole output in the main window? I am running tail on the log in a second window, so its just superfluid for me? Your strategy file works perfectly though it won't pay the bills. Make sure you are loading it. e.g. python ./goxtool.py --protocol=websocket --strategy=_test.py And you should see the load and unload in goxtool.log 2013-05-01 14:47:32,433:DEBUG:_test.Strategy:_test.Strategy loaded ... 2013-05-01 14:47:38,099:DEBUG:_test.Strategy:canceling all rebalancing orders ... 2013-05-01 14:47:40,974:DEBUG:_test.Strategy:_test.Strategy unloaded
|
|
|
|
wilfried
Sr. Member
Offline
Activity: 288
Merit: 250
ManualMiner
|
|
May 01, 2013, 03:09:01 PM |
|
thx, so your log shows the message, mine doesnt; there is something wrong with my setup, but i cant figure out what. i.e. this script prints out the messages: http://www.rugatu.com/questions/14260/python-trading-bot-configuration-filemy bot does load - debug message appears: 2013-04-30 15:30:24,177:DEBUG:testbot.Strategy:testbot.Strategy unloaded and keystroke is registered, but the self.debug message doesnt print. If I use it i.e. with an non existent bot file (goxtool.py --strategy=anything.py it does not recognize the key pressed. I am stuck with this
|
|
|
|
prof7bit (OP)
|
|
May 01, 2013, 03:16:44 PM Last edit: May 01, 2013, 03:28:54 PM by prof7bit |
|
hy i started to look into goxbot and i must admit, i dont get anything, but anyway i will reach the goal of my own little bot. plz help! in my strategy module i got (copied most of it of the 50/50-balance boot) import strategy import goxapi
class Strategy(strategy.Strategy):
"""a protfolio rebalancing bot""" def __init__(self, gox): strategy.Strategy.__init__(self, gox) self.temp_halt = False
def slot_before_unload(self, _sender, _data): pass
def slot_keypress(self, gox, (key)): if key == ord("b"): self.debug("canceling all rebalancing orders")
This can't work. Please fix the formatting and indentations. And set your editor to 4 spaces, no tabs (recommended style, used by most others too) and dont ever mix tabs and spaces. You should first make yourself comfortable with some essential concepts of the Python programming language with simpler examples and simple isolated standalone programs, follow some tutorials. You should not attempt to ride a motorbike until you can safely ride a bicycle. This will avoid many frustrations.
|
|
|
|
wilfried
Sr. Member
Offline
Activity: 288
Merit: 250
ManualMiner
|
|
May 01, 2013, 03:25:11 PM |
|
Hy prof7bit, maybe i am blind, but i left the parts as they were in the rebalancing bot. what i saw now from looking into http://www.rugatu.com/questions/14260/python-trading-bot-configuration-fileis that the rebalancing bot does import strategy and in strategy.py there is a function slot_keypress in the bot of tarzan he doesnt import strategy and defines the class Strategy(goxapi.BaseObject): - but if thats the problem, how does the balancing bot work? thx
|
|
|
|
prof7bit (OP)
|
|
May 01, 2013, 03:38:15 PM |
|
Tarzan's bots are not autoritative. Also he wrote some comments that indicate he did not really understand goxtool yet at the time he attempted to write these bots. One can either make a copy of the existing strategy.py and use it directy or one can (more elegant and recommended) just derive a new class from it and override only the virtual slot methods that are needed for the bot and leave away the ones that are not needed (in Python all methods are always virtual and defining a method that exists in the inherited class will automatically override it) Also please paste your code as it is (it was clearly not formatted properly in your previous posting, and you know (because you followed my advice to learn Python) that in Python indentation is a critical part of the syntax. Also post *all* relevant log output)
|
|
|
|
wilfried
Sr. Member
Offline
Activity: 288
Merit: 250
ManualMiner
|
|
May 01, 2013, 03:41:32 PM Last edit: May 01, 2013, 03:54:13 PM by wilfried |
|
thx again, i re-pasted the rebalancing bot and now it works, still i cant see what the error in the above code was, anyway it prints out now. I got this code now: """ The portfolio rebalancing bot will buy and sell to maintain a constant asset allocation ratio of exactly 50/50 = fiat/BTC """
import strategy import goxapi
DISTANCE = 7 # percent price distance of next rebalancing orders MARKER = 7 # lowest digit of price to identify bot's own orders COIN = 1E8 # number of satoshi per coin, this is a constant.
def add_marker(price, marker): """encode a marker in the price value to find bot's own orders""" return price / 10 * 10 + marker
def has_marker(price, marker): """return true if the price value has the marker""" return (price % 10) == marker
def mark_own(price): """return the price with our own marker embedded""" return add_marker(price, MARKER)
def is_own(price): """return true if this price has our own marker""" return has_marker(price, MARKER)
class Strategy(strategy.Strategy): """a protfolio rebalancing bot""" def __init__(self, gox): strategy.Strategy.__init__(self, gox) self.temp_halt = False
def slot_before_unload(self, _sender, _data): pass
def slot_keypress(self, gox, (key)): """a key has been pressed"""
if key == ord("c"): # cancel existing rebalancing orders and suspend trading self.debug("canceling all rebalancing orders") self.temp_halt = True #self.cancel_orders()
could you please point me in the right direction, so i can do some reading, about the "virtual slots"- i suppose the functions in the Strategy Class are those slots, i.e. "slot_history_changed" - one is supposed to use this function to put some code in, when it is "fired" - what i dont get is, the def is only fount in the strategy.py file - how does the goxtool and goxapi fire something into it?? thx!
|
|
|
|
prof7bit (OP)
|
|
May 01, 2013, 03:51:15 PM |
|
thx again, i re-pasted the rebalancing bot and now it works, still i cant see what the error in the above code was
Because you messed up the indentations. This totally changes the program. In Python whitespace has a syntactical meaning to get rid of the ugly and redundant and hard to reach (on a german keyboard) curly braces. The absence of curly braces and the clean and readable syntax are one of the main reasons I prefer python over all other scripting languages and Pascal over C++.
|
|
|
|
wilfried
Sr. Member
Offline
Activity: 288
Merit: 250
ManualMiner
|
|
May 01, 2013, 03:55:33 PM |
|
i know about indentation (just a beginner yet), what i ment was, that i didnt see which indentation was messed up, but maybe due to the fact that since 6 hours i am studying your code and its the first time i actually try to cope with classes..
|
|
|
|
prof7bit (OP)
|
|
May 01, 2013, 03:58:23 PM |
|
i know about indentation (just a beginner yet), what i ment was, that i didnt see which indentation was messed up
The last two lines in your other posting, the if statement was outside the slot_keypress method, it was even outside the entire class. MtQuid intuitively corrected it and fixed the indentation without asking further questions when he tested it (because he understood what was probably your intention) but the Python interpreter cannot guess what you might have wanted to do, it will interpret it such that the block belonging to the slot_keypress method ends as soon as the indentation level changes.
|
|
|
|
wilfried
Sr. Member
Offline
Activity: 288
Merit: 250
ManualMiner
|
|
May 01, 2013, 03:58:56 PM |
|
AAAAAAHHHHH, its the variables in the braces of the class-functions, right?
i.e.
def slot_history_changed(self, history, _dummy):
history is found in goxapi - class History(BaseObject)
so goxapi "fills" its classes and strategy.py is defining other classes filled with goxapi results?
I think i start to understand
|
|
|
|
wilfried
Sr. Member
Offline
Activity: 288
Merit: 250
ManualMiner
|
|
May 01, 2013, 04:07:34 PM |
|
i am blind as a fish, cant see it.. i posted: hy i started to look into goxbot and i must admit, i dont get anything, but anyway i will reach the goal of my own little bot. plz help! in my strategy module i got (copied most of it of the 50/50-balance boot) import strategy import goxapi
class Strategy(strategy.Strategy):
"""a protfolio rebalancing bot""" def __init__(self, gox): strategy.Strategy.__init__(self, gox) self.temp_halt = False
def slot_before_unload(self, _sender, _data): pass
def slot_keypress(self, gox, (key)): if key == ord("b"): self.debug("canceling all rebalancing orders")
If key "b" is pressed goxtool displays: someone pressed key b, But it doesnt display "canceling all rebalancing orders". so, how to write messages to the log output? btw: is there an easy way to get rid of the Winconsole output in the main window? I am running tail on the log in a second window, so its just superfluid for me? what i run now is (snipplet): class Strategy(strategy.Strategy): """a protfolio rebalancing bot""" def __init__(self, gox): strategy.Strategy.__init__(self, gox) self.temp_halt = False
def slot_before_unload(self, _sender, _data): pass
def slot_keypress(self, gox, (key)): """a key has been pressed"""
if key == ord("c"): # cancel existing rebalancing orders and suspend trading self.debug("canceling all rebalancing orders") self.temp_halt = True #self.cancel_orders()
do you mean that self.debug.. is under the "e" of key and above it was under the "y" of key?
|
|
|
|
prof7bit (OP)
|
|
May 01, 2013, 04:11:18 PM |
|
AAAAAAHHHHH, its the variables in the braces of the class-functions, right? i.e. def slot_history_changed(self, history, _dummy): history is found in goxapi - class History(BaseObject) so goxapi "fills" its classes and strategy.py is defining other classes filled with goxapi results? I think i start to understand
lol, yes, almost. Although your usage of the above terms indicates that you are only at the beginning of your journey, learning Python. You should really try to work through some tutorials, write your own simple programs from scratch, first start with simple functon calls, understand what function arguments are, global and local variables, then much later maybe learn what classes are and methods and how these are related, inheritance, virtual methods and all that stuff. And then beneath all that there also exist an entire universe of hidden Python-specific black magic that can also be used. This is not learned and understood in one single day, it needs some time.
|
|
|
|
ErebusBat
|
|
May 01, 2013, 04:19:56 PM |
|
You REALLY want to listen to prof7bit. Especially because we don't have backtesting so you are effectively PAYING to test your bot on the live system.
|
|
|
|
prof7bit (OP)
|
|
May 01, 2013, 04:21:15 PM Last edit: May 01, 2013, 04:34:58 PM by prof7bit |
|
def slot_keypress(self, gox, (key)): if key == ord("b"): self.debug("canceling all rebalancing orders")
do you mean that self.debug.. is under the "e" of key and above it was under the "y" of key? the entire two last lines don't seem to belong into the slot_keypress method because the if line needs to be intended further than the def line to be considered inside the method and the line after the if needs to be intended even further than the if to be considered inside the if block. Also be careful with mixing tabs and spaces, you dont see them, everything looks right but isnt. In python it has been established that everybody use 4 spaces and no tabs to have a consistent coding style everywhere and I am trying to follow the styleguides as close as possible myself. So set your editor to (depending on what editor you use, every editor has similar options somewhere in its config) indentation 4 spaces no tabs convert tabs to spaces Do this once and from then on everything becomes much easier. You should also make it a habit to run your code through pylint, I'm doing this everytime I save the code in the editor, before I even attempt to run it, Its a great help, it forces you to adhere to the established standards and coding style and it also finds a lot of problems and errors (my favorite are misspelled variable names, missing function arguments, missing self argument in methods) that could otherwise only be detected at runtime and maybe even not immediately after program start but only after a few hours when its attempting to do its first trade.
|
|
|
|
wilfried
Sr. Member
Offline
Activity: 288
Merit: 250
ManualMiner
|
|
May 01, 2013, 04:21:52 PM |
|
thx, i use your code as leraning object; isnt that a good motivation - as soon as it works it brings btc
|
|
|
|
c0inbuster
|
|
May 01, 2013, 07:35:11 PM Last edit: May 01, 2013, 08:15:38 PM by c0inbuster |
|
I just want to inform you, guys, that an interesting python open source software for backtesting strategy is available here http://gbeced.github.io/pyalgotrade/mixing both goxtool and pyalgotrade could make a good "recipe". I'm looking for a 1 hour timeframe data history for MtGox BTCUSD I tried http://bitcoincharts.com/t/trades.csv?symbol=mtgoxUSD&start=1335830400&end=1367366400as 1335830400 is UNIX Timestamp for Tue, 01 May 2012 00:00:00 GMT and 1367366400 for Wed, 01 May 2013 00:00:00 GMT but Bitcoincharts only reply with data from 1367249267 (Mon, 29 Apr 2013 15:27:47 GMT)
|
|
|
|
DonBit
Member
Offline
Activity: 69
Merit: 10
|
|
May 01, 2013, 08:42:16 PM |
|
Excellent work prof7bit!!! Keep it up the good job! Just made some changes to the stop loss bot and posted it in the stop loss bot thread (I added the start gain feature and full wallet amount autofill). Donating 0.1 for this amazing tool. See transaction dd9dc2b56c328d7a1bb57d07381c789d2312249ee84dd79b578d75e49b4b854b -DonBit
|
1DonBitkTdvCtt8ZC5UDdBh3c1axrvXHbP
|
|
|
MtQuid
Newbie
Offline
Activity: 24
Merit: 0
|
|
May 02, 2013, 10:39:23 AM |
|
Cool. Have a look here http://www.reddit.com/r/Bitcoin/comments/11iz5b/the_history_of_gox_mountain/I just downloaded the torrent and this is the head http://data.mtgox.com/api/2/BTCUSD/money/trades/fetch?since=0 insert into trades values ("USD", "1279408157", "Y", "BTC", "limit", "1", "2000000000", "20", "4951", "", "0.04951") insert into trades values ("USD", "1279424586", "Y", "BTC", "limit", "2", "5001000000", "50.01", "5941", "", "0.05941") insert into trades values ("USD", "1279475336", "Y", "BTC", "limit", "3", "500000000", "5", "8080", "", "0.0808") insert into trades values ("USD", "1279489451", "Y", "BTC", "limit", "4", "1000000000", "10", "8585", "", "0.08585") insert into trades values ("USD", "1279490426", "Y", "BTC", "limit", "5", "500000000", "5", "8584", "", "0.08584") insert into trades values ("USD", "1279490436", "Y", "BTC", "limit", "6", "500000000", "5", "8584", "", "0.08584") insert into trades values ("USD", "1279511584", "Y", "BTC", "limit", "7", "500000000", "5", "9090", "", "0.0909") insert into trades values ("USD", "1279556653", "Y", "BTC", "limit", "9", "8000000000", "80", "9307", "", "0.09307") insert into trades values ("USD", "1279559013", "Y", "BTC", "limit", "10", "10000000000", "100", "8911", "", "0.08911")
and the tail insert into trades values ("USD", "1367047706", "Y", "BTC", "limit", "1367047706332857", "9980000", "0.0998", "13683040", "ask", "136.8304") insert into trades values ("USD", "1367047791", "Y", "BTC", "limit", "1367047791768232", "25712723", "0.25712723", "13688009", "bid", "136.88009") insert into trades values ("USD", "1367047804", "Y", "BTC", "market", "1367047804704062", "80186290", "0.8018629", "13682010", "ask", "136.8201") insert into trades values ("USD", "1367047805", "Y", "BTC", "limit", "1367047805062520", "79726342", "0.79726342", "13688009", "bid", "136.88009") insert into trades values ("USD", "1367047825", "Y", "BTC", "limit", "1367047825872682", "497020000", "4.9702", "13682020", "ask", "136.8202") insert into trades values ("USD", "1367047826", "Y", "BTC", "limit", "1367047826181247", "500000000", "5", "13682000", "ask", "136.82") insert into trades values ("USD", "1367047853", "Y", "BTC", "limit", "1367047853175671", "502980000", "5.0298", "13682000", "bid", "136.82") insert into trades values ("USD", "1367047879", "Y", "BTC", "market", "1367047879486765", "800000000", "8", "13686000", "bid", "136.86") insert into trades values ("USD", "1367047879", "Y", "BTC", "market", "1367047879775307", "600000000", "6", "13688000", "bid", "136.88") insert into trades values ("USD", "1367047879", "Y", "BTC", "market", "1367047879824265", "122345236", "1.22345236", "13688009", "bid", "136.88009")
Would be cool to link up with pyalgotrade.
|
|
|
|
evilscoop
|
|
May 02, 2013, 01:17:06 PM |
|
can anyone help me with coding a strategy for this tool...
I need to calc the EMAs and want to use the differance in my stratagy... I have no clue atm how to do this....
Im looking to create a macd stratagy on the dema from mtgox
Pm me pls, as I dont want to derail the thread, thx
|
|
|
|
|