Exemplo n.º 1
0
    def _bc_sendOrder(self, vtSymbol, direction, offset, price, volume,
                      pfName):
        """记录交易数据(由portfolio调用)"""

        # 记录成交数据
        dt = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
        time.sleep(0.01)
        order_id = str(int(time.time()))

        r = [[
            dt, pfName, order_id, 'minx', vtSymbol, direction, offset, price,
            volume
        ]]
        #print('send order: ', r)
        to_log(str(r)[3:-2])
        fn = 'fut/engine/engine_deal.csv'
        a_file(fn, str(r)[2:-2])

        priceTick = get_contract(vtSymbol).price_tick
        price = int(round(price / priceTick, 0)) * priceTick

        if self.gateway is not None:
            # self.gateway._bc_sendOrder(dt, vtSymbol, direction, offset, price_deal, volume, pfName)
            threading.Thread(target=self.gateway._bc_sendOrder,
                             args=(dt, vtSymbol, direction, offset, price,
                                   volume, pfName)).start()
Exemplo n.º 2
0
def fut_owl():
    tips = ''
    if request.method == "POST":
        if request.form.get('token') != '9999':
            tips = 'token error'
        else:
            code = del_blank( request.form.get('code') )
            ins_type = del_blank( request.form.get('ins_type') )
            price = del_blank( float(request.form.get('price')) )
            num = del_blank( int(request.form.get('num')) )

            ins = str({'ins':ins_type,'price':price,'num':num})
            fn = 'fut/engine/owl/signal_owl_mix_var_' + code + '.csv'
            # fn = get_dss() + 'fut/engine/owl/signal_owl_mix_var_' + code + '.csv'
            a_file(fn,ins)

            # 历史维护记录
            now = datetime.now()
            today = now.strftime('%Y-%m-%d %H:%M:%S')
            ins = str({'date':today,'ins':ins_type,'price':price,'num':num})
            fn = 'fut/engine/owl/history.csv'
            a_file(fn,ins)

            tips = 'append success'

    return render_template("owl.html",tip=tips)
Exemplo n.º 3
0
    def _bc_sendOrder(self, vtSymbol, direction, offset, price, volume,
                      pfName):
        """记录交易数据(由portfolio调用)"""
        priceTick = get_contract(vtSymbol).price_tick
        price = int(round(price / priceTick, 0)) * priceTick

        sp = get_contract(vtSymbol).sp
        if sp in ['SP', 'SPC', 'SPD', 'IPS', 'CUS']:
            vtSymbol = sp + ' ' + vtSymbol

        # 记录成交数据
        dt = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
        # time.sleep(0.01)
        order_id = str(int(time.time()))

        r = [[
            dt, pfName, order_id, 'minx', vtSymbol, direction, offset, price,
            volume
        ]]
        #print('send order: ', r)
        to_log(str(r)[3:-2])
        fn = get_dss() + 'fut/engine/engine_deal.csv'
        a_file(fn, str(r)[2:-2])

        if self.gateway is not None:
            if sp == 'CUS':
                symbols = vtSymbol[4:]
                symbol_list = symbols.split('&')
                s0 = symbol_list[0]
                price0 = get_tick(s0)['LastPrice']
                s1 = symbol_list[1]
                price1 = get_tick(s1)['LastPrice']

                threading.Thread(target=self.gateway._bc_sendOrder,
                                 args=(dt, s0, direction, offset, price0,
                                       volume, pfName)).start()
                if direction == DIRECTION_LONG:
                    threading.Thread(target=self.gateway._bc_sendOrder,
                                     args=(dt, s1, DIRECTION_SHORT, offset,
                                           price1, volume, pfName)).start()
                if direction == DIRECTION_SHORT:
                    threading.Thread(target=self.gateway._bc_sendOrder,
                                     args=(dt, s1, DIRECTION_LONG, offset,
                                           price1, volume, pfName)).start()
            else:
                # self.gateway._bc_sendOrder(dt, vtSymbol, direction, offset, price_deal, volume, pfName)
                threading.Thread(target=self.gateway._bc_sendOrder,
                                 args=(dt, vtSymbol, direction, offset, price,
                                       volume, pfName)).start()
Exemplo n.º 4
0
    def _bc_sendOrder(self, vtSymbol, direction, offset, price, volume, pfName):
        """记录交易数据(由portfolio调用)"""

        # 记录成交数据
        dt = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime())
        time.sleep(0.1)
        order_id = str(int(time.time()))

        r = [[dt,pfName,order_id,'minx',vtSymbol, direction, offset, price, volume]]
        print('send order: ', r)
        fn = get_dss() + 'fut/engine/engine_deal.csv'
        a_file(fn, str(r)[2:-2])

        if self.gateway is not None:
            self.gateway._bc_sendOrder(vtSymbol, direction, offset, price, volume, pfName)
Exemplo n.º 5
0
def stare_ins():
    print('stare_ins begin... ')
    item_list = []
    del_list = []
    filename = 'csv/ins.txt'
    while True:
        try:
            time.sleep(3)
            if is_trade_time():
                # 读入ins文件后清空
                new_ins = rc_file(filename)

                # 分离 'del' 指令与其它指令,将其它指令加入到列表中
                c = []
                for i, item in enumerate(new_ins):
                    if item['ins'] == 'del':
                        del_list.append(item)
                    else:
                        c.append(item)
                item_list += c

                # 处理 'del' 指令
                if del_list != []:
                    d = del_list.pop()
                    for i, item in enumerate(item_list):
                        if item['code'] == d['code'] and item['num'] == d[
                                'num'] and item['price'] == d['price']:
                            item_list.pop(i)
                            break
                # 处理其他指令
                for i, item in enumerate(item_list):
                    if deal_single_ins(item):
                        item_list.pop(i)
                        break
            else:
                time.sleep(300)
                if item_list != []:
                    # 将未触发的指令保存到文件中
                    for i, item in enumerate(item_list):
                        a_file(filename, str(item))
                    item_list = []
        except Exception as e:
            print("error: ")
            print(e)
Exemplo n.º 6
0
    def _bc_sendOrder(self, vtSymbol, direction, offset, price, volume,
                      pfName):
        """记录交易数据(由portfolio调用)"""

        # 记录成交数据
        dt = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
        time.sleep(0.1)
        order_id = str(int(time.time()))

        r = [[
            dt, pfName, order_id, self.minx, vtSymbol, direction, offset,
            price, volume
        ]]
        print('send order: ', r)

        # df = pd.DataFrame(r, columns=['datetime','order_id','pfname','minx','vtSymbol', 'direction', 'offset', 'price', 'volume'])
        # fn = get_dss() + 'fut/deal.csv'
        # df.to_csv(fn, index=False, mode='a')

        fn = 'fut/deal.csv'
        a_file(fn, str(r)[2:-2])
Exemplo n.º 7
0
def confirm_ins():
    if request.form.get('token') != '9999':
        return redirect('/')

    ins_type = request.form.get('ins_type')
    code = request.form.get('code')
    num = int(request.form.get('num'))
    price = float(request.form.get('price'))
    cost = int(num * price)
    portfolio = request.form.get('portfolio')
    agent = request.form.get('agent')

    df = ts.get_realtime_quotes(code)
    name = df.at[0, 'name']
    if ins_type in ['down_sell', 'sell_order', 'buy_order']:
        ins = str({
            'ins': ins_type,
            'portfolio': portfolio,
            'code': code,
            'num': num,
            'price': price,
            'cost': cost,
            'agent': agent,
            'name': name
        })
    if ins_type in ['up_warn', 'down_warn', 'del']:
        ins = str({
            'ins': ins_type,
            'code': code,
            'num': num,
            'price': price,
            'name': name
        })

    filename = 'csv/ins.txt'

    a_file(filename, ins)
    return 'success: ' + ins