2022-09-04 19:56:14,149 - INFO - {'log_id': 'cd9c512b-477b-475d-8f89-af43a817e4da', 'process': 'main', 'detail': '行情接口登錄成功'} 股票池: ['000009.SZ', '002002.SZ', '002191.SZ', '600031.SH', '600690.SH', '601668.SH', '600570.SH'] 2022-09-04 19:56:14,468 - INFO - {'log_id': 'cd9c512b-477b-475d-8f89-af43a817e4da', 'process': 'main', 'detail': '開始監(jiān)聽行情數(shù)據(jù)'} 啟動漲幅監(jiān)控
以下是追漲的源代碼,復制到mindgo即可
然后如果要改條件的話,比如要提前追漲,就把漲幅參數(shù)調(diào)到2.5%
可以自己任意調(diào) 如果遇到代碼跑不通的,直接留言就好了; 推送會影響你們自己跑代碼,等有新的代碼出來了,再分享給你們體驗 from datetime import date, timedelta import time import re import pandas as pd import datetime from tick_trade_api import DatafeedHqGenerator from tick_trade_api.api import TradeAPI import math
#--------------------- # 超參 # 單筆買入金額上限,單位:百元 single_buy_amount = 8888 # 單只買入次數(shù)上限 max_buy_cnt = 1
#選股最高上限 max_stock_cnt = 30
#通知用戶uid uid_list = ['輸入自己想要推送的UID']
def symbol_convert(x): if x >= '600000': return x + '.SH' else: return x + '.SZ'
#trade_api = TradeAPI(account_id='輸入資金賬號') # portfolio = trade_api.portfolio # positions = trade_api.positions
days_10_ago = (date.today() + timedelta(days=-10)).strftime('%Y-%m-%d') today = date.today().strftime('%Y-%m-%d') f_today = date.today().strftime('%Y%m%d')
date_list = get_price(['300033.SZ'],days_10_ago, today, '1d', ['close', 'open', 'low', 'high']) date_list = [i.strftime('%Y年%m月%d日') for i in date_list['300033.SZ'].index.tolist()] yestoday = date_list[-2] the_day_before_yestoday = date_list[-3]
has_buy = {} #判斷是否已經(jīng)買了
symbol_list = ['000998.SZ','002625.SZ','600030.SH','600359.SH'] stock_score = {} #選股評分 stock_price_key = {} #判斷分鐘,緩存數(shù)據(jù) buy_signal = {} #買入信號 high_signal = {} #買入信號
def stock_name_map(x): #轉(zhuǎn)代碼格式 x = symbol_convert(x[2:]) return x
# file_name = './data/stock-{f_today}.csv'.format(f_today=f_today) # stocks_from_csv = pd.read_csv(file_name,dtype=str) # stocks_from_csv['代碼'] = stocks_from_csv['代碼'].map(stock_name_map) # display(stocks_from_csv)
# for code in stocks_from_csv['代碼']: # symbol_list.append(code)
print('股票池:',symbol_list) stock_price = {} #記錄股票分時按分鐘價格
for stock_code in symbol_list: #orders = trade_api.get_orders() #獲取交易賬戶已下單訂單 has_buy[stock_code] = 0 stock_score[stock_code] = 0 stock_price[stock_code] = [] stock_price_key[stock_code] = [] buy_signal[stock_code] = 0 high_signal[stock_code] = 0
# for order in orders: # if order['symbol'] == stock_code and order['status'] != '廢單': # has_buy[stock_code] += 1
g1 = DatafeedHqGenerator(stock=symbol_list) print('啟動漲幅監(jiān)控') print('\n')
for d in g1: # print(d.trade_time.strftime('%H:%M:%S')) # print(d) symbol = d.code symbol = symbol_convert(symbol) # 在每一條行情推送計算股票漲幅 ret = d.new_price / d.pre_price - 1.0 #算漲幅 price_key = d.trade_time.strftime('%H-%M') # # 儲存數(shù)據(jù) # if price_key not in stock_price_key[symbol]: # stock_price[symbol].append(d.new_price) # stock_price_key[symbol].append(price_key) # 儲存數(shù)據(jù) if price_key not in stock_price_key[symbol]: stock_price[symbol].append(d.new_price) stock_price_key[symbol].append(price_key) else: stock_price[symbol][-1] = d.new_price # 分時股價創(chuàng)新高 & 漲幅在3.5 - 5 之間 if ret > 0.035 and ret <= 0.05 and d.new_price >= d.high_price: high_signal[symbol] = 1 # #5分鐘時間窗口異動:每5分鐘,按1分鐘時間平移,K線漲幅超過2% 研究一下功能邏輯 # if len(stock_price[symbol]) >= 5: # for i in range(5,2): # last_5 = stock_price[symbol][-5:] # max_v = max(last_5) # min_v = min(last_5) # if max_v == stock_price[symbol][-1] and (max_v-min_v)/d.pre_price > 0.02: # buy_signal[symbol] += 1 t_len = min(5,len(stock_price[symbol])) #5分鐘時間窗口異動:每5分鐘,按1分鐘時間平移,K線漲幅超過2% 研究一下功能邏輯 if t_len >= 2: last_5 = stock_price[symbol][-t_len:] max_v = max(last_5) min_v = min(last_5) if max_v >= stock_price[symbol][-1] and (max_v-min_v)/d.pre_price > 0.02: buy_signal[symbol] = 1 if buy_signal[symbol] + high_signal[symbol] >= 2: amount = math.floor( single_buy_amount / d.new_price) * 100 # 賬戶金額判斷,暫時不加 # portfolio['available_cash'] if has_buy[symbol] < max_buy_cnt: print('%s 漲幅為 %.2f%%' % (symbol, ret * 100)) print('%s 超過預警漲幅 開始買入' % (symbol)) # pricetype = 1 表示漲停價買入 # |pricetype|意義|pricetype|意義| # |---|---|---|---| # |0|指定價|1|漲停價| # |2|跌停價|3|最新價| # |4|賣一價|5|賣二價| # |6|賣三價|7|賣四價| # |8|賣五價|9|買一價| # |10|買二價|11|買三價| # |12|買四價|13|買五價| buy_amount = amount #trade_api.order(symbol=symbol, amount=buy_amount, pricetype=5) content = ('僅供參考學習,%s 切勿跟風買賣;賣出策略:隔日開盤賣出;說明:該策略只賺日內(nèi)的錢' % (symbol)) # 推送提醒 for uid in uid_list: notify_push(content=content,uids=uid) has_buy[symbol] += 1
|