def sell_more_batch(coin_name, time_type, latest_price, lever_rate = 20):
    global processing
    processing = True
    jRet = json.loads(okFuture.future_position_4fix(coin_name+"_usd", time_type, "1"))
    print(jRet)
    flag = True
    ret = u'没有做多订单'
    while len(jRet["holding"]) > 0:
        cancel_uncompleted_order(coin_name, time_type)
        if flag:
            flag = False
            amount = jRet["holding"][0]["buy_available"]
            order_data = gen_orders_data(latest_price, amount, 3, 5)
            ret = okFuture.future_batchTrade(coin_name + "_usd", time_type, order_data, lever_rate)
        else:
            buy_available = jRet["holding"][0]["buy_available"]
            ret = okFuture.future_trade(coin_name + "_usd", time_type, '', buy_available, 3, 1, lever_rate)
        if 'true' in ret:
            time.sleep(2)
            jRet = json.loads(okFuture.future_position_4fix(coin_name + "_usd", time_type, "1"))

    sell_more_suc()
    email_msg = "做多%s批量卖出成交, 时间: %s, 成交结果: %s" \
                % (coin_name, timestamp2string(time.time()), ret)
    thread.start_new_thread(send_email, (email_msg,))
    processing = False
    return True
def sell_less_batch(coin_name, time_type, latest_price, lever_rate=20):
    jRet = json.loads(
        okFuture.future_position_4fix(coin_name + "_usd", time_type, "1"))
    ret = u'没有做空订单'
    while len(jRet["holding"]) > 0:
        amount = jRet["holding"][0]["sell_available"]
        order_data = gen_orders_data(latest_price, amount, 4, 5)
        ret = okFuture.future_batchTrade(coin_name + "_usd", time_type,
                                         order_data, lever_rate)
        if 'true' in ret:
            break
        else:
            sell_available = jRet["holding"][0]["sell_available"]
            ret = okFuture.future_trade(coin_name + "_usd", time_type, '',
                                        sell_available, 4, 1, lever_rate)
            if 'true' in ret:
                break
            else:
                return False

    return True
Example #3
0
def sell_more_batch(coin_name, time_type, latest_price, lever_rate=20):
    global processing, more2less
    processing = True
    jRet = json.loads(
        okFuture.future_position_4fix(coin_name + "_usd", time_type, "1"))
    print(jRet)
    flag = True
    ret = u'没有做多订单'
    while len(jRet["holding"]) > 0:
        cancel_uncompleted_order(coin_name, time_type)
        if flag:
            flag = False
            amount = jRet["holding"][0]["buy_available"]
            order_data = gen_orders_data(latest_price, amount, 3, 5)
            ret = okFuture.future_batchTrade(coin_name + "_usd", time_type,
                                             order_data, lever_rate)
        else:
            buy_available = jRet["holding"][0]["buy_available"]
            ret = okFuture.future_trade(coin_name + "_usd", time_type, '',
                                        buy_available, 3, 1, lever_rate)
        if 'true' in ret:
            time.sleep(5)
            jRet = json.loads(
                okFuture.future_position_4fix(coin_name + "_usd", time_type,
                                              "1"))

    sell_more_suc()
    if more2less == 1:
        if buyin_less(coin_name, time_type, latest_price):
            info = u'发出反手做空信号!!!买入价格:' + str(latest_price)
            with codecs.open(file_transaction, 'a+', 'utf-8') as f:
                f.writelines(info + '\n')
        else:
            more2less = 0
    email_msg = "做多%s批量卖出成交, 时间: %s, 成交结果: %s" \
                % (coin_name, timestamp2string(time.time()), ret)
    thread.start_new_thread(send_email, (email_msg, ))
    processing = False
    return True