Bitcoin Forum
May 04, 2024, 11:18:30 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: « 1 2 [3] 4 5 6 7 8 9 10 11 »  All
  Print  
Author Topic: ncurses based MtGox live monitor and trading-bot-framework  (Read 33817 times)
teek
Hero Member
*****
Offline Offline

Activity: 667
Merit: 500



View Profile
April 17, 2013, 07:36:55 PM
 #41

wow this looks awesome,  checking it out!
1714821510
Hero Member
*
Offline Offline

Posts: 1714821510

View Profile Personal Message (Offline)

Ignore
1714821510
Reply with quote  #2

1714821510
Report to moderator
Bitcoin addresses contain a checksum, so it is very unlikely that mistyping an address will cause you to lose money.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714821510
Hero Member
*
Offline Offline

Posts: 1714821510

View Profile Personal Message (Offline)

Ignore
1714821510
Reply with quote  #2

1714821510
Report to moderator
JWU42
Legendary
*
Offline Offline

Activity: 1666
Merit: 1000


View Profile
April 17, 2013, 07:59:45 PM
 #42

Just another friendly mention that a Bitfloor "version" would be of interest.  If there needs to be a minimum pledged let us know as I am fairly sure it can be accomplished.

I have thought about this too already. Its just a matter of time. But since its GPL maybe someone else who is faster than me can fork it and make a bitfloor version, maybe with some refactoring it might even be possible later to combine both into one tool again. Its not imposible its just some work that needs to be done and time to put into it and I also have so many other unfinished things that occasionally need my attention, I wish I could fork myself into many parallel processes to get more stuff done ;-)

Appreciate the reply.  If I had the skills I would have tried to write it myself...

ErebusBat
Hero Member
*****
Offline Offline

Activity: 560
Merit: 500

I am the one who knocks


View Profile
April 17, 2013, 09:51:25 PM
 #43

I was wondering what someone would charge to calculate arbitrary EMAs in the strategy file.

I am no python expert, nor a GOX api specialist.

░▒▓█ Coinroll.it - 1% House Edge Dice Game █▓▒░ • Coinroll Thread • *FREE* 100 BTC Raffle

Signup for CEX.io BitFury exchange and get GHS Instantly!  Don't wait for shipping, mine NOW!
toffoo
Sr. Member
****
Offline Offline

Activity: 408
Merit: 261



View Profile
April 17, 2013, 10:53:18 PM
 #44

Just another friendly mention that a Bitfloor "version" would be of interest.  If there needs to be a minimum pledged let us know as I am fairly sure it can be accomplished.

I have thought about this too already. Its just a matter of time. But since its GPL maybe someone else who is faster than me can fork it and make a bitfloor version, maybe with some refactoring it might even be possible later to combine both into one tool again. Its not imposible its just some work that needs to be done and time to put into it and I also have so many other unfinished things that occasionally need my attention, I wish I could fork myself into many parallel processes to get more stuff done ;-)

Appreciate the reply.  If I had the skills I would have tried to write it myself...

No point now!

Think of it like you just saved yourself the trouble of doing lots of extra work for nothing!

JWU42
Legendary
*
Offline Offline

Activity: 1666
Merit: 1000


View Profile
April 17, 2013, 11:30:48 PM
 #45

Toffoo,

Had no idea what you were speaking of until I visited the site just now  Shocked

fnordfnordfnord
Newbie
*
Offline Offline

Activity: 56
Merit: 0


View Profile
April 18, 2013, 07:53:40 PM
 #46

prof7bit, the people demand bitfloor support Grin

Belay that order, disregard.
smooth
Legendary
*
Offline Offline

Activity: 2968
Merit: 1198



View Profile
April 18, 2013, 09:57:20 PM
 #47

Is this actually usable?  socketio seems to drop constantly and lag horribly, especially on orders.  websocket just sits there and doesn't update.

dutt
Member
**
Offline Offline

Activity: 135
Merit: 10



View Profile WWW
April 18, 2013, 10:32:07 PM
 #48

Yea. The problem lies with mtgox though, not with the code.

fnordfnordfnord
Newbie
*
Offline Offline

Activity: 56
Merit: 0


View Profile
April 18, 2013, 10:43:00 PM
 #49

Is this actually usable?  socketio seems to drop constantly and lag horribly, especially on orders.  websocket just sits there and doesn't update.



Been running it for a week, it is surprisingly robust considering the problems with mtgox, and me suspending my laptop a couple of times per day.


Quote
Please read about portfolio rebalancing to understand the implications and why you would want (or not want) to do this.

So, about that, got any good links or books to recommend? Googling for "portfolio rebalancing" gets me a bunch of noise about how I should own a diversity of stocks, bonds, and other garbage. Googling for "Forex rebalancing" is only a bit better.
ErebusBat
Hero Member
*****
Offline Offline

Activity: 560
Merit: 500

I am the one who knocks


View Profile
April 18, 2013, 11:50:52 PM
 #50

A very very basic overview on rebalancing would be that it protects you from volitilty of one asset.

░▒▓█ Coinroll.it - 1% House Edge Dice Game █▓▒░ • Coinroll Thread • *FREE* 100 BTC Raffle

Signup for CEX.io BitFury exchange and get GHS Instantly!  Don't wait for shipping, mine NOW!
smooth
Legendary
*
Offline Offline

Activity: 2968
Merit: 1198



View Profile
April 18, 2013, 11:58:52 PM
 #51

Been running it for a week, it is surprisingly robust considering the problems with mtgox, and me suspending my laptop a couple of times per day.

What API configuration are you using?  Do you trade or just use it to watch the market?
fnordfnordfnord
Newbie
*
Offline Offline

Activity: 56
Merit: 0


View Profile
April 19, 2013, 02:07:08 AM
 #52

Been running it for a week, it is surprisingly robust considering the problems with mtgox, and me suspending my laptop a couple of times per day.

What API configuration are you using?  Do you trade or just use it to watch the market?


I installed it last weekend with git.
Code:
git clone https://github.com/prof7bit/goxtool.git

I run it just like this.
Code:
./goxtool.py  --protocol=socketio --use-http 

I tried other configurations, but I can't say anything good or bad considering the conditions. I wouldn't call it a controlled experiment in other words.

I traded manually with it this week a bit, and it worked fine. I changed the colors up a bit since I have 256 color xterm. Until today I was just entering trades manually but then I checked the thread and saw the _balancer so I did a git stash and a git pull and I have been playing with it this evening. Fun stuff, thanks to OP for posting the example. It's better (more complete) than what I was throwing together. A good starting point.

PS If anyone is interested, I found a book on Amazon http://www.amazon.com/Trading-Systems-Methods-Website-Wiley/dp/1118043561
smooth
Legendary
*
Offline Offline

Activity: 2968
Merit: 1198



View Profile
April 19, 2013, 04:44:22 AM
 #53

I run it just like this.
Code:
./goxtool.py  --protocol=socketio --use-http 

Thanks, that does seem to work a lot better.
prof7bit (OP)
Hero Member
*****
Offline Offline

Activity: 938
Merit: 500


https://youengine.io/


View Profile WWW
April 19, 2013, 09:18:36 AM
Last edit: April 19, 2013, 09:42:52 AM by prof7bit
 #54

A very very basic overview on rebalancing would be that it protects you from volitilty of one asset.

and it is producing a small profit in the long run and outperforms a buy and hold strategy. This is because you are always selling higher than you have bought. Its only a small amount because only a tiny fraction of your BTC is bought or sold on every step but if BTC price is very volatile and does two digit percent changes every single day and huge ups and downs this can become significant quite fast.

Its a very conservative strategy and probably one of the few strategies that can cannot accidentally burn all your money in one night if the bot is crashing/hanging while you are sleeping.

Maybe we could make a separate forum thread where people post their bots and discuss them.

ErebusBat
Hero Member
*****
Offline Offline

Activity: 560
Merit: 500

I am the one who knocks


View Profile
April 19, 2013, 04:04:08 PM
 #55

@prof7bit

I noticed that sometimes with the balancer + gox connection issues sometimes the balancer gets out of whack.  Last night with the spike at $130 was a prime example.

Would it be possible to add a slot to the strategy so that on a gox reconnection the strategy can then re-asses if anything needs to be done (a cancel and re-place orders in the case of the balancer).

░▒▓█ Coinroll.it - 1% House Edge Dice Game █▓▒░ • Coinroll Thread • *FREE* 100 BTC Raffle

Signup for CEX.io BitFury exchange and get GHS Instantly!  Don't wait for shipping, mine NOW!
K1773R
Legendary
*
Offline Offline

Activity: 1792
Merit: 1008


/dev/null


View Profile
April 19, 2013, 04:13:49 PM
 #56

Bug Report: please check if the terminal is a terminal emulation and not a real tty otherwise the CUI looks ugly because of this code
Code:
# update the xterm title (this is not handled by curses)
        if self.gox.config.get_bool("goxtool", "set_xterm_title"):
            last_candle = self.gox.history.last_candle()
            if last_candle:
                title = goxapi.int2str(last_candle.cls, self.gox.currency).strip()
                title += " - goxtool -"
                title += " bid:" + goxapi.int2str(book.bid, self.gox.currency).strip()
                title += " ask:" + goxapi.int2str(book.ask, self.gox.currency).strip()
                curses.putp("\033]0;%s\007" % title)
if you want i can provide a screenshot Wink

EDIT: im aware of the following code, still its not nice. altough its good that you can disable it with ease.
Code:
if self.gox.config.get_bool("goxtool", "set_xterm_title"):

[GPG Public Key]
BTC/DVC/TRC/FRC: 1K1773RbXRZVRQSSXe9N6N2MUFERvrdu6y ANC/XPM AK1773RTmRKtvbKBCrUu95UQg5iegrqyeA NMC: NK1773Rzv8b4ugmCgX789PbjewA9fL9Dy1 LTC: LKi773RBuPepQH8E6Zb1ponoCvgbU7hHmd EMC: EK1773RxUes1HX1YAGMZ1xVYBBRUCqfDoF BQC: bK1773R1APJz4yTgRkmdKQhjhiMyQpJgfN
prof7bit (OP)
Hero Member
*****
Offline Offline

Activity: 938
Merit: 500


https://youengine.io/


View Profile WWW
April 19, 2013, 04:50:44 PM
 #57

Would it be possible to add a slot to the strategy so that on a gox reconnection the strategy can then re-asses if anything needs to be done (a cancel and re-place orders in the case of the balancer).

Yes, something like that is on my todo list because i have exactly the same problems with the balancer.bot. As a workaround I have slightly modified the _balancer.py code to also trade when it suddenly detects only one order while the trade signal has been missed:

Code:
"""
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.last_trade = 0
        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"):
            # remove existing rebalancing orders
            self.debug("canceling all rebalancing orders")
            self.temp_halt = True
            self.cancel_orders()

        if key == ord("p"):
            # create the initial two rebalancing orders. Before you
            # do this the portfolio should already be balanced.
            self.debug("adding new initial rebalancing orders")
            book = self.gox.orderbook
            self.temp_halt = False
            self.place_orders((book.bid + book.ask) / 2)

        if key == ord("u"):
            gox.client.channel_subscribe()

        if key == ord("i"):
            price = (gox.orderbook.bid + gox.orderbook.ask) / 2
            vol_buy = self.get_buy_at_price(price)
            self.debug("BTC difference:",
                goxapi.int2float(vol_buy, "BTC"))

        if key == ord("b"):
            price = (gox.orderbook.bid + gox.orderbook.ask) / 2
            vol_buy = self.get_buy_at_price(price)
            if abs(vol_buy) > 0.01 * COIN:
                self.temp_halt = True
                self.cancel_orders()
                if vol_buy > 0:
                    self.debug("buy %f at market" %
                        goxapi.int2float(vol_buy, "BTC"))
                    gox.buy(0, vol_buy)
                else:
                    self.debug("sell %f at market" %
                        goxapi.int2float(-vol_buy, "BTC"))
                    gox.sell(0, -vol_buy)



    def cancel_orders(self):
        """cancel all rebalancing orders, we identify
        them through the marker in the price value"""
        must_cancel = []
        for order in self.gox.orderbook.owns:
            if is_own(order.price):
                must_cancel.append(order)

        for order in must_cancel:
            self.gox.cancel(order.oid)

    def get_buy_at_price(self, price_int):
        """calculate amount of BTC needed to buy at price to achieve
        rebalancing. price and return value are in mtgox integer format"""
        currency = self.gox.currency
        fiat_have = goxapi.int2float(self.gox.wallet[currency], currency)
        btc_have  = goxapi.int2float(self.gox.wallet["BTC"], "BTC")
        price_then = goxapi.int2float(price_int, currency)

        btc_value_then = btc_have * price_then
        diff = fiat_have - btc_value_then
        diff_btc = diff / price_then
        must_buy = diff_btc / 2
        return goxapi.float2int(must_buy, "BTC")

    def place_orders(self, center):
        """place two new rebalancing orders above and below center price"""
        currency = self.gox.currency
        step = int(center * DISTANCE / 100.0)
        next_sell = mark_own(center + step)
        next_buy  = mark_own(center - step)

        sell_amount = -self.get_buy_at_price(next_sell)
        buy_amount = self.get_buy_at_price(next_buy)

        if sell_amount < 0.01 * COIN:
            sell_amount = int(0.01 * COIN)
            self.debug("WARNING! minimal sell amount adjusted to 0.01")

        if buy_amount < 0.01 * COIN:
            buy_amount = int(0.01 * COIN)
            self.debug("WARNING! minimal buy amount adjusted to 0.01")

        self.debug("new buy order %f at %f" % (
            goxapi.int2float(buy_amount, "BTC"),
            goxapi.int2float(next_buy, currency)
        ))
        self.gox.buy(next_buy, buy_amount)

        self.debug("new sell order %f at %f" % (
            goxapi.int2float(sell_amount, "BTC"),
            goxapi.int2float(next_sell, currency)
        ))
        self.gox.sell(next_sell, sell_amount)


    def slot_trade(self, gox, (date, price, volume, typ, own)):
        """a trade message has been receivd"""
        # not interested in other people's trades
        if not own:
            return

        # not interested in manually entered (not bot) trades
        if not is_own(price):
            return

        text = {"bid": "sold", "ask": "bought"}[typ]
        self.debug("*** %s %f at %f" % (
            text,
            goxapi.int2float(volume, "BTC"),
            goxapi.int2float(price, gox.currency)
        ))
        self.last_trade = price
        self.check_trades()

    def slot_owns_changed(self, orderbook, _dummy):
        """status or amount of own open orders has changed"""
        self.check_trades()

    def check_trades(self):
        """find out if we need to place new orders and do it if neccesary"""

        # bot temporarily disabled
        if self.temp_halt:
            return

        # still waiting for submitted orders,
        # can wait for next signal
        if self.gox.count_submitted:
            return

        # we count the open and pending orders
        count = 0
        count_pending = 0
        book = self.gox.orderbook
        for order in book.owns:
            if is_own(order.price):
                if order.status == "open":
                    count += 1
                else:
                    count_pending += 1

        # as long as there are ANY pending orders around we
        # just do nothing and wait for the next signal
        if count_pending:
            return

        # if count is exacty 1 then one of the orders must have been filled,
        # now we cancel the other one and place two fresh orders in the
        # distance of DISTANCE around current price.
        if count == 1:
            price = self.last_trade
            self.last_trade = 0
            if not price:
                price = (book.ask + book.bid) / 2
                self.debug(
                    "*** missed trade message, using current price %f" %
                    goxapi.int2float(price, self.gox.currency)
                )
            self.cancel_orders()
            self.place_orders(price)

there are also some new keyboard commands:

"u": update own order list, depth, history, wallet and everything
"i": display how much it is out of balance at current price (negative: must sell, positive: must buy)
"b":  balance immediately (cancel orders and then buy/sell at market to rebalance)

ErebusBat
Hero Member
*****
Offline Offline

Activity: 560
Merit: 500

I am the one who knocks


View Profile
April 19, 2013, 05:15:58 PM
 #58

Would it be possible to add a slot to the strategy so that on a gox reconnection the strategy can then re-asses if anything needs to be done (a cancel and re-place orders in the case of the balancer).

Yes, something like that is on my todo list because i have exactly the same problems with the balancer.bot. As a workaround I have slightly modified the _balancer.py code to also trade when it suddenly detects only one order while the trade signal has been missed:

Thanks for this, esp the 'b' command I just deposited this morning and would have been very helpful.   

Do you have the bot in a separate git repo that can be tracked?

For those playing along at home, here is a command summary & launch instructions for prof7bit's balancer bot:
Code:
# "p": place 2 orders above and below price. 
# "c": cancel orders and effectively stop the bot
# "u": update own order list, depth, history, wallet and everything
# "i": display how much it is out of balance at current price (negative: must sell, positive: must buy)
# "b":balance immediately (cancel orders and then buy/sell at market to rebalance)
./goxtool.py --protocol=socketio --use-http --strategy=_balancer.py

░▒▓█ Coinroll.it - 1% House Edge Dice Game █▓▒░ • Coinroll Thread • *FREE* 100 BTC Raffle

Signup for CEX.io BitFury exchange and get GHS Instantly!  Don't wait for shipping, mine NOW!
prof7bit (OP)
Hero Member
*****
Offline Offline

Activity: 938
Merit: 500


https://youengine.io/


View Profile WWW
April 19, 2013, 05:24:33 PM
 #59

Do you have the bot in a separate git repo that can be tracked?
No, not yet.

havardr
Newbie
*
Offline Offline

Activity: 29
Merit: 0



View Profile
April 20, 2013, 09:00:12 AM
 #60

I just tested the balancer.py now, and i must say it had a huge spread.

Had about 7BTC, divided in two, and got 433 USD in cash. Current price is 120.
Started the bot with p, and it put in a sell at 129.03137, and a buy at 112.14877   
Pages: « 1 2 [3] 4 5 6 7 8 9 10 11 »  All
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!