예제 #1
0
def real2_update(args):
    record = {}
    if args.user:
        record["user"] = args.user
    if args.instance_id:
        record["instance_id"] = args.instance_id
    if args.config_path:
        record["config_path"] = args.config_path
    if args.exchange:
        record["exchange"] = args.exchange
    if args.value:
        instance = si.get_strategy_instance(args.sii)
        instance_id = instance["instance_id"]
        exchange_name = instance["exchange"]
        if not exchange_name:
            exchange_name = record["exchange_name"]
        config_path = instance["config_path"]
        if not config_path:
            config_path = record["config_path"]
        value = instance["value"]
        config = xq.get_strategy_config(config_path)
        symbol = config['symbol']
        realEngine = RealEngine(instance_id, exchange_name, config, value)
        orders = realEngine.get_orders(symbol)
        if orders:
            return

        record["value"] = args.value
    if args.status:
        record["status"] = args.status

    if record:
        si.update_strategy_instance({"instance_id": args.sii}, record)
예제 #2
0
파일: real.py 프로젝트: leezizi/xquant
def real_analyze(config, instance_id, exchange_name, value, print_switch_hl,
                 display_rmk):
    symbol = config['symbol']

    realEngine = RealEngine(instance_id, exchange_name, config, value)
    orders = realEngine.get_orders(symbol)
    realEngine.analyze(symbol, orders, print_switch_hl, display_rmk)
예제 #3
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))
예제 #4
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))
예제 #5
0
def real_view(config, instance_id, exchange_name, value):
    symbol = config['symbol']

    realEngine = RealEngine(instance_id, exchange_name, config, value)
    orders = realEngine.get_orders(symbol)
    realEngine.view(symbol, orders)