Browse Source

Merge #80: ob-watcher.py: full segregation of distinct markets

5cdc379 ob-watcher.py: full segregation of distinct markets (Adlai Chandrasekhar)
master
AdamISZ 8 years ago
parent
commit
d9590ebaaf
No known key found for this signature in database
GPG Key ID: B3AE09F1E9A3197A
  1. 26
      scripts/obwatch/ob-watcher.py

26
scripts/obwatch/ob-watcher.py

@ -34,8 +34,10 @@ import jmbitcoin as btc
from jmdaemon.protocol import * from jmdaemon.protocol import *
log = get_log() log = get_log()
#Initial state: allow all SW+legacy offer types #Initial state: allow only SW offer types
filtered_offername_list = offername_list swoffers = filter(lambda x: x[0:2] == 'sw', offername_list)
pkoffers = filter(lambda x: x[0:2] != 'sw', offername_list)
filtered_offername_list = swoffers
shutdownform = '<form action="shutdown" method="post"><input type="submit" value="Shutdown" /></form>' shutdownform = '<form action="shutdown" method="post"><input type="submit" value="Shutdown" /></form>'
shutdownpage = '<html><body><center><h1>Successfully Shut down</h1></center></body></html>' shutdownpage = '<html><body><center><h1>Successfully Shut down</h1></center></body></html>'
@ -54,7 +56,8 @@ def calc_depth_data(db, value):
def create_depth_chart(db, cj_amount, args=None): def create_depth_chart(db, cj_amount, args=None):
if args is None: if args is None:
args = {} args = {}
sqlorders = db.execute('SELECT * FROM orderbook;').fetchall() rows = db.execute('SELECT * FROM orderbook;').fetchall()
sqlorders = [o for o in rows if o["ordertype"] in filtered_offername_list]
orderfees = sorted([calc_cj_fee(o['ordertype'], o['cjfee'], cj_amount) / 1e8 orderfees = sorted([calc_cj_fee(o['ordertype'], o['cjfee'], cj_amount) / 1e8
for o in sqlorders for o in sqlorders
if o['minsize'] <= cj_amount <= o[ if o['minsize'] <= cj_amount <= o[
@ -91,7 +94,8 @@ def create_depth_chart(db, cj_amount, args=None):
def create_size_histogram(db, args): def create_size_histogram(db, args):
rows = db.execute('SELECT maxsize FROM orderbook;').fetchall() rows = db.execute('SELECT maxsize, ordertype FROM orderbook;').fetchall()
rows = [o for o in rows if o["ordertype"] in filtered_offername_list]
ordersizes = sorted([r['maxsize'] / 1e8 for r in rows]) ordersizes = sorted([r['maxsize'] / 1e8 for r in rows])
fig = plt.figure() fig = plt.figure()
@ -226,15 +230,15 @@ class OrderbookPageRequestHeader(SimpleHTTPServer.SimpleHTTPRequestHandler):
for row in rows: for row in rows:
o = dict(row) o = dict(row)
if 'cjfee' in o: if 'cjfee' in o:
o['cjfee'] = int(o['cjfee']) if o[ o['cjfee'] = int(o['cjfee']) if o['ordertype']\
'ordertype'] == 'swabsoffer' else float( == 'swabsoffer' else float(o['cjfee'])
o['cjfee'])
result.append(o) result.append(o)
return result return result
def get_counterparty_count(self): def get_counterparty_count(self):
counterparties = self.taker.db.execute( counterparties = self.taker.db.execute(
'SELECT DISTINCT counterparty FROM orderbook;').fetchall() 'SELECT DISTINCT counterparty FROM orderbook WHERE ordertype=? OR ordertype=?;',
filtered_offername_list).fetchall()
return str(len(counterparties)) return str(len(counterparties))
def do_GET(self): def do_GET(self):
@ -331,10 +335,10 @@ class OrderbookPageRequestHeader(SimpleHTTPServer.SimpleHTTPRequestHandler):
self.path = '/' self.path = '/'
self.do_GET() self.do_GET()
elif self.path == '/toggleSW': elif self.path == '/toggleSW':
if filtered_offername_list == offername_list: if filtered_offername_list == swoffers:
filtered_offername_list = ["swreloffer", "swabsoffer"] filtered_offername_list = pkoffers
else: else:
filtered_offername_list = offername_list filtered_offername_list = swoffers
self.path = '/' self.path = '/'
self.do_GET() self.do_GET()

Loading…
Cancel
Save