def get_depth(self, base, alt): book = { "bids" : [], "asks" : [] } pair0 = (base, alt) pair, swapped = self.get_validated_pair(pair0) newbase, newalt = pair slug = newbase + "_" + newalt marketdata = self.unauthenticated_request('markets/data/') depth = marketdata['markets'][slug]['marketdepth'] if swapped: for bid in depth['bids']: o = Order(float(bid['r']), float(bid['q'])) ask = get_swapped_order(o) book['asks'].append(ask) for ask in depth['asks']: o = Order(float(ask['r']), float(ask['q'])) bid = get_swapped_order(o) book['bids'].append(o) else: for bid in depth['bids']: o = Order(float(bid['r']), float(bid['q'])) book['bids'].append(o) for ask in depth['asks']: o = Order(float(ask['r']), float(ask['q'])) book['asks'].append(o) return book
def get_depth(self, base, alt): book = {"bids": [], "asks": []} pair0 = (base, alt) pair, swapped = self.get_validated_pair(pair0) newbase, newalt = pair slug = newbase + "_" + newalt marketdata = self.unauthenticated_request('markets/data/') depth = marketdata['markets'][slug]['marketdepth'] if swapped: for bid in depth['bids']: o = Order(float(bid['r']), float(bid['q'])) ask = get_swapped_order(o) book['asks'].append(ask) for ask in depth['asks']: o = Order(float(ask['r']), float(ask['q'])) bid = get_swapped_order(o) book['bids'].append(o) else: for bid in depth['bids']: o = Order(float(bid['r']), float(bid['q'])) book['bids'].append(o) for ask in depth['asks']: o = Order(float(ask['r']), float(ask['q'])) book['asks'].append(o) return book
def get_depth(self, alt, base): book = {'bids': [], 'asks': []} pair, swapped = self.get_validated_pair((alt, base)) a, b = pair slug = a + "/" + b #print ("slug to fetch order book: %s swaped %s" % (slug, swapped)) data = self.exchange.fetch_order_book(slug) if swapped: for ask in data['asks']: o = Order(float(ask[0]), float(ask[1])) bid = get_swapped_order(o) book['bids'].append(bid) for bid in data['bids']: o = Order(float(bid[0]), float(bid[1])) ask = get_swapped_order(o) book['asks'].append(ask) else: for bid in data['bids']: o = Order(float(bid[0]), float(bid[1])) book['bids'].append(o) for ask in data['asks']: o = Order(float(ask[0]), float(ask[1])) book['asks'].append(o) return book
def get_depth(self, base, alt): pair0 = (base, alt) pair, swapped = self.get_validated_pair(pair0) newbase, newalt = pair marketid = self.get_market_id(newbase, newalt) data = self.api.depth(marketid)['return'] book = { "bids" : [], "asks" : [] } if swapped: for bid in data['buy']: # find out o = Order(float(bid[0]),float(bid[1])) ask = get_swapped_order(o) book['asks'].append(ask) for ask in data['sell']: o = Order(float(ask[0]), float(ask[1])) bid = get_swapped_order(o) book['bids'].append(bid) else: for bid in data['buy']: o = Order(float(bid[0]),float(bid[1])) book['bids'].append(o) for ask in data['sell']: o = Order(float(ask[0]), float(ask[1])) book['asks'].append(o) return book
def get_depth(self, base, alt): pair0 = (base, alt) pair, swapped = self.get_validated_pair(pair0) newbase, newalt = pair marketid = self.get_market_id(newbase, newalt) data = self.api.depth(marketid)['return'] book = {"bids": [], "asks": []} if swapped: for bid in data['buy']: # find out o = Order(float(bid[0]), float(bid[1])) ask = get_swapped_order(o) book['asks'].append(ask) for ask in data['sell']: o = Order(float(ask[0]), float(ask[1])) bid = get_swapped_order(o) book['bids'].append(bid) else: for bid in data['buy']: o = Order(float(bid[0]), float(bid[1])) book['bids'].append(o) for ask in data['sell']: o = Order(float(ask[0]), float(ask[1])) book['asks'].append(o) return book
def get_orders(self, pair, type): """ use this function for accessing the depth info Note that the depth retrieval already flips the order for us based on the ordering that we specified during pair updates. However those pair update orders are arbitrary and we may end up needing both buy(A_B) and sell(B_A) orders with the samedepth info. (TODO - confirm whether the swapped retrieval ever gets called!) we could pre-compute the depth information but it would double the serialized data size. so it's probably easier for now just to re-compute on the fly when we need it again. type = 'bids' or 'asks' """ base, alt = pair slug = base + '_' + alt if slug in self.depth: return self.depth[slug][type] # damn, it's flipped. do we ever actually cross this point? swapped_slug = alt + '_' + base if swapped_slug in self.depth: opposite = 'bids' if type is 'asks' else 'asks' return [ get_swapped_order(o) for o in self.depth[swapped_slug][opposite] ]
def get_depth(self, base, alt): """ coinEx does not support retrieving all depths! GRRRR TODO - need to also append orderID!!! """ pair0 = (base, alt) pair, swapped = self.get_validated_pair(pair0) newbase, newalt = pair pairID = self.get_pairID(newbase, newalt) orders = self.api.get_orders(pairID) book = {"bids": [], "asks": []} for data in orders["orders"]: if not data["complete"]: price = float(data["rate"] * 1e-8) volume = float(data["amount"] * 1e-8) order = Order(price, volume, orderID=data['id'], timestamp=data['created_at']) if not swapped: if data['bid']: # buy order book['bids'].append(order) else: # sell order book['asks'].append(order) else: # is swapped order = get_swapped_order(order) if data['bid']: book['asks'].append(order) else: book['bids'].append(order) return book
def get_depth(self, base, alt): """ coinEx does not support retrieving all depths! GRRRR TODO - need to also append orderID!!! """ pair0 = (base, alt) pair, swapped = self.get_validated_pair(pair0) newbase, newalt = pair pairID = self.get_pairID(newbase, newalt) orders = self.api.get_orders(pairID) book = { "bids" : [], "asks" : [] } for data in orders["orders"]: if not data["complete"]: price = float(data["rate"]*1e-8) volume = float(data["amount"]*1e-8) order = Order(price, volume, orderID=data['id'], timestamp=data['created_at']) if not swapped: if data['bid']: # buy order book['bids'].append(order) else: # sell order book['asks'].append(order) else: # is swapped order = get_swapped_order(order) if data['bid']: book['asks'].append(order) else: book['bids'].append(order) return book
def get_highest_bid(self, pair): base, alt = pair slug = base + "_" + alt if slug in self.depth and len(self.depth[slug]['bids']) > 0: return self.depth[slug]['bids'][0].p swapped_slug = alt + "_" + base if swapped_slug in self.depth and len(self.depth[swapped_slug]['asks']) > 0: print('WEIRD, this shouldn\'t being getting called!') ask = self.rates[swapped_slug]['asks'][0] return get_swapped_order(ask).p return None
def get_highest_bid(self, pair): base, alt = pair slug = base + "_" + alt if slug in self.depth and len(self.depth[slug]['bids']) > 0: return self.depth[slug]['bids'][0].p swapped_slug = alt + "_" + base if swapped_slug in self.depth and len( self.depth[swapped_slug]['asks']) > 0: print('WEIRD, this shouldn\'t being getting called!') ask = self.rates[swapped_slug]['asks'][0] return get_swapped_order(ask).p return None
def get_lowest_ask(self, pair): base, alt = pair slug = base + "_" + alt if slug in self.depth and len(self.depth[slug]['asks']) > 0: return self.depth[slug]['asks'][0].p swapped_slug = alt + "_" + base # note - there should actually be no reason that the swapped low ask gets called, because we are already fetching # all the depths in the order that we would actually see them! if swapped_slug in self.depth and len(self.depth[swapped_slug]['bids']) > 0: print('WEIRD, this shouldn\'t being getting called!') bid = self.rates[swapped_slug]['bids'][0] return get_swapped_order(bid).p return None
def get_lowest_ask(self, pair): base, alt = pair slug = base + "_" + alt if slug in self.depth and len(self.depth[slug]['asks']) > 0: return self.depth[slug]['asks'][0].p swapped_slug = alt + "_" + base # note - there should actually be no reason that the swapped low ask gets called, because we are already fetching # all the depths in the order that we would actually see them! if swapped_slug in self.depth and len( self.depth[swapped_slug]['bids']) > 0: print('WEIRD, this shouldn\'t being getting called!') bid = self.rates[swapped_slug]['bids'][0] return get_swapped_order(bid).p return None
def get_depth(self, base, alt): book = {'bids': [], 'asks': []} pair, swapped = self.get_validated_pair((base, alt)) b,a = pair slug = b.lower() + "_" + a.lower() data = self.api.reqpublic('depth' + '/' + slug) if swapped: for ask in data['asks']: o = Order(float(ask[0]), float(ask[1])) bid = get_swapped_order(o) book['bids'].append(bid) for bid in data['bids']: o = Order(float(bid[0]), float(bid[1])) ask = get_swapped_order(o) book['asks'].append(ask) else: for bid in data['bids']: o = Order(float(bid[0]), float(bid[1])) book['bids'].append(o) for ask in data['asks']: o = Order(float(ask[0]), float(ask[1])) book['asks'].append(o) return book
def get_orders(self, pair, type): """ use this function for accessing the depth info Note that the depth retrieval already flips the order for us based on the ordering that we specified during pair updates. However those pair update orders are arbitrary and we may end up needing both buy(A_B) and sell(B_A) orders with the samedepth info. (TODO - confirm whether the swapped retrieval ever gets called!) we could pre-compute the depth information but it would double the serialized data size. so it's probably easier for now just to re-compute on the fly when we need it again. type = 'bids' or 'asks' """ base, alt = pair slug = base + '_' + alt if slug in self.depth: return self.depth[slug][type] # damn, it's flipped. do we ever actually cross this point? swapped_slug = alt + '_' + base if swapped_slug in self.depth: opposite = 'bids' if type is 'asks' else 'asks' return [get_swapped_order(o) for o in self.depth[swapped_slug][opposite]]