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的更多相关文章

  1. [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 ...

  2. [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 ...

  3. [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 ...

  4. [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 ...

  5. [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 ...

  6. [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 ...

  7. 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 ...

  8. [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 ...

  9. [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 ...

  10. [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 ...

随机推荐

  1. poj-3080(kmp+暴力枚举)

    题意:给你多个字符串,问你这几个字符串的最长公共子串是哪个,如果有多个,输出字典序最大的那个,如果最长的公共子串长度小于3,输出一个奇怪的东西: 解题思路:首先看数据,数据不大,开始简单快乐的暴力之路 ...

  2. hdu-1176(dp)

    解题思路:用dp做的,dp[i][j]表示在i时刻,j点的最大馅饼.a[i][j]表示在i这个时刻j点同时掉落的馅饼: 每个点除了0和10之外,都有三种状态: 1.没有移动,这样值就为dp[i][j] ...

  3. [西安交大附中集训] d6 删边(cip)

    B. 删边(cip.cpp/in/out 1S/256M) 题面 给出一个没有重边和自环的无向图,现在要求删除其中两条边,使得图仍然保持连通. 你的任务是计算有多少组不合法的选边方案.注意方案是无序二 ...

  4. JarvisOJ Misc 炫酷的战队logo

    欣赏过了实验室logo,有人觉得我们战队logo直接盗图比较丑,于是我就重新设计了一个,大家再欣赏下? 一开始拿到的BMP文件就打不开,用010打开发现文件头被抹去了,补上了BMP,与文件大小后,发现 ...

  5. 英特尔DRM内核驱动程序默认启用PSR2省电功能

    导读 英特尔DRM/KMS内核驱动程序很快就会启用PSR2面板自刷新功能,以便在英特尔支持的超极本/笔记本电脑上实现更多节能. 一段时间以来,英特尔的Direct Rendering Manager驱 ...

  6. Vmware 给虚拟机传脚本并执行

    #_*_ coding:utf8 _*_ from pysphere import VIServer import ssl import re import sys import os import ...

  7. BZOJ4372烁烁的游戏——动态点分治+线段树(点分树套线段树)

    题目描述 背景:烁烁很喜欢爬树,这吓坏了树上的皮皮鼠.题意:给定一颗n个节点的树,边权均为1,初始树上没有皮皮鼠.烁烁他每次会跳到一个节点u,把周围与他距离不超过d的节点各吸引出w只皮皮鼠.皮皮鼠会被 ...

  8. P1495 曹冲养猪

    原题链接 https://www.luogu.org/problemnew/show/P1495 这个题明显的中国剩余定理(孙子定理),如果有不懂孙子定理的点这个链接https://baike.bai ...

  9. NEXUS 上传到私仓的SNAPSHOT 包下载不下来

    使用NEXUS 上传 SNAPSHOT版本的jar包到服务器上,但是下载不下来,报错提示:Dependency ... not found 后来百度到一句话: Maven内置的插件远程仓库配置,关闭了 ...

  10. jqGrid 中文配置 - grid.locale-cn.js 多国语言

    中文配置如下:多国语言(demo 内有官方下载连接 ): jqGrid 表格插件中文 grid.locale-cn.js 代码如下: ;(function ($) { /** * jqGrid Eng ...