Esempio n. 1
0
 def post_msg(self, dest, operation):
     assert self.thread_local.name
     dest_queue = self.queue_dict[dest]
     msg = TradeMessage(self.thread_local.name, operation, result_queue=None)
     mylog.notice(dest_queue)
     mylog.notice(operation)
     dest_queue.put(msg)
Esempio n. 2
0
 def sell_stock():
     mylog.notice('Begin sell operation .........')
     stock_code, price = select_price_code()
     oper_sell = ClientOperSell(stock_code, price, 100, EntrustType.FIXED_PRICE)
     context.send_oper(oper_sell)
     self.db.add_operation(oper_sell)
     mylog.notice(f'Sell operation result \n {oper_sell.result}')
Esempio n. 3
0
 def buy_stock():
     mylog.notice('Begin buy operation .........')
     stock_code, price = select_price_code()
     mylog.error(f'-----------{stock_code}, {price}')
     oper_buy = ClientOperBuy(stock_code, price, 100, EntrustType.FIXED_PRICE)
     context.send_oper(oper_buy)
     self.db.add_operation(oper_buy)
     mylog.notice(f'Buy operation result \n {oper_buy.result}')
Esempio n. 4
0
    def handle_bar(self, context, rdr):
        #        open    yclose  price  high   low   name
        # 510900  1.152   1.145  1.151  1.157  1.149  H股ETF
        # 510050  2.490   2.490  2.472  2.494  2.466  50ETF
        mylog.info('On handle bar --------')

        self._push_times += 1
        if self._push_times / 2 != 1:
            # toch
            pass
            # return
        mylog.notice('On handle bar operation')
        prices1 = [val / 1000 + rdr.price[0] for val in range(-5, 5)]
        prices2 = [val / 1000 + rdr.price[1] for val in range(-5, 5)]
        stock_price = [(rdr.index[0], prices1), (rdr.index[1], prices2)]

        def select_price_code():
            sp = choice(stock_price)
            price = choice(sp[1])
            return sp[0], float(price)

        def buy_stock():
            mylog.notice('Begin buy operation .........')
            stock_code, price = select_price_code()
            mylog.error(f'-----------{stock_code}, {price}')
            oper_buy = ClientOperBuy(stock_code, price, 100, EntrustType.FIXED_PRICE)
            context.send_oper(oper_buy)
            self.db.add_operation(oper_buy)
            mylog.notice(f'Buy operation result \n {oper_buy.result}')

        def sell_stock():
            mylog.notice('Begin sell operation .........')
            stock_code, price = select_price_code()
            oper_sell = ClientOperSell(stock_code, price, 100, EntrustType.FIXED_PRICE)
            context.send_oper(oper_sell)
            self.db.add_operation(oper_sell)
            mylog.notice(f'Sell operation result \n {oper_sell.result}')

        def cancel_operation():
            mylog.notice('Begin cancel operation .........')
            if not self.db.query_operation(): return
            oper = choice(self.db.query_operation())
            if isinstance(oper, ClientOperBuy) and oper.result.success:
                cancel_oper = ClientOperCancel(oper.result.entrust_id, oper.stock_code,
                                               EntrustWay.way_buy)
            elif isinstance(oper, ClientOperSell) and oper.result.success:
                cancel_oper = ClientOperCancel(oper.result.entrust_id, oper.stock_code,
                                               EntrustWay.way_sell)
            else:
                return
            context.send_oper(cancel_oper)
            mylog.notice(f'Cancel operation result {cancel_oper}')
            self.db.add_operation(cancel_oper)

        func_list = [buy_stock, sell_stock, cancel_operation]
        func = choice(func_list)
        func()
Esempio n. 5
0
 def cancel_operation():
     mylog.notice('Begin cancel operation .........')
     if not self.db.query_operation(): return
     oper = choice(self.db.query_operation())
     if isinstance(oper, ClientOperBuy) and oper.result.success:
         cancel_oper = ClientOperCancel(oper.result.entrust_id, oper.stock_code,
                                        EntrustWay.way_buy)
     elif isinstance(oper, ClientOperSell) and oper.result.success:
         cancel_oper = ClientOperCancel(oper.result.entrust_id, oper.stock_code,
                                        EntrustWay.way_sell)
     else:
         return
     context.send_oper(cancel_oper)
     mylog.notice(f'Cancel operation result {cancel_oper}')
     self.db.add_operation(cancel_oper)