def marketBuy(self, orderQuantity, asset, currency, note=None): result = self.market.Order.Order_new(symbol=asset + currency, orderQty=orderQuantity, ordType="Market").result() logger.logOrder('Bitmex', 'market', self.getCurrentPrice(asset, currency), asset, currency, orderQuantity, note=note) return result
def limitBuy(self, price, asset, currency, orderQuantity, orderId=None, note=None): result = None openOrder = self.orderOpen(orderId) if openOrder and orderQuantity != 0: try: result = self.market.Order.Order_amend(orderID=orderId, price=price).result() logger.logOrder( self.marketName, 'Limit', price, asset, currency, orderQuantity, str(note) + ' amend for order: ' + str(orderId)) except Exception as e: if e.response.status_code == 400: logger.logError('LIMIT AMEND ERROR') orderQuantity = self.quantityLeftInOrder( orderId, orderQuantity) if orderQuantity != 0: openOrder = False else: logger.logError('UNKNOWN LIMIT ERROR: ' + str(e)) raise e if not openOrder and orderQuantity != 0: result = self.market.Order.Order_new( symbol=asset + currency, orderQty=orderQuantity, ordType="Limit", price=price, execInst='ParticipateDoNotInitiate').result() logger.logOrder(self.marketName, 'Limit', price, asset, currency, orderQuantity, note) if result is not None: tradeInfo = result[0] for key, value in tradeInfo.items(): if key == "orderID": newOrderId = (key + ": {0}".format(value)) return newOrderId[9:] else: return None
def marketBuy(self, orderSize, asset, currency, note): if self.real_money: result = self.market.order_market_buy(symbol=asset + currency, quantity=orderSize) logger.logOrder('Binance', 'market', self.getCurrentPrice(asset, currency), asset, currency, orderSize, note=note) return result else: result = self.market.create_test_order(symbol=asset + currency, side='BUY', type='MARKET', timeInForce='GTC', quantity=orderSize)