Пример #1
0
 def sign_in_success(self):
     self.bee_ext = CtpbeeApi('default_setting', current_app)
     self.bee_ext.map[EVENT_ACCOUNT] = self.on_account
     self.bee_ext.map[EVENT_CONTRACT] = self.on_contract
     self.bee_ext.map[EVENT_BAR] = self.on_bar
     self.bee_ext.map[EVENT_ORDER] = self.on_order
     self.bee_ext.map[EVENT_POSITION] = self.on_position
     self.bee_ext.map[EVENT_TICK] = self.on_tick
     self.bee_ext.map[EVENT_SHARED] = self.on_shared
     self.bee_ext.map[EVENT_TRADE] = self.on_trade
     self.bee_ext.map[EVENT_TIMER] = self.on_realtime
     #
     contracts = {
         contract.local_symbol: contract.name
         for contract in self.bee_ext.app.recorder.get_all_contracts()
     }
     G.all_contracts = contracts
     self.home_handle()
Пример #2
0
            # main_contract = self.app.recorder.get_main_contract_by_code("ap")
            #
            # # 获取合约的价格
            # # #  如果你需要该合约的最新的行情价格 你可能需要通过self.app.trader.request_market_data() 来更新最新的深度行情,回调函数会自动更新行情数据,
            # # 也许在风控那边一直发送请求数据或者在start()之后开个单独线程来请求是个不错的选择
            # print(self.app.recorder.get_contract_last_price("AP910.CZCE"))
            #
            # # 获取主力合约列表
            # print(self.app.recorder.main_contract_list)
            main_contract = self.app.recorder.get_main_contract_by_code("ap")
            if main_contract:
                self.instrument_set.add(main_contract.local_symbol)
            # print(app.recorder.get_contract("ag1912.SHFE"))


api = CtpbeeApi(extension_name="hi")


@api.route(handler="bar")
def handle_bar(self, bar):
    """ """
    # self.action.short(bar.high_price, 1, bar)


@api.route(handler="tick")
def handle_tick(self, tick):
    """ """
    print(tick._to_df())


@api.route(handler="contract")
Пример #3
0
"""
 本地模拟示例
"""
from datetime import datetime
from time import sleep

from ctpbee import CtpBee
from ctpbee import CtpbeeApi
from ctpbee.constant import BarData, TickData

api = CtpbeeApi("实盘")

pre = CtpbeeApi("模拟")


class Me(CtpbeeApi):
    def on_tick(self, tick: TickData) -> None:
        print(tick)

    def on_bar(self, bar: BarData) -> None:
        print(bar)


@api.route(handler="tick")
def handle_tick(self, tick):
    """ """
    # print("当前时间: ", str(datetime.now()))
    # print("tick时间: ", str(tick.datetime))


@api.route(handler="contract")
Пример #4
0
#         if not auth_time(tick.datetime.time()):
#             """ 过滤非交易时间段的数据 """
#             return
#
#         if self.datetime_queue.empty() or self.datetime_queue.qsize() <= self.queue_length:
#             pass
#         else:
#             q = self.datetime_queue.get()
#             interval = q - tick.datetime
#             if interval > 3600 * 4 or q < tick.datetime:
#                 """ 如果出现间隔过大或者时间小于队列的里面的数据,那么代表着脏数据"""
#                 return
#         self.datetime_queue.put(TimeIt(tick.datetime))
#         database_c[tick.local_symbol].insert_one(tick._to_dict())

api = CtpbeeApi("api")


@api.route(handler="tick")
def handle_tick(self, tick):
    """ """
    print(tick)
    # print("当前时间: ", str(datetime.now()))
    # print("tick时间: ", str(tick.datetime))


@api.route(handler="bar")
def handle_bar(self, bar):
    # print(bar)
    pass