stock
version: 1
disable_existing_loggers: False
formatters:
simple:
format: "%(asctime)s - %(name)s - %(levelname)s - %(threadName)s - %(lineno)d - %(message)s"
handlers:
console:
class: logging.StreamHandler
level: DEBUG
formatter: simple
stream: ext://sys.stdout
info_file_handler:
class: logging.handlers.RotatingFileHandler
level: INFO
formatter: simple
filename: info.log
maxBytes: 10485760
backupCount: 20
encoding: utf8
error_file_handler:
class: logging.handlers.RotatingFileHandler
level: ERROR
formatter: simple
filename: errors.log
maxBytes: 10485760
backupCount: 20
encoding: utf8
loggers:
my_module:
level: ERROR
handlers: [info_file_handler]
propagate: no
root:
level: INFO
handlers: [console,info_file_handler,error_file_handler]
log_config.yaml
# encoding: utf-8
import requests
import logging
import logging.config
import random
import os
import yaml
import time
import threading class Observer(object):
open_price_last_1 = ''
close_price_last_1 = ''
highest_price_last_1 = ''
minimum_price_last_1 = ''
ding_fen_xing = []
di_fen_xing = []
not_ding_di = []
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36'} def __init__(self):
self.stop_flag = False def get_stock_data(self,stock_code,scale):
"""
获取K 线数据
:param stock_code: 代码
:param scale: 级别
:return: k线数据
"""
#url = 'http://ifzq.gtimg.cn/appstock/app/kline/mkline?param=sh600030,m30,,320&_var=m30_today&r=0.1700474168906776'
url = 'http://ifzq.gtimg.cn/appstock/app/kline/mkline'
params = {
'param': '{},m{},,320'.format(stock_code,scale),
'_var': 'm{}_today'.format(scale),
'r': '0.1700474{}'.format("".join(random.choice("") for i in range(10)))
}
logging.info('url:%s \t params:%s',url,params)
res = requests.get(url,params=params,headers=self.headers)
logging.info('response:%s:',res.content.decode('unicode_escape').rstrip()) def get_stock_code(self,a_type):
"""
获取两市股票代码
:param a_type: sh or sz
:return: stock_code
"""
#url = 'http://stock.gtimg.cn/data/index.php?appn=rank&t=rankash/chr&p=1&o=0&l=40&v=list_data'
url = 'http://stock.gtimg.cn/data/index.php'
params = {
'appn': 'rank',
't': 'ranka{}/chr'.format(a_type),
'p': 1,
'o': 0,
'l': 3000,
'v': 'list_data'
}
logging.info('url:%s \t params:%s', url, params)
res = requests.get(url, params=params, headers=self.headers)
logging.info('response:%s:',res.content.decode('unicode_escape').rstrip()) def get_plate_data(self,stock_code):
"""
获取盘中数据,如果出现大于80万的买单弹框提示
:param stock_code:
:return:
"""
#url = 'http://web.sqt.gtimg.cn/q=sh601208?r=0.9884275211413494'
url = 'http://web.sqt.gtimg.cn'
params = {
'q': stock_code,
'r': '0.1700474{}'.format("".join(random.choice("") for i in range(10)))
}
logging.info('url:%s \t params:%s', url, params)
res = requests.get(url, params=params, headers=self.headers)
res_text = res.content.decode('GBK')
logging.info('response:%s:',res_text.rstrip())
plate_data = res_text.split('~')
stock_name_this = plate_data[1]
stock_code_this = plate_data[2]
for list_data in plate_data:
if '|' in list_data:
plate_date_strike = list_data.split('|')
#logging.info(plate_date_strike )
buy_list = []
for plate_date_strike_detail in plate_date_strike:
if 'B' in plate_date_strike_detail :
buy_list.append(int(plate_date_strike_detail.split('/')[4]))
logging.info(buy_list)
if buy_list and max(buy_list) > 800000:
logging.info('%s %s 出现了80万以上的买单' % (stock_name_this, stock_code_this))
self.alert_msg('%s %s 出现了80万以上的买单' % (stock_name_this, stock_code_this))
self.stop_flag = True
else:
logging.info('%s %s 没有出现80万以上的买单' % (stock_name_this, stock_code_this)) def alert_msg(self,msg):
commond = 'msg * %s'%msg
os.system(commond) class MonitorThread(threading.Thread):
def __init__(self,stock_code):
threading.Thread.__init__(self)
self.name = stock_code
self.stock_code = stock_code def run(self):
logging.info(self.name + '监控开始...')
o = Observer()
while 1:
o.get_plate_data(self.stock_code)
if o.stop_flag:
break
time.sleep(5)
logging.info(self.name + '监控结束!') if __name__ == '__main__':
path = 'logging.yaml'
value = os.getenv('LOG_CFG', None)
if value:
path = value
if os.path.exists(path):
with open(path, "r") as f:
config = yaml.load(f)
logging.config.dictConfig(config)
else:
print('log config file not found!') monitor_list = ['sz002464','sh603008']
for stock_code in monitor_list:
thread_a = MonitorThread(stock_code)
thread_a.start()
# encoding: utf-8
import requests
import logging
import logging.config
import random
import os
import yaml
import time
import threading class Observer(object):
open_price_last_1 = ''
close_price_last_1 = ''
highest_price_last_1 = ''
minimum_price_last_1 = ''
ding_fen_xing = []
di_fen_xing = []
not_ding_di = []
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36'} def __init__(self):
self.stop_flag = False def get_stock_data(self,stock_code,scale):
"""
获取K 线数据
:param stock_code: 代码
:param scale: 级别
:return: k线数据
"""
#url = 'http://ifzq.gtimg.cn/appstock/app/kline/mkline?param=sh600030,m30,,320&_var=m30_today&r=0.1700474168906776'
url = 'http://ifzq.gtimg.cn/appstock/app/kline/mkline'
params = {
'param': '{},m{},,320'.format(stock_code,scale),
'_var': 'm{}_today'.format(scale),
'r': '0.1700474{}'.format("".join(random.choice("") for i in range(10)))
}
logging.info('url:%s \t params:%s',url,params)
res = requests.get(url,params=params,headers=self.headers)
res_str = res.content.decode('unicode_escape').rstrip()
#logging.info('response:%s:',res_str)
res_dict = eval(res_str[res_str.index("={")+1:res_str.index("}}}")+3])
scale_data = res_dict['data'][stock_code]['m'+scale]
#logging.info(scale_data)
return scale_data def get_stock_code(self,a_type):
"""
获取两市股票代码
:param a_type: sh or sz
:return: stock_code
"""
#url = 'http://stock.gtimg.cn/data/index.php?appn=rank&t=rankash/chr&p=1&o=0&l=40&v=list_data'
url = 'http://stock.gtimg.cn/data/index.php'
params = {
'appn': 'rank',
't': 'ranka{}/chr'.format(a_type),
'p': 1,
'o': 0,
'l': 3000,
'v': 'list_data'
}
logging.info('url:%s \t params:%s', url, params)
res = requests.get(url, params=params, headers=self.headers)
res_str = res.content.decode('unicode_escape').rstrip()
#logging.info('response:%s:',res_str)
res_str_list = res_str[res_str.index("data:'") + 6:res_str.index("'}")].split(',')
logging.info(res_str_list)
return res_str_list def get_plate_data(self,stock_code):
"""
获取盘中数据,如果出现大于80万的买单弹框提示
:param stock_code:
:return:
"""
#url = 'http://web.sqt.gtimg.cn/q=sh601208?r=0.9884275211413494'
url = 'http://web.sqt.gtimg.cn'
params = {
'q': stock_code,
'r': '0.1700474{}'.format("".join(random.choice("") for i in range(10)))
}
logging.info('url:%s \t params:%s', url, params)
res = requests.get(url, params=params, headers=self.headers)
res_text = res.content.decode('GBK')
logging.info('response:%s:',res_text.rstrip())
plate_data = res_text.split('~')
stock_name_this = plate_data[1]
stock_code_this = plate_data[2]
for list_data in plate_data:
if '|' in list_data:
plate_date_strike = list_data.split('|')
#logging.info(plate_date_strike )
buy_list = []
for plate_date_strike_detail in plate_date_strike:
if 'B' in plate_date_strike_detail :
buy_list.append(int(plate_date_strike_detail.split('/')[4]))
logging.info(buy_list)
if buy_list and max(buy_list) > 800000:
logging.info('%s %s 出现了80万以上的买单' % (stock_name_this, stock_code_this))
self.alert_msg('%s %s 出现了80万以上的买单' % (stock_name_this, stock_code_this))
self.stop_flag = True
else:
logging.info('%s %s 没有出现80万以上的买单' % (stock_name_this, stock_code_this)) def alert_msg(self,msg):
commond = 'msg * %s'%msg
os.system(commond) class MonitorThread(threading.Thread):
def __init__(self,stock_code):
threading.Thread.__init__(self)
self.name = stock_code
self.stock_code = stock_code def run(self):
logging.info(self.name + '监控开始...')
o = Observer()
while 1:
o.get_plate_data(self.stock_code)
if o.stop_flag:
break
time.sleep(5)
logging.info(self.name + '监控结束!') if __name__ == '__main__':
path = 'logging.yaml'
value = os.getenv('LOG_CFG', None)
if value:
path = value
if os.path.exists(path):
with open(path, "r") as f:
config = yaml.load(f)
logging.config.dictConfig(config)
else:
print('log config file not found!') # monitor_list = ['sz002464','sh603008']
# for stock_code in monitor_list:
# thread_a = MonitorThread(stock_code)
# thread_a.start()
o = Observer()
code_list_sh = o.get_stock_code('sh')
code_list_sz = o.get_stock_code('sz')
code_list = code_list_sh + code_list_sz
code_list_keguanzhu = []
for stock_code in code_list:
m30_data = o.get_stock_data(stock_code, '')
#倒数第二个k线最低点是最后三根k线最低点中最低且最后一根k线收盘价高于中间一个k线的最高价
if min(float(m30_data[-1][4]), float(m30_data[-2][4]), float(m30_data[-3][4])) == float(m30_data[-2][4]) and float(m30_data[-1][2]) > float(m30_data[-2][3]):
logging.info('%s可以关注'%stock_code)
code_list_keguanzhu.append(stock_code)
logging.info('可关注的%d个票:%s'%(len(code_list_keguanzhu),str(code_list_keguanzhu)))
选股
stock的更多相关文章
- [LeetCode] Best Time to Buy and Sell Stock with Cooldown 买股票的最佳时间含冷冻期
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...
- [LeetCode] Best Time to Buy and Sell Stock IV 买卖股票的最佳时间之四
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...
- [LeetCode] Best Time to Buy and Sell Stock III 买股票的最佳时间之三
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...
- [LeetCode] Best Time to Buy and Sell Stock II 买股票的最佳时间之二
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...
- [LeetCode] Best Time to Buy and Sell Stock 买卖股票的最佳时间
Say you have an array for which the ith element is the price of a given stock on day i. If you were ...
- [LeetCode] Best Time to Buy and Sell Stock II
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...
- 4 Best Time to Buy and Sell Stock III_Leetcode
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...
- [LintCode] Best Time to Buy and Sell Stock II 买股票的最佳时间之二
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...
- [LintCode] Best Time to Buy and Sell Stock 买卖股票的最佳时间
Say you have an array for which the ith element is the price of a given stock on day i. If you were ...
- [LeetCode] Best Time to Buy and Sell Stock
Say you have an array for which the ith element is the price of a given stock on day i. If you were ...
随机推荐
- Clear Linux 为脚本语言提供更高的性能
导读 Clear Linux的领先性能不仅限于C/C++应用程序,而且PHP,R和Python等脚本语言也有很大的提升速度.在一篇新的博客文章中,英特尔的一位开发人员概述了他们对Python的一些性能 ...
- 【数学建模】day02-整数规划
基本类似于中学讲的整数规划--线性规划中变量约束为整数的情形. 目前通用的解法适合整数线性规划.不管是完全整数规划(变量全部约束为整数),还是混合整数规划(变量既有整数又有实数),MATLAB都提供了 ...
- Promise.all和Promise.race区别,和使用场景
一.Pomise.all的使用 常见使用场景 : 多个异步结果合并到一起 Promise.all可以将多个Promise实例包装成一个新的Promise实例.用于将多个Promise实例,包装成一个新 ...
- CF1106F Lunar New Year and a Recursive Sequence
题目链接:CF1106F Lunar New Year and a Recursive Sequence 大意:已知\(f_1,f_2,\cdots,f_{k-1}\)和\(b_1,b_2,\cdot ...
- MySql的CURRENT_TIMESTAMP
在创建时间字段的时候 DEFAULT CURRENT_TIMESTAMP表示当插入数据的时候,该字段默认值为当前时间 ON UPDATE CURRENT_TIMESTAMP表示每次更新这条数据的时候, ...
- 来一波全套向量运算(C++)
//头文件要求 #include <cmath> struct P{long long x, y;}p[N]; //加法 P operator +(P x, P y){return (P) ...
- 【php】php数组相关操作函数片段
下面这些都是我在工作中用到的函数,现在整理下. 判断是否是一个数组 function _is_array($value){ if (is_array($value)) { return true; } ...
- django restframework 环境配置
Requirements: coreapi (1.32.0+) - Schema generation support.Markdown (2.1.0+) - Markdown support for ...
- Composer 安装时要求输入授权用户名密码?
D:\work\dreamland-yii>composer require "saviorlv/yii2-dysms:dev-master" Authentication ...
- LinkedList(JDK1.8)源码分析
双向循环链表 双向循环链表和双向链表的不同在于,第一个节点的pre指向最后一个节点,最后一个节点的next指向第一个节点,也形成一个"环".而LinkedList就是基于双向循环链 ...