def new_order(self, kexchange, type, maker_only=True, amount=None, price=None):
if type == 'buy' or type == 'sell':
if not price or not amount:
if type == 'buy':
price = self.get_buy_price()
amount = math.floor((self.cny_balance/price)*10)/10
else:
price = self.get_sell_price()
amount = math.floor(self.btc_balance * 10) / 10
if maker_only:
amount = min(self.max_maker_volume, amount)
if amount < self.min_maker_volume:
logging.debug('Maker amount is too low %s %s' % (type, amount))
return None
else:
amount = min(self.max_taker_volume, amount)
if amount < self.min_taker_volume:
logging.debug('Taker amount is too low %s %s' % (type, amount))
return None
if maker_only:
if type == 'buy':
order_id = self.clients[kexchange].buy_maker(amount, price)
else:
order_id = self.clients[kexchange].sell_maker(amount, price)
else:
if type == 'buy':
order_id = self.clients[kexchange].buy(amount, price)
else:
order_id = self.clients[kexchange].sell(amount, price)
if not order_id:
logging.warn("%s @%s %f/%f BTC failed" % (type, kexchange, amount, price))
return None
if order_id == -1:
logging.warn("%s @%s %f/%f BTC failed, %s" % (type, kexchange, amount, price, order_id))
return None
order = {
'market': kexchange,
'id': order_id,
'price': price,
'amount': amount,
'deal_amount':0,
'deal_index': 0,
'type': type,
'maker_only': maker_only,
'time': time.time()
}
self.orders.append(order)
logging.verbose("submit order %s" % (order))
return order
return None
评论列表
文章目录