代码拉取完成,页面将自动刷新
同步操作将从 macroan/traderStock-gui 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#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()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。