Exemplo n.º 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.exch.config.get_bool("btctool", "set_xterm_title"):
            last_candle = self.exch.history.last_candle()
            if last_candle:
                title = btcapi.int2str(last_candle.cls, self.exch.currency).strip()
                title += " - btctool -"
                title += " bid:" + btcapi.int2str(book.bid, self.exch.currency).strip()
                title += " ask:" + btcapi.int2str(book.ask, self.exch.currency).strip()
                curses.putp("\033]0;%s\007" % title)
Exemplo n.º 2
0
    def paint(self):
        """paint the complete status"""
        self.win.bkgd(" ", COLOR_PAIR["status_text"])
        self.win.erase()
        line1 = "Currency: " + self.exch.currency + " | "
        line1 += "Account: "
        if len(self.exch.wallet):
            for currency in self.exch.wallet:
                line1 += currency + " " \
                + btcapi.int2str(self.exch.wallet[currency], currency).strip() \
                + " + "
            line1 = line1.strip(" +")
        else:
            line1 += "No info (yet)"

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

        line2 = "total bid: " + str_fiat + " " + self.exch.currency + " | "
        line2 += "total ask: " + str_btc + " BTC | "
        line2 += "ratio: " + str_ratio + " " + self.exch.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"])
Exemplo n.º 3
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.exch.config.get_bool("btctool", "set_xterm_title"):
            last_candle = self.exch.history.last_candle()
            if last_candle:
                title = btcapi.int2str(last_candle.cls,
                                       self.exch.currency).strip()
                title += " - btctool -"
                title += " bid:" + btcapi.int2str(book.bid,
                                                  self.exch.currency).strip()
                title += " ask:" + btcapi.int2str(book.ask,
                                                  self.exch.currency).strip()
                curses.putp("\033]0;%s\007" % title)
Exemplo n.º 4
0
    def paint(self):
        """paint the complete status"""
        self.win.bkgd(" ", COLOR_PAIR["status_text"])
        self.win.erase()
        line1 = "Currency: " + self.exch.currency + " | "
        line1 += "Account: "
        if len(self.exch.wallet):
            for currency in self.exch.wallet:
                line1 += currency + " " \
                + btcapi.int2str(self.exch.wallet[currency], currency).strip() \
                + " + "
            line1 = line1.strip(" +")
        else:
            line1 += "No info (yet)"

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

        line2 = "total bid: " + str_fiat + " " + self.exch.currency + " | "
        line2 += "total ask: " +str_btc + " BTC | "
        line2 += "ratio: " + str_ratio + " " + self.exch.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"])
Exemplo n.º 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, btcapi.int2str(order.price, self.exch.currency), attr)
        self.addstr(posy, 22, btcapi.int2str(order.volume, "BTC"), attr)
Exemplo n.º 6
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, btcapi.int2str(order.price, self.exch.currency),
                    attr)
        self.addstr(posy, 22, btcapi.int2str(order.volume, "BTC"), attr)
Exemplo n.º 7
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.exch.orderbook
        pos = mid - 1
        i = 0
        cnt = len(book.asks)
        while pos >= 0 and i < cnt:
            self.addstr(pos, 0,
                        btcapi.int2str(book.asks[i].price, book.exch.currency),
                        col_ask)
            self.addstr(pos, 12, btcapi.int2str(book.asks[i].volume, "BTC"),
                        col_vol)
            ownvol = book.get_own_volume_at(book.asks[i].price)
            if ownvol:
                self.addstr(pos, 28, btcapi.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,
                        btcapi.int2str(book.bids[i].price, book.exch.currency),
                        col_bid)
            self.addstr(pos, 12, btcapi.int2str(book.bids[i].volume, "BTC"),
                        col_vol)
            ownvol = book.get_own_volume_at(book.bids[i].price)
            if ownvol:
                self.addstr(pos, 28, btcapi.int2str(ownvol, "BTC"), col_own)
            pos += 1
            i += 1
Exemplo n.º 8
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.exch.orderbook
        pos = mid - 1
        i = 0
        cnt = len(book.asks)
        while pos >= 0 and  i < cnt:
            self.addstr(pos, 0,  btcapi.int2str(book.asks[i].price, book.exch.currency), col_ask)
            self.addstr(pos, 12, btcapi.int2str(book.asks[i].volume, "BTC"), col_vol)
            ownvol = book.get_own_volume_at(book.asks[i].price)
            if ownvol:
                self.addstr(pos, 28, btcapi.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,  btcapi.int2str(book.bids[i].price, book.exch.currency), col_bid)
            self.addstr(pos, 12, btcapi.int2str(book.bids[i].volume, "BTC"), col_vol)
            ownvol = book.get_own_volume_at(book.bids[i].price)
            if ownvol:
                self.addstr(pos, 28, btcapi.int2str(ownvol, "BTC"), col_own)
            pos += 1
            i += 1
Exemplo n.º 9
0
    def paint(self):
        """paint the visible portion of the chart"""

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

        hist = self.exch.history
        book = self.exch.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,
                                btcapi.int2str(labelprice, self.exch.currency),
                                COLOR_PAIR["chart_text"])
                labelprice += step
Exemplo n.º 10
0
    def paint(self):
        """paint the visible portion of the chart"""


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

        hist = self.exch.history
        book = self.exch.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,
                        btcapi.int2str(labelprice, self.exch.currency),
                        COLOR_PAIR["chart_text"]
                    )
                labelprice += step