예제 #1
0
파일: trader.py 프로젝트: agfp/HomeBroker
def place_first_order(max_price, my_order, orders):
    # TODO: receive balance as parameter and check:
    # TODO: 1) is it possible to place before cancel?
    # TODO: 2) do i have balance for creating order?
    if my_order.price == orders[0].price and my_order.amount == orders[0].amount:  # My order is top order
        next_order = find_next_order(my_order.price, orders)
        update, price = False, 0

        if my_order.price - next_order.price > 0.2:  # If price is can be reduced
            log.log_trading('Reducing top order price')
            update = True
            price = next_order.price + 0.1
        elif my_order.amount < TOP_ORDER_PRICE:  # If my top order is less than TOP_ORDER_PRICE BTC
            log.log_trading('Increasing top order amount')
            update = True
            price = my_order.price

        if update:
            bitnz.place_order(price, TOP_ORDER_PRICE)
            bitnz.cancel_order(my_order)
            my_order.price = price
            my_order.amount = TOP_ORDER_PRICE

    elif not my_order.price == max_price:  # If my order is not top order and is not max_price
        log.log_trading('Replacing top order')
        price = orders[0].price + 1e-8
        if price > max_price:
            price = max_price
        bitnz.place_order(price, TOP_ORDER_PRICE)
        bitnz.cancel_order(my_order)
        my_order.price = price
        my_order.amount = TOP_ORDER_PRICE
예제 #2
0
파일: trader.py 프로젝트: agfp/HomeBroker
def delete_overpriced_bids(max_value, orders):
    for i in range(len(orders) - 1, -1, -1):
        if orders[i].price > max_value:
            log.log_trading('Deleting overpriced order')
            bitnz.cancel_order(orders[i])
            del orders[i]
예제 #3
0
파일: bitnz.py 프로젝트: agfp/HomeBroker
def place_order(price, amount):
    response = urllib.request.urlopen(URL_CREATE_ORDER, get_parameters(None, amount, price)).read().decode('utf-8')
    parse = json.loads(response)
    if not parse['result']:
        raise Exception('Error creating order.')
    log.log_trading('+ %.8f  %.8f' % (parse['price'], parse['amount']), 'blue')
예제 #4
0
파일: bitnz.py 프로젝트: agfp/HomeBroker
def cancel_order_by_details(order_id, price, amount):
    response = urllib.request.urlopen(URL_CANCEL_ORDER, get_parameters(order_id)).read().decode('utf-8')
    parse = json.loads(response)
    if not parse['result']:
        raise Exception('Error canceling order.')
    log.log_trading('- %.8f  %.8f' % (price, amount), 'red')