예제 #1
0
def real2_list(args):
    td_db = get_mongodb(setup.trade_db_name)
    ss = td_db.find(si.STRATEGY_INSTANCE_COLLECTION_NAME, {"user": args.user})
    #pprint(ss)
    all_value = 0
    all_his_profit = 0
    all_flo_profit = 0
    all_commission = 0

    title_head_fmt = "%-30s  %10s%12s"
    head_fmt       = "%-30s  %10s(%10.0f)"

    title_profit_fmt = "%21s  %21s  %12s"
    profit_fmt       = "%12.2f(%6.2f%%)  %12.2f(%6.2f%%)  %12.2f"

    title_tail_fmt = "    %-60s  %-20s  %10s"


    print(title_head_fmt % ("instance_id", "value", "") + title_profit_fmt % ("history_profit", "floating_profit", "commission") + title_tail_fmt % ("config_path", "exchange", "status"))
    for s in ss:
        instance_id = s["instance_id"]
        exchange_name = s["exchange"]
        value = s["value"]
        config_path = s["config_path"]
        if "status" in s:
            status = s["status"]
        else:
            status = ""
        if status != args.status and status != "":
            continue

        all_value += value
        profit_info = ""
        try:
            config = xq.get_strategy_config(config_path)
            symbol = config['symbol']
            realEngine = RealEngine(instance_id, exchange_name, config, value)
            orders = realEngine.get_orders(symbol)
            pst_info = realEngine.get_pst_by_orders(orders)
            history_profit, history_profit_rate, history_commission = realEngine.get_history(pst_info)
            all_his_profit += history_profit
            floating_profit, floating_profit_rate, floating_commission, cur_price = realEngine.get_floating(symbol, pst_info)
            all_flo_profit += floating_profit
            commission = history_commission + floating_commission
            all_commission += commission
            profit_info = profit_fmt % (history_profit, history_profit_rate*100, floating_profit, floating_profit_rate*100, commission)

        except Exception as ept:
            profit_info = "error:  %s" % (ept)

        print(head_fmt % (instance_id, value, (value+history_profit+floating_profit)) + profit_info + title_tail_fmt % (config_path, exchange_name, status))

    if args.stat:
        print(head_fmt % ("all", all_value, all_value+all_his_profit+all_flo_profit) + profit_fmt % (all_his_profit, all_his_profit/all_value*100, all_flo_profit, all_flo_profit/all_value*100, all_commission))
예제 #2
0
def real2_list(args):
    td_db = get_mongodb(setup.trade_db_name)
    ss = td_db.find(si.STRATEGY_INSTANCE_COLLECTION_NAME, {"user": args.user})
    #pprint(ss)
    title1_fmt = "%-30s  %10s"
    title2_fmt = "%-60s  %-20s  %10s"
    print((title1_fmt + "    %s    " + title2_fmt) %
          ("instance_id", "value", "     history_profit       floating_profit",
           "config_path", "exchange", "status"))
    for s in ss:
        instance_id = s["instance_id"]
        exchange_name = s["exchange"]
        value = s["value"]
        config_path = s["config_path"]
        if "status" in s:
            status = s["status"]
        else:
            status = ""
        if status != args.status and status != "":
            continue

        profit_info = ""
        try:
            config = xq.get_strategy_config(config_path)
            symbol = config['symbol']
            realEngine = RealEngine(instance_id, exchange_name, config, value)
            orders = realEngine.get_orders(symbol)
            pst_info = realEngine.get_pst_by_orders(orders)
            history_profit, history_profit_rate, history_commission = realEngine.get_history(
                pst_info)
            floating_profit, floating_profit_rate, floating_commission, cur_price = realEngine.get_floating(
                symbol, pst_info)
            profit_info = "%10.2f(%6.2f%%)   %10.2f(%6.2f%%)" % (
                history_profit, history_profit_rate * 100, floating_profit,
                floating_profit_rate * 100)

        except Exception as ept:
            profit_info = "error:  %s" % (ept)

        print((title1_fmt + "    %s    " + title2_fmt) %
              (instance_id, value, profit_info, config_path, exchange_name,
               status))