| | |
| | | |
| | | from __future__ import print_function, absolute_import |
| | | |
| | | import schedule |
| | | |
| | | # import gm.api as gmapi |
| | | from cancel_strategy.s_l_h_cancel_strategy import LCancelBigNumComputer |
| | | from code_attribute import big_money_num_manager, global_data_loader, gpcode_manager, gpcode_first_screen_manager |
| | | from code_attribute.code_nature_analyse import LatestMaxVolumeManager, HighIncreaseCodeManager, CodeNatureRecordManager |
| | | from db.redis_manager_delegate import RedisUtils |
| | | from l2.l2_sell_manager import L2MarketSellManager |
| | | from l2.l2_transaction_data_manager import HuaXinBuyOrderManager |
| | | from ths import client_manager |
| | | import constant |
| | | from third_data.third_blocks_manager import InvalidBlockManager, CodeThirdBlocksManager |
| | | from trade.buy_money_count_setting import BuyMoneyAndCountSetting |
| | | from trade.deal_big_money_manager import DealOrderNoManager |
| | | from trade.trade_manager import AccountAvailableMoneyManager, AutoCancelSellModeManager |
| | | from utils import global_util, tool |
| | | import threading |
| | | from trade.trade_manager import AutoCancelSellModeManager |
| | | from utils import tool |
| | | |
| | | import server |
| | | |
| | | from db import redis_manager_delegate as redis_manager |
| | | from user import authority |
| | | import decimal |
| | | |
| | | from third_data.history_k_data_util import HistoryKDatasUtils |
| | | from trade import l2_trade_util, trade_manager |
| | | from trade import l2_trade_util |
| | | from l2.cancel_buy_strategy import L2LimitUpSellStatisticUtil |
| | | from log_module.log import logger_juejin_tick, logger_system |
| | | from trade.trade_data_manager import CodeActualPriceProcessor, PlaceOrderCountManager |
| | | from trade.trade_queue_manager import JueJinBuy1VolumnManager |
| | | |
| | | redisManager = redis_manager.RedisManager(0) |
| | | __jueJinBuy1VolumnManager = JueJinBuy1VolumnManager() |
| | | __actualPriceProcessor = CodeActualPriceProcessor() |
| | | |
| | | |
| | | # 设置账户信息 |
| | | def setAccountInfo(accountId, strategyId, token): |
| | | redis = redisManager.getRedis() |
| | | try: |
| | | RedisUtils.set(redis, "juejin-account-id", accountId, auto_free=False) |
| | | RedisUtils.set(redis, "juejin-strategy-id", strategyId, auto_free=False) |
| | | RedisUtils.set(redis, "juejin-token", token, auto_free=False) |
| | | finally: |
| | | RedisUtils.realse(redis) |
| | | |
| | | |
| | | def getAccountInfo(): |
| | | redis = redisManager.getRedis() |
| | | try: |
| | | account_id = RedisUtils.get(redis, "juejin-account-id", auto_free=False) |
| | | strategy_id = RedisUtils.get(redis, "juejin-strategy-id", auto_free=False) |
| | | token = RedisUtils.get(redis, "juejin-token", auto_free=False) |
| | | return account_id, strategy_id, token |
| | | finally: |
| | | RedisUtils.realse(redis) |
| | | from log_module.log import logger_system |
| | | from trade.trade_data_manager import PlaceOrderCountManager, AccountMoneyManager |
| | | from utils.ths_industry_util import ThsCodeIndustryManager |
| | | |
| | | |
| | | def init_data(): |
| | |
| | | # 载入量 |
| | | global_data_loader.load_volumn() |
| | | # 初始化载入 |
| | | AccountAvailableMoneyManager() |
| | | AccountMoneyManager() |
| | | # 初始化载入 |
| | | AutoCancelSellModeManager() |
| | | |
| | | ThsCodeIndustryManager() |
| | | |
| | | InvalidBlockManager() |
| | | |
| | | CodeThirdBlocksManager() |
| | | |
| | | BuyMoneyAndCountSetting() |
| | | |
| | | gpcode_manager.WantBuyCodesManager() |
| | | |
| | | # 9点25之前删除所有代码 |
| | | if tool.trade_time_sub(tool.get_now_time_str(), "09:25:00") <= 0: |
| | |
| | | gpcode_manager.WhiteListCodeManager().clear() |
| | | # 清空想要买 |
| | | gpcode_manager.WantBuyCodesManager().clear() |
| | | # 清空分数禁止代码 |
| | | trade_manager.ForbiddenBuyCodeByScoreManager().clear() |
| | | # 清空暂停交易代码 |
| | | gpcode_manager.PauseBuyCodesManager().clear() |
| | | # 清除L撤数据 |
| | |
| | | # if not tool.is_init_time() or True: |
| | | # raise Exception("交易时间不能初始化") |
| | | init_data() |
| | | codes = gpcode_manager.get_gp_list() |
| | | logger_system.info("每日初始化") |
| | | |
| | | # 今日实时涨停 |
| | | global_data_loader.add_limit_up_codes([], True) |
| | | # 主要获取收盘价 |
| | | __get_latest_info(None) |
| | | # 获取60天最大量与昨日量 |
| | | global_util.today_volumn.clear() |
| | | global_util.max60_volumn.clear() |
| | | global_util.yesterday_volumn.clear() |
| | | # 清除大单数据 |
| | | global_util.big_money_num.clear() |
| | | # 初始化大单数据 |
| | | for code in codes: |
| | | big_money_num_manager.add_num(code, 0) |
| | | big_money_num_manager.expire(code) |
| | | # 清除涨停时间 |
| | | global_util.limit_up_time.clear() |
| | | |
| | | # 初始化同花顺主站 |
| | | if constant.L2_SOURCE_TYPE == constant.L2_SOURCE_TYPE_THS: |
| | | l2_clients = client_manager.getValidL2Clients() |
| | | for client in l2_clients: |
| | | try: |
| | | server.repair_ths_main_site(client) |
| | | except Exception as e: |
| | | pass |
| | | |
| | | |
| | | def __run_schedule(): |
| | | while True: |
| | | schedule.run_pending() |
| | | |
| | | |
| | | def init(context): |
| | | # gmapi.subscribe(symbols="SZSE.002529", frequency="1d", count=30) |
| | | # 订阅浦发银行, bar频率为一天和一分钟 |
| | | # 订阅订阅多个频率的数据,可多次调用subscribe |
| | | # 获取需要监听的股票 |
| | | init_data() |
| | | logger_system.info("掘金初始化") |
| | | schedule.every().day.at("09:15:00").do(everyday_init) |
| | | t1 = threading.Thread(target=lambda: __run_schedule()) |
| | | # 后台运行 |
| | | t1.setDaemon(True) |
| | | t1.start() |
| | | |
| | | # 多个时间点获取收盘价 |
| | | gmapi.schedule(schedule_func=__get_latest_info, date_rule='1d', time_rule='09:28:00') |
| | | |
| | | # 初始化内容 |
| | | clients = authority.get_l2_clients() |
| | | for client in clients: |
| | | for i in range(0, constant.L2_CODE_COUNT_PER_DEVICE): |
| | | gpcode_manager.init_listen_code_by_pos(client, i) |
| | | |
| | | |
| | | def __get_latest_info(context): |
| | | # 初始化内容 |
| | | clients = authority.get_l2_clients() |
| | | for c in clients: |
| | | for i in range(0, constant.L2_CODE_COUNT_PER_DEVICE): |
| | | gpcode_manager.init_listen_code_by_pos(int(c), i) |
| | | codes = gpcode_manager.get_gp_list() |
| | | result = HistoryKDatasUtils.get_gp_latest_info(codes) |
| | | for item in result: |
| | | sec_level = item['sec_level'] |
| | | symbol = item['symbol'] |
| | | symbol = symbol.split(".")[1] |
| | | pre_close = tool.to_price(decimal.Decimal(str(item['pre_close']))) |
| | | if sec_level == 1: |
| | | if symbol in codes: |
| | | gpcode_manager.CodePrePriceManager.set_price_pre(symbol, pre_close) |
| | | else: |
| | | gpcode_manager.rm_gp(symbol) |
| | | |
| | | |
| | | # 获取最新的信息 |
| | | def __get_current_info(): |
| | | data = gpcode_manager.get_gp_list() |
| | | results = HistoryKDatasUtils.get_gp_current_info(data) |
| | | logger_juejin_tick.debug("定时获取:{}", results) |
| | | for result in results: |
| | | price = result["price"] |
| | | symbol = result['symbol'] |
| | | # 保存最新价 |
| | | symbol = symbol.split(".")[1] |
| | | |
| | | |
| | | __prices_now = {} |
| | | |
| | | |
| | | # 保存运行时数据 |