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': '開(kāi)始監(jiān)聽(tīng)行情數(shù)據(jù)'} 啟動(dòng)漲幅監(jiān)控
以下是追漲的源代碼,復(fù)制到mindgo即可
然后如果要改條件的話,比如要提前追漲,就把漲幅參數(shù)調(diào)到2.5%
可以自己任意調(diào) 如果遇到代碼跑不通的,直接留言就好了; 推送會(huì)影響你們自己跑代碼,等有新的代碼出來(lái)了,再分享給你們體驗(yàn) 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
#--------------------- # 超參 # 單筆買(mǎi)入金額上限,單位:百元 single_buy_amount = 8888 # 單只買(mǎi)入次數(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='輸入資金賬號(hào)') # 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)買(mǎi)了
symbol_list = ['000998.SZ','002625.SZ','600030.SH','600359.SH'] stock_score = {} #選股評(píng)分 stock_price_key = {} #判斷分鐘,緩存數(shù)據(jù) buy_signal = {} #買(mǎi)入信號(hào) high_signal = {} #買(mǎi)入信號(hào)
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 = {} #記錄股票分時(shí)按分鐘價(jià)格
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('啟動(dòng)漲幅監(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) # 在每一條行情推送計(jì)算股票漲幅 ret = d.new_price / d.pre_price - 1.0 #算漲幅 price_key = d.trade_time.strftime('%H-%M') # # 儲(chǔ)存數(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) # 儲(chǔ)存數(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 # 分時(shí)股價(jià)創(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分鐘時(shí)間窗口異動(dòng):每5分鐘,按1分鐘時(shí)間平移,K線漲幅超過(guò)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分鐘時(shí)間窗口異動(dòng):每5分鐘,按1分鐘時(shí)間平移,K線漲幅超過(guò)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 # 賬戶金額判斷,暫時(shí)不加 # portfolio['available_cash'] if has_buy[symbol] < max_buy_cnt: print('%s 漲幅為 %.2f%%' % (symbol, ret * 100)) print('%s 超過(guò)預(yù)警漲幅 開(kāi)始買(mǎi)入' % (symbol)) # pricetype = 1 表示漲停價(jià)買(mǎi)入 # |pricetype|意義|pricetype|意義| # |---|---|---|---| # |0|指定價(jià)|1|漲停價(jià)| # |2|跌停價(jià)|3|最新價(jià)| # |4|賣(mài)一價(jià)|5|賣(mài)二價(jià)| # |6|賣(mài)三價(jià)|7|賣(mài)四價(jià)| # |8|賣(mài)五價(jià)|9|買(mǎi)一價(jià)| # |10|買(mǎi)二價(jià)|11|買(mǎi)三價(jià)| # |12|買(mǎi)四價(jià)|13|買(mǎi)五價(jià)| buy_amount = amount #trade_api.order(symbol=symbol, amount=buy_amount, pricetype=5) content = ('僅供參考學(xué)習(xí),%s 切勿跟風(fēng)買(mǎi)賣(mài);賣(mài)出策略:隔日開(kāi)盤(pán)賣(mài)出;說(shuō)明:該策略只賺日內(nèi)的錢(qián)' % (symbol)) # 推送提醒 for uid in uid_list: notify_push(content=content,uids=uid) has_buy[symbol] += 1
|