1 Star 0 Fork 16

龙在江湖/traderStock-gui

forked from macroan/traderStock-gui 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
getkdj.py 2.86 KB
一键复制 编辑 原始数据 按行查看 历史
macroan 提交于 2018-11-01 09:30 . no commit message
#coding=utf-8
import urllib
import urllib2
import json
import time
import pandas as pd
import datetime as dt
from threading import Timer
class MyTimer:
def __init__(self, sec, fun):
self._tm = sec
self._fn = fun
def _do_func(self):
if self._fn:
self._fn()
self._do_start()
def _do_start(self):
self._timer = Timer(self._tm, self._do_func)
self._timer.start()
def start(self):
self._do_start()
def stop(self):
try:
self._timer.cancel()
except:
pass
def join(self):
self._timer.join()
def now():
return dt.datetime.now()
def timestamp():
now = dt.datetime.now()
ans_time = int(time.mktime(now.timetuple()))
return ans_time
def getkdj():
#url = 'https://www.aicoin.net.cn/chart/api/data/period'
#data = {'symbol': 'okexeosweekusd',
# 'step':'60'
# }
#data = urllib.urlencode(data)
#url = '%s%s%s'%(url, '?', data)
url = 'https://www.okex.com/api/v1/future_kline.do?symbol=eos_usd&contract_type=this_week&type=1min'
req = urllib2.Request(url)
req.add_header('Connection', 'keep-alive')
req.add_header('User-Agent','Mozilla/5.0 (Windows NT 6.1; WOW64; rv:53.0) Gecko/20100101 Firefox/53.0')
#req.add_header('Cookie','aliyungf_tc=AQAAAGVrPVlNYgYAum8/t+n7WKaCX3tL; s=er116hhhp2; xq_a_token=445b4b15f59fa37c8bd8133949f910e7297a52ef; xq_r_token=132b2ba19b0053bc7f04401788b6e0d24f35d365; u=361497500257379; Hm_lvt_1db88642e346389874251b5a1eded6e3=1497500257; Hm_lpvt_1db88642e346389874251b5a1eded6e3=1497500257; __utmt=1; __utma=1.222397977.1497500258.1497500258.1497500258.1; __utmb=1.1.10.1497500258; __utmc=1; __utmz=1.1497500258.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)')
#req.add_header('Host','www.aicoin.net.cn')
#req.add_header('Referer','https://www.aicoin.net.cn/chart/6CA642F7')
res = urllib2.urlopen(req)
data = res.read()
df = pd.read_json(data)
df.columns = ['Time','Open','High','Low','Last','Volume','Amount']
df['Time'] = df['Time'].apply(lambda x: dt.datetime.fromtimestamp(x/1000))
df = df[-10:]
low_list = df['Low'].rolling(window=9,center=False).min()
low_list.fillna(value=df['Low'].expanding(min_periods=1).min(), inplace=True)
high_list = df['High'].rolling(window=9,center=False).max()
high_list.fillna(value=df['High'].expanding(min_periods=1).max(), inplace=True)
rsv = (df['Last'] - low_list) / (high_list - low_list) * 100
df['kdj_k'] = rsv.ewm(ignore_na=False,min_periods=0,adjust=True,com=2).mean()
df['kdj_d'] = df['kdj_k'].ewm(ignore_na=False,min_periods=0,adjust=True,com=2).mean()
df['kdj_j'] = 3 * df['kdj_k'] - 2 * df['kdj_d']
print(df)
if __name__=="__main__":
#timer = MyTimer(1, getkdj)
getkdj()
#timer.start()
#timer.join()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/yizhengsh/traderStock-gui.git
git@gitee.com:yizhengsh/traderStock-gui.git
yizhengsh
traderStock-gui
traderStock-gui
master

搜索帮助