def _order(self, side, ordertype, pair, volume, price=None, leverage=None, validate=True, oflags=[]): order = { 'pair': pair, 'type': side, 'ordertype': ordertype, 'volume': volume, } if validate: order['validate'] = True if leverage: order['leverage'] = leverage if price: order['price'] = price if oflags != []: order['oflags'] = ','.join(oflags) resp = self._post_request('/0/private/AddOrder', data=order) if resp['error'] != []: raise common.OrderException(resp['error']) return common.Order(resp['result']['txid'][0], ordertype, side, volume, price)
def _market_order(self, side, product_id, size, sandbox=False): order = { 'type': 'market', 'side': side, 'product_id': product_id, 'size': size } resp = self._auth_post('/orders', data=order, sandbox=sandbox) return common.Order(resp['id'], 'market', side, size, resp['executed_value'])
def _order(self, pair, side, ordertype, quantity, **kwargs): # Just add the timestamp here if 'post_only' in kwargs: ordertype = 'LIMIT_MAKER' order = { 'symbol': self.convert_pair(pair).upper(), 'side': side, 'type': ordertype, 'quantity': quantity, 'newOrderRespType': 'FULL', 'timestamp': int(time.time()*1000), 'recvWindow': 10000 } if 'IOC' in kwargs: order['timeInForce'] = 'IOC' if 'FOK' in kwargs: order['timeInForce'] = 'FOK' if ordertype == 'LIMIT': order['price'] = kwargs['price'] if 'timeInForce' not in order: order['timeInForce'] = 'GTC' #order['timeInForce'] = time_in_force elif ordertype == 'LIMIT_MAKER': order['price'] = kwargs['price'] ''' if ordertype == 'LIMIT' or ordertype == 'LIMIT_MAKER': try: order['price'] = kwargs['price'] #order['timeInForce'] = time_in_force except KeyError as e: raise ValueError(f'Missing required parameter for limit order: {e.args[0]}') ''' resp = requests.post(f'{BinanceAPI.ENDPOINT}/api/v3/order', data=order, auth=BinanceAuth(self.api_key, self.api_secret)) try: resp.raise_for_status() except requests.HTTPError as e: raise common.ExchangeException('binance_us', e.response.text) resp = resp.json() return common.Order(resp['orderId'], resp['type'].lower(), resp['side'].lower(), Decimal(resp['origQty']), price=Decimal(resp['price']))
def _order(self, pair, side, price, quantity, **kwargs): data = { 'currencyPair': self.convert_pair(pair), 'rate': price, 'amount': quantity } if 'post_only' in kwargs: data['postOnly'] = '1' if 'IOC' in kwargs: data['immediateOrCancel'] = '1' if 'FOK' in kwargs: data['fillOrKill'] = '1' resp = self._auth_request(side, data=data) if 'error' in resp: raise common.ExchangeException('poloniex', resp['error']) return common.Order(resp['orderNumber'], 'limit', side, Decimal(quantity), price=Decimal(price))
def _limit_order(self, side, product_id, price, size, post_only=False, sandbox=False): params = { #'client_oid': str(uuid.uuid4()), 'type': 'limit', 'side': side, 'product_id': CoinbaseAPI.convert_pair(product_id), 'price': f'{price}', 'size': f'{size}', 'post_only': 'true', # this needs to be based off the variable! 'time_in_force': 'GTC' } log.debug( f'pair: {product_id} price: {params["price"]} quantity: {params["size"]}' ) resp = self._auth_post('/orders', data=params, sandbox=sandbox) return common.Order(resp['id'], 'limit', side, size, price)