예제 #1
0
def draw_line_up(price):
    global GRID_BIT_AMOUNT
    global CURR_PRICE
    while True:
        if HIGHEST - LOWEST > 100:
            break

        while abs(CURR_PRICE - price) > 10:
            sleep(60)

        amount = GRID_BIT_AMOUNT
        print "up" + str(price)
        high_price = price
        # high_amount = GRID_MONEY_HALF / high_price
        # s_trade_id, s_order_id = sure_sell(high_price, high_amount)
        # print "sell_order price is :" + str(high_price)

        #  BIT_COIN amount as trade Unit
        s_trade_id, s_order_id = sure_sell(high_price, amount)
        # print "befor mysql"
        db_helper.insert_order(s_order_id, s_trade_id, 1, high_price, amount, 0)

        # half trade had finished, delete from orders table, add to half_trades table
        price1 = sure_order_success(1, s_order_id, price, True)
        if False == price1:
            sure_cancel(s_order_id)
            db_helper.delete_order(s_order_id)
            continue
        db_helper.delete_order(s_order_id)
        db_helper.insert_half_trade(s_order_id, s_trade_id, 1, price1, amount)

        print 'UP Sell %10.2f' % high_price
        logger.info('UP Sell %10.2f' % high_price)

        low_price = price - GRID_MONEY_SPAN
        # low_amount = GRID_MONEY_HALF / low_price
        # b_trade_id, b_order_id = sure_buy(low_price, low_amount)
        # print "buy_order price is :" + str(low_price)

        b_trade_id, b_order_id = sure_buy(low_price, amount)
        db_helper.insert_order(b_order_id, b_trade_id, 1, low_price, amount, 1)

        # two-way trade had finished, delete from orders table and half_trades table, add to trades table
        price2 = sure_order_success(1, b_order_id, price)
        db_helper.delete_order(b_order_id)
        db_helper.delete_half_trade(s_order_id)
        db_helper.insert_trades(s_order_id, s_trade_id, b_order_id, b_trade_id, 1,
                                price1, price2, amount)
        print 'UP Buy %10.2f' % low_price
        logger.info('UP Buy %10.2f' % low_price)

        logger.info("UP gain profit! %10.2f -- %10.2f" % (price1, price2))
        print "======================"
        print "UP gain profit! %10.2f -- %10.2f" % (price1, price2)
        print "======================"
예제 #2
0
def draw_line_up(price):
    global GRID_BIT_AMOUNT
    while True:
        amount = GRID_BIT_AMOUNT
        print "up" + str(price)
        high_price = price
        # high_amount = GRID_MONEY_HALF / high_price
        # s_trade_id, s_order_id = sure_sell(high_price, high_amount)
        # print "sell_order price is :" + str(high_price)

        #  BIT_COIN amount as trade Unit
        s_trade_id, s_order_id = sure_sell(high_price, amount)
        # print "befor mysql"
        db_helper.insert_order(s_order_id, s_trade_id, 1, high_price, amount,
                               0)

        # half trade had finished, delete from orders table, add to half_trades table
        sure_order_success(1, s_order_id, price)
        db_helper.delete_order(s_order_id)
        db_helper.insert_half_trade(s_order_id, s_trade_id, 1, high_price,
                                    amount)

        print 'UP Sell %10.2f' % high_price
        logger.info('UP Sell %10.2f' % high_price)

        low_price = price - GRID_MONEY_SPAN
        # low_amount = GRID_MONEY_HALF / low_price
        # b_trade_id, b_order_id = sure_buy(low_price, low_amount)
        # print "buy_order price is :" + str(low_price)

        b_trade_id, b_order_id = sure_buy(low_price, amount)
        db_helper.insert_order(b_order_id, b_trade_id, 1, low_price, amount, 1)

        # two-way trade had finished, delete from orders table and half_trades table, add to trades table
        sure_order_success(1, b_order_id, price)
        db_helper.delete_order(b_order_id)
        db_helper.delete_half_trade(s_order_id)
        db_helper.insert_trades(s_order_id, s_trade_id, b_order_id, b_trade_id,
                                1, high_price, low_price, amount)
        print 'UP Buy %10.2f' % low_price
        logger.info('UP Buy %10.2f' % low_price)

        logger.info("UP gain profit! %10.2f -- %10.2f" %
                    (high_price, low_price))
        print "======================"
        print "UP gain profit! %10.2f -- %10.2f" % (high_price, low_price)
        print "======================"
예제 #3
0
def draw_line_down(price):
    global GRID_BIT_AMOUNT
    while True:
        amount = GRID_BIT_AMOUNT
        print "down" + str(price)
        low_price = price
        # low_amount = GRID_MONEY_HALF / low_price
        # b_trade_id, b_order_id = sure_buy(low_price, low_amount)
        # print "buy_order price is :" + str(low_price)

        b_trade_id, b_order_id = sure_buy(low_price, amount)
        db_helper.insert_order(b_order_id, b_trade_id, -1, low_price, amount,
                               0)

        # half trade had finished, delete from orders table, add to half_trades table
        sure_order_success(1, b_order_id, price)
        db_helper.delete_order(b_order_id)
        db_helper.insert_half_trade(b_order_id, b_trade_id, -1, low_price,
                                    amount)

        print 'DOWN Buy %10.2f' % low_price
        logger.info('DOWN Buy %10.2f' % low_price)

        high_price = price + GRID_MONEY_SPAN
        # high_amount = GRID_MONEY_HALF / high_price
        # s_trade_id, s_order_id = sure_sell(high_price, high_amount)
        # print "sell_order price is :" + str(high_price)

        s_trade_id, s_order_id = sure_sell(high_price, amount)
        db_helper.insert_order(s_order_id, s_trade_id, -1, high_price, amount,
                               1)

        # two-way trade had finished, delete from orders table and half_trades table, add to trades table
        sure_order_success(1, s_order_id, price)
        db_helper.delete_order(s_order_id)
        db_helper.delete_half_trade(b_order_id)
        db_helper.insert_trades(b_order_id, b_trade_id, s_order_id, s_trade_id,
                                -1, low_price, high_price, amount)

        print 'DOWN Sell %10.2f' % high_price
        logger.info('DOWN Sell %10.2f' % high_price)

        logger.info("DOWN gain profit! %10.2f -- %10.2f" %
                    (low_price, high_price))
        print "======================"
        print "DOWN gain profit! %10.2f -- %10.2f" % (low_price, high_price)
        print "======================"
예제 #4
0
def reverse_draw_up(reverse_price, price, amount, forward_order_id=0, forward_trade_id=0):
    b_trade_id, b_order_id = sure_buy(reverse_price, amount)
    db_helper.insert_order(b_order_id, b_trade_id, 1, reverse_price, amount, 1)

    # two-way trade had finished, delete from orders table and half_trades table, add to trades table
    sure_order_success(1, b_order_id, reverse_price)
    db_helper.delete_order(b_order_id)
    db_helper.delete_half_trade(forward_order_id)
    db_helper.insert_trades(forward_order_id, forward_trade_id, b_order_id, b_trade_id, 1,
                            price, reverse_price, amount)
    print 'UP Buy %10.2f' % reverse_price
    logger.info('UP Buy %10.2f' % reverse_price)

    logger.info("UP gain profit! %10.2f -- %10.2f" % (price, reverse_price))
    print "======================"
    print "UP gain profit! %10.2f -- %10.2f" % (price, reverse_price)
    print "======================"
    spawn(draw_line_up, price)
예제 #5
0
def reverse_draw_down(reverse_price, price, amount, forward_order_id=0, forward_trade_id=0):
    s_trade_id, s_order_id = sure_sell(reverse_price, amount)
    db_helper.insert_order(s_order_id, s_trade_id, -1, reverse_price, amount, 1)

    # two-way trade had finished, delete from orders table and half_trades table, add to trades table
    sure_order_success(1, s_order_id, reverse_price)
    db_helper.delete_order(s_order_id)
    db_helper.delete_half_trade(forward_order_id)
    db_helper.insert_trades(forward_order_id, forward_trade_id, s_order_id, s_trade_id, -1,
                            price, reverse_price, amount)

    print 'DOWN Sell %10.2f' % reverse_price
    logger.info('DOWN Sell %10.2f' % reverse_price)

    logger.info("DOWN gain profit! %10.2f -- %10.2f" % (price, reverse_price))
    print "======================"
    print "DOWN gain profit! %10.2f -- %10.2f" % (price, reverse_price)
    print "======================"
    spawn(draw_line_down, price)