basicbot.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:crypto-arbitrager 作者: artooze 项目源码 文件源码
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.warn('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.warn('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, %s" % (type, kexchange, amount, price, order_id))
                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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号