def start(self): if not self._pairs: print("Warning: Pairs not set for Bitstamp client!") return bitstamp_info_url = 'https://www.bitstamp.net/api/v2/trading-pairs-info/' bitstamp_info = json.loads(urlopen(bitstamp_info_url).read().decode()) exchange = exchanges.BitstampExchange.instance() for pair in self._pairs: symbol = ''.join(pair).lower() pair_info = first(bitstamp_info, lambda i: i['url_symbol'] == symbol) name = pair_info['name'] tick_size = Decimal('0.1')**Decimal(pair_info['counter_decimals']) step_size = Decimal('0.1')**Decimal(pair_info['base_decimals']) market_ = market.BasicMarket(name, pair, symbol, exchange, tick_size, step_size) self._markets[symbol] = market_ self._did_recieve[symbol] = False self._pusher.connect()
def __init__(self, name, dr, first_neighbor=None): Zone.__init__(self, name, dr, first_neighbor) self.z_type = "town" self.z_options = ("(M)arket (T)ravel (R)est (I)nventory " + "(C)haracter Sheet\n(Q)uit (S)ave") self.market = market.BasicMarket() """
def _on_open(self, ws): tick_sizes = {} step_sizes = {} exchange_info_url = 'https://api.binance.com/api/v1/exchangeInfo' exchange_info = json.loads(urlopen(exchange_info_url).read().decode()) for symbol_info in exchange_info['symbols']: symbol = symbol_info['symbol'] if symbol not in self._symbols: continue filters = symbol_info['filters'] ftype = 'filterType' tick_size = first(filters, lambda f: f[ftype] == 'PRICE_FILTER')['tickSize'] step_size = first(filters, lambda f: f[ftype] == 'LOT_SIZE')['stepSize'] tick_sizes[symbol] = Decimal(tick_size.rstrip('0')) step_sizes[symbol] = Decimal(step_size.rstrip('0')) for i in range(len(self.pairs)): pair = self.pairs[i] name = '{}/{}'.format(*map(self._convert_sym, pair)) symbol = self._symbols[i] exchange = exchanges.BinanceExchange.instance() ts = tick_sizes[symbol] ss = step_sizes[symbol] market_ = market.BasicMarket(name, pair, symbol, exchange, ts, ss) self.markets.append(market_)
def on_open(self): self.markets = [] disp_names = ['{}/{}'.format(*p) for p in self._pairs] product_info = self._cli.get_products() for i in range(len(self._pairs)): exchange = exchanges.GDAXExchange.instance() try: pinfo = first(product_info, lambda x: x['id'] == self.products[i]) except: print(product_info) exit() tick_size = Decimal(pinfo['quote_increment']) market_ = market.BasicMarket(disp_names[i], self._pairs[i], self.products[i], exchange, tick_size, Decimal('0.00000001')) self.markets.append(market_) self.channels = [ { 'name': 'level2', 'product_ids': self.products }, { 'name': 'matches', 'product_ids': self.products } ]
def start(self): if self.is_running(): return # I looked these tick sizes up myself because there's no way to grab # them programmatically without a web crawler. Subject to change. tick_sizes = { BITCOIN: Decimal('1000'), ETHEREUM: Decimal('100'), DASH: Decimal('100'), LITECOIN: Decimal('50'), ETHEREUM_CLASSIC: Decimal('10'), RIPPLE: Decimal('1'), BCASH: Decimal('500'), MONERO: Decimal('100'), ZCASH: Decimal('100'), QTUM: Decimal('10'), BGOLD: Decimal('100'), EOS: Decimal('1') } step_size = Decimal('0.00000001') for pair in self.pairs: name = '{}/{}'.format(*pair) symbol = pair[0] exchange = exchanges.BithumbExchange.instance() tick_size = tick_sizes[symbol] market_ = market.BasicMarket(name, pair, symbol, exchange, tick_size, step_size) self.markets.append(market_) ws_url = 'wss://wss.bithumb.com/public' header = 'Origin: https://bithumb.com' ws = websocket.create_connection(ws_url, header=header) data = {'currency': symbol, 'service': 'orderbook'} msg = json.dumps(data).encode() ws.send(msg) header = ['Origin: https://www.bithumb.com'] for pair in self.pairs: name = '{}/{}'.format()
from decimal import Decimal import exchanges import json import market import traceback import websocket url = 'wss://wss.bithumb.com/public' if __name__ == '__main__': market_ = market.BasicMarket('ETH/KRW', ('ETH', 'KRW'), 'ETH', 'Bithumb', Decimal('100'), Decimal('0.00000001')) i = 0 currencies = ['BTC', 'ETH', 'LTC', 'XMR', 'DASH'] def o(ws): pass def m(ws, msg_str): msg = json.loads(msg_str) if msg['header']['service'] == 'orderbook': print(msg['header']['currency']) print(msg['data'], end='\n\n') global i send_data = json.dumps({ 'currency': currencies[i % len(currencies)], 'service': 'orderbook' })