Exemple #1
0
    def slot_changed(self, book, dummy_data):
        """Slot for orderbook.signal_changed"""
        self.do_paint()

        # 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)
Exemple #2
0
    def paint(self):
        """paint the complete status"""
        cbase = self.gox.curr_base
        cquote = self.gox.curr_quote
        self.sort_currency_list_if_changed()
        self.win.bkgd(" ", COLOR_PAIR["status_text"])
        self.win.erase()
        line1 = "Market: %s%s | " % (cbase, cquote)
        line1 += "Account: "
        if len(self.sorted_currency_list):
            for currency in self.sorted_currency_list:
                if currency in self.gox.wallet:
                    line1 += currency + " " \
                    + goxapi.int2str(self.gox.wallet[currency], currency).strip() \
                    + " + "
            line1 = line1.strip(" +")
        else:
            line1 += "No info (yet)"

        str_btc = locale.format('%d', self.gox.orderbook.total_ask, 1)
        str_fiat = locale.format('%d', self.gox.orderbook.total_bid, 1)
        if self.gox.orderbook.total_ask:
            str_ratio = locale.format(
                '%1.2f',
                self.gox.orderbook.total_bid / self.gox.orderbook.total_ask, 1)
        else:
            str_ratio = "-"

        line2 = "sum_bid: %s %s | " % (str_fiat, cquote)
        line2 += "sum_ask: %s %s | " % (str_btc, cbase)
        line2 += "ratio: %s %s/%s | " % (str_ratio, cquote, cbase)
        line2 += "o_lag: %s | " % self.order_lag_txt
        line2 += "s_lag: %.3f s" % (self.gox.socket_lag / 1e6)
        self.addstr(0, 0, line1, COLOR_PAIR["status_text"])
        self.addstr(1, 0, line2, COLOR_PAIR["status_text"])
Exemple #3
0
    def paint(self):
        """paint the complete status"""
        self.win.bkgd(" ", COLOR_PAIR["status_text"])
        self.win.erase()
        line1 = "Currency: " + self.gox.currency + " | "
        line1 += "Account: "
        if len(self.gox.wallet):
            for currency in self.gox.wallet:
                line1 += currency + " " \
                + goxapi.int2str(self.gox.wallet[currency], currency).strip() \
                + " + "
            line1 = line1.strip(" +")
        else:
            line1 += "No info (yet)"

        str_btc = locale.format('%d', self.gox.orderbook.total_ask, 1)
        str_fiat = locale.format('%d', self.gox.orderbook.total_bid, 1)
        if self.gox.orderbook.total_ask:
            str_ratio = locale.format('%1.2f',
                self.gox.orderbook.total_bid / self.gox.orderbook.total_ask, 1)
        else:
            str_ratio = "-"

        line2 = "total bid: " + str_fiat + " " + self.gox.currency + " | "
        line2 += "total ask: " +str_btc + " BTC | "
        line2 += "ratio: " + str_ratio + " " + self.gox.currency + "/BTC | "
        line2 += "lag: " + self.order_lag_txt
        self.addstr(0, 0, line1, COLOR_PAIR["status_text"])
        self.addstr(1, 0, line2, COLOR_PAIR["status_text"])
Exemple #4
0
    def paint(self):
        """paint the complete status"""
        cbase = self.gox.curr_base
        cquote = self.gox.curr_quote
        self.sort_currency_list_if_changed()
        self.win.bkgd(" ", COLOR_PAIR["status_text"])
        self.win.erase()
        line1 = "Market: %s%s | " % (cbase, cquote)
        line1 += "Account: "
        if len(self.sorted_currency_list):
            for currency in self.sorted_currency_list:
                if currency in self.gox.wallet:
                    line1 += currency + " " \
                    + goxapi.int2str(self.gox.wallet[currency], currency).strip() \
                    + " + "
            line1 = line1.strip(" +")
        else:
            line1 += "No info (yet)"

        str_btc = locale.format('%d', self.gox.orderbook.total_ask, 1)
        str_fiat = locale.format('%d', self.gox.orderbook.total_bid, 1)
        if self.gox.orderbook.total_ask:
            str_ratio = locale.format('%1.2f',
                self.gox.orderbook.total_bid / self.gox.orderbook.total_ask, 1)
        else:
            str_ratio = "-"

        line2 = "sum_bid: %s %s | " % (str_fiat, cquote)
        line2 += "sum_ask: %s %s | " % (str_btc, cbase)
        line2 += "ratio: %s %s/%s | " % (str_ratio, cquote, cbase)
        line2 += "o_lag: %s | " % self.order_lag_txt
        line2 += "s_lag: %.3f s" % (self.gox.socket_lag / 1e6)
        self.addstr(0, 0, line1, COLOR_PAIR["status_text"])
        self.addstr(1, 0, line2, COLOR_PAIR["status_text"])
Exemple #5
0
    def paint_item(self, posy, index):
        """paint one single order"""
        order = self.items[index]
        if order in self.selected:
            marker = "*"
            if index == self.item_sel:
                attr = COLOR_PAIR["dialog_sel_sel"]
            else:
                attr = COLOR_PAIR["dialog_sel_text"] + curses.A_BOLD
        else:
            marker = ""
            if index == self.item_sel:
                attr = COLOR_PAIR["dialog_sel"]
            else:
                attr = COLOR_PAIR["dialog_text"]

        self.addstr(posy, 2, marker, attr)
        self.addstr(posy, 5, order.typ, attr)
        self.addstr(posy, 9, goxapi.int2str(order.price, self.gox.currency), attr)
        self.addstr(posy, 22, goxapi.int2str(order.volume, "BTC"), attr)
Exemple #6
0
    def paint(self):
        """paint the visible portion of the orderbook"""
        self.win.bkgd(" ",  COLOR_PAIR["book_text"])
        self.win.erase()
        mid = self.height / 2
        col_bid = COLOR_PAIR["book_bid"]
        col_ask = COLOR_PAIR["book_ask"]
        col_vol = COLOR_PAIR["book_vol"]
        col_own = COLOR_PAIR["book_own"]

        # print the asks
        # pylint: disable=C0301
        book = self.gox.orderbook
        pos = mid - 1
        i = 0
        cnt = len(book.asks)
        while pos >= 0 and  i < cnt:
            self.addstr(pos, 0,  goxapi.int2str(book.asks[i].price, book.gox.currency), col_ask)
            self.addstr(pos, 12, goxapi.int2str(book.asks[i].volume, "BTC"), col_vol)
            ownvol = book.get_own_volume_at(book.asks[i].price)
            if ownvol:
                self.addstr(pos, 28, goxapi.int2str(ownvol, "BTC"), col_own)
            pos -= 1
            i += 1

        # print the bids
        pos = mid + 1
        i = 0
        cnt = len(book.bids)
        while pos < self.height and  i < cnt:
            self.addstr(pos, 0,  goxapi.int2str(book.bids[i].price, book.gox.currency), col_bid)
            self.addstr(pos, 12, goxapi.int2str(book.bids[i].volume, "BTC"), col_vol)
            ownvol = book.get_own_volume_at(book.bids[i].price)
            if ownvol:
                self.addstr(pos, 28, goxapi.int2str(ownvol, "BTC"), col_own)
            pos += 1
            i += 1
Exemple #7
0
    def paint(self):
        """paint the visible portion of the chart"""


        self.win.bkgd(" ",  COLOR_PAIR["chart_text"])
        self.win.erase()

        hist = self.gox.history
        book = self.gox.orderbook

        self.pmax = 0
        self.pmin = 9999999999

        # determine y range
        posx = self.width - 2
        index = 0
        while index < hist.length() and posx >= 0:
            candle = hist.candles[index]
            if self.pmax < candle.hig:
                self.pmax = candle.hig
            if self.pmin > candle.low:
                self.pmin = candle.low
            index += 1
            posx -= 1

        if self.pmax == self.pmin:
            return

        # paint the candles
        posx = self.width - 2
        index = 0
        while index < hist.length() and posx >= 0:
            candle = hist.candles[index]
            self.paint_candle(posx, candle)
            index += 1
            posx -= 1

        # paint bid, ask, own orders
        posx = self.width - 1
        for order in book.owns:
            if self.is_in_range(order.price):
                posy = self.price_to_screen(order.price)
                if order.status == "pending":
                    self.addch(posy, posx,
                        ord("o"), COLOR_PAIR["order_pending"])
                else:
                    self.addch(posy, posx,
                        ord("O"), COLOR_PAIR["chart_text"])

        if self.is_in_range(book.bid):
            posy = self.price_to_screen(book.bid)
            # pylint: disable=E1101
            self.addch(posy, posx,
                curses.ACS_HLINE, COLOR_PAIR["chart_up"])

        if self.is_in_range(book.ask):
            posy = self.price_to_screen(book.ask)
            # pylint: disable=E1101
            self.addch(posy, posx,
                curses.ACS_HLINE, COLOR_PAIR["chart_down"])

        # paint the y-axis labels
        posx = 0
        step = self.get_optimal_step(4)
        if step:
            labelprice = int(self.pmin / step) * step
            while not labelprice > self.pmax:
                posy = self.price_to_screen(labelprice)
                if posy < self.height - 1:
                    self.addstr(
                        posy, posx,
                        goxapi.int2str(labelprice, self.gox.currency),
                        COLOR_PAIR["chart_text"]
                    )
                labelprice += step
Exemple #8
0
 def paint_row(pos, price, vol, ownvol, color):
     """paint a row in the orderbook (bid or ask)"""
     self.addstr(pos, 0,  goxapi.int2str(price, book.gox.currency), color)
     self.addstr(pos, 12, goxapi.int2str(vol, "BTC"), col_vol)
     if ownvol:
         self.addstr(pos, 28, goxapi.int2str(ownvol, "BTC"), col_own)
Exemple #9
0
    def paint(self):
        """paint the visible portion of the orderbook"""
        self.win.bkgd(" ",  COLOR_PAIR["book_text"])
        self.win.erase()
        mid = self.height / 2
        col_bid = COLOR_PAIR["book_bid"]
        col_ask = COLOR_PAIR["book_ask"]
        col_vol = COLOR_PAIR["book_vol"]
        col_bigvol = COLOR_PAIR["book_bigvol"]
        col_own = COLOR_PAIR["book_own"]

        # get threshold for big transactions from config (if any)
        vol_threshold = self.gox.config.get_safe("goxtool", "color_bigvol_threshold")
        if len(vol_threshold) > 0:
            vol_threshold = float(vol_threshold)
        else:
            vol_threshold = 0

        # get threshold for ignoring small orders from config (if any)
        hide_smallorder_threshold = self.gox.config.get_safe("goxtool", "hide_smallorder_threshold")
        if len(hide_smallorder_threshold) > 0.6:
            hide_smallorder_threshold = float(hide_smallorder_threshold)
        else:
            hide_smallorder_threshold = 0.6

        # print the asks
        # pylint: disable=C0301
        book = self.gox.orderbook
        pos = mid - 1
        i = 0
        cnt = len(book.asks)
        while pos >= 0 and  i < cnt:
            col_thisvol = col_vol
            if vol_threshold != 0:
                if float(goxapi.int2str(book.asks[i].volume, "BTC")) > vol_threshold:
                    col_thisvol = col_bigvol

            if float(goxapi.int2str(book.asks[i].volume, "BTC")) > hide_smallorder_threshold:
                self.addstr(pos, 0,  goxapi.int2str(book.asks[i].price, book.gox.currency), col_ask)
                self.addstr(pos, 12, goxapi.int2str(book.asks[i].volume, "BTC"), col_thisvol)
            ownvol = book.get_own_volume_at(book.asks[i].price)
            if ownvol:
                self.addstr(pos, 28, goxapi.int2str(ownvol, "BTC"), col_own)
            if float(goxapi.int2str(book.asks[i].volume, "BTC")) > hide_smallorder_threshold:
                pos -= 1
            i += 1

        # print the bids
        pos = mid + 1
        i = 0
        cnt = len(book.bids)
        while pos < self.height and  i < cnt:
            col_thisvol = col_vol
            if vol_threshold != 0:
                if float(goxapi.int2str(book.bids[i].volume, "BTC")) > vol_threshold:
                    col_thisvol = col_bigvol
            if float(goxapi.int2str(book.bids[i].volume, "BTC")) > hide_smallorder_threshold:
                self.addstr(pos, 0,  goxapi.int2str(book.bids[i].price, book.gox.currency), col_bid)
                self.addstr(pos, 12, goxapi.int2str(book.bids[i].volume, "BTC"), col_thisvol)
            ownvol = book.get_own_volume_at(book.bids[i].price)
            if ownvol:
                self.addstr(pos, 28, goxapi.int2str(ownvol, "BTC"), col_own)
            if float(goxapi.int2str(book.bids[i].volume, "BTC")) > hide_smallorder_threshold:
                pos += 1
            i += 1