Skip to content

make big asks/bids standout in order book #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 33 additions & 8 deletions goxtool.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
,["book_ask", curses.COLOR_BLACK, curses.COLOR_RED]
,["book_own", curses.COLOR_BLACK, curses.COLOR_YELLOW]
,["book_vol", curses.COLOR_BLACK, curses.COLOR_BLUE]
,["book_bigvol", curses.COLOR_BLACK, curses.COLOR_MAGENTA]

,["chart_text", curses.COLOR_BLACK, curses.COLOR_WHITE]
,["chart_up", curses.COLOR_BLACK, curses.COLOR_GREEN]
Expand Down Expand Up @@ -254,17 +255,30 @@ def paint(self):
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

# 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

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)
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)
Expand All @@ -276,8 +290,13 @@ def paint(self):
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

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)
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)
Expand Down Expand Up @@ -605,7 +624,8 @@ def modal(self):
self.down(1)
if key_pressed == curses.KEY_UP:
self.down(-1)
if key_pressed == curses.KEY_IC:
#if key_pressed == curses.KEY_IC:
if key_pressed == curses.KEY_ENTER:
self.toggle_select()
self.down(1)

Expand All @@ -623,8 +643,10 @@ class DlgCancelOrders(DlgListItems):
"""modal dialog to cancel orders"""
def __init__(self, stdscr, gox):
self.gox = gox
hlp = [("INS", "select"), ("F8", "cancel selected"), ("F10", "exit")]
keys = [(curses.KEY_F8, self._do_cancel)]
#hlp = [("INS", "select"), ("F8", "cancel selected"), ("F10", "exit")]
hlp = [("ENTER", "select"), ("d", "cancel selected"), ("F10", "exit")]
#keys = [(curses.KEY_F8, self._do_cancel)]
keys = [(ord('d'), self._do_cancel)]
DlgListItems.__init__(self, stdscr, 45, "Cancel order(s)", hlp, keys)

def init_items(self):
Expand Down Expand Up @@ -962,11 +984,14 @@ def curses_loop(stdscr):
key = conwin.win.getch()
if key == ord("q"):
break
if key == curses.KEY_F4:
#if key == curses.KEY_F4:
if key == ord("b"):
DlgNewOrderBid(stdscr, gox).modal()
if key == curses.KEY_F5:
#if key == curses.KEY_F5:
if key == ord("s"):
DlgNewOrderAsk(stdscr, gox).modal()
if key == curses.KEY_F6:
#if key == curses.KEY_F6:
if key == ord("i"):
DlgCancelOrders(stdscr, gox).modal()
if key == curses.KEY_RESIZE:
stdscr.erase()
Expand Down