Skip to content

Commit

Permalink
code update.
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmysoa committed Jul 29, 2018
1 parent c6010ae commit 9b46dcd
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 389 deletions.
3 changes: 1 addition & 2 deletions tushare/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,4 @@
from tushare.coins.market import (coins_tick, coins_bar,
coins_snapshot, coins_trade)

from tushare.util.conns import (get_apis, close_apis)

from tushare.util.conns import (get_apis, close_apis)
17 changes: 6 additions & 11 deletions tushare/futures/domestic.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,12 @@ def get_cffex_daily(date = None):
row_dict = {'date': day_const, 'symbol': row[0], 'variety': m.group(1)}

for i,field in enumerate(ct.CFFEX_COLUMNS):
## some data was missing in the csv files. e.g. 2018-01-19
## using error handle to avoid crushing
try:
if row[i+1] == u"":
row_dict[field] = 0.0
elif field in ['volume', 'open_interest', 'oi_chg']:
row_dict[field] = int(row[i+1])
else:
row_dict[field] = float(row[i+1])
except Exception:
row_dict[field] = None
if row[i+1] == u"":
row_dict[field] = 0.0
elif field in ['volume', 'open_interest', 'oi_chg']:
row_dict[field] = int(row[i+1])
else:
row_dict[field] = float(row[i+1])
row_dict['pre_settle'] = row_dict['close'] - row_dict['change1']
dict_data.append(row_dict)

Expand Down
3 changes: 2 additions & 1 deletion tushare/stock/classifying.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ def _get_detail(tag, retry_count=3, pause=0.001):
jstr = json.dumps(text)
js = json.loads(jstr)
df = pd.DataFrame(pd.read_json(js, dtype={'code':object}), columns=ct.THE_FIELDS)
df = df[ct.FOR_CLASSIFY_B_COLS]
# df = df[ct.FOR_CLASSIFY_B_COLS]
df = df[['code', 'name']]
dfc = pd.concat([dfc, df])
if df.shape[0] < num_limit:
return dfc
Expand Down
12 changes: 5 additions & 7 deletions tushare/stock/cons.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
'oss': 'file.tushare.org', 'idxip':'115.29.204.48',
'shibor': 'www.shibor.org', 'mbox':'www.cbooo.cn',
'tt': 'gtimg.cn', 'gw': 'gw.com.cn',
'dfcf': 'nufm.dfcfw.com',
'v500': 'value500.com', 'sstar': 'stock.stockstar.com'}
'v500': 'value500.com', 'sstar': 'stock.stockstar.com',
'dfcf': 'nufm.dfcfw.com'}
PAGES = {'fd': 'index.phtml', 'dl': 'downxls.php', 'jv': 'json_v2.php',
'cpt': 'newFLJK.php', 'ids': 'newSinaHy.php', 'lnews':'rollnews_ch_out_interface.php',
'ntinfo':'vCB_BulletinGather.php', 'hs300b':'000300cons.xls',
Expand All @@ -42,7 +42,6 @@
't_ticks':'vMS_tradedetail.php', 'dw': 'downLoad.html',
'qmd':'queryMargin.do', 'szsefc':'ShowReport.szse',
'ssecq':'commonQuery.do', 'sinadd':'cn_bill_download.php', 'ids_sw':'SwHy.php',
'ssecq':'commonQuery.do', 'sinadd':'json_v2.php', 'ids_sw':'SwHy.php',
'idx': 'index.php', 'index': 'index.html'}
TICK_COLUMNS = ['time', 'price', 'change', 'volume', 'amount', 'type']
TODAY_TICK_COLUMNS = ['time', 'price', 'pchange', 'change', 'volume', 'amount', 'type']
Expand Down Expand Up @@ -123,11 +122,10 @@
GPZY_D_URL = '%s%s/tsdata/gpzy/%s.csv'
SHS_FAC_URL = '%s%s/tsdata/shares/%s.csv'
ZF = '%s%s/tsdata/%s.csv'
SHS_FAC_URL = '%s%s/tsdata/shares/%s.csv'
INDEX_HQ_URL = '''%shq.%s/rn=xppzh&list=sh000001,sh000002,sh000003,sh000008,sh000009,sh000010,sh000011,sh000012,sh000016,sh000017,sh000300,sh000905,sz399001,sz399002,sz399003,sz399004,sz399005,sz399006,sz399008,sz399100,sz399101,sz399106,sz399107,sz399108,sz399333,sz399606'''
SSEQ_CQ_REF_URL = '%s%s/assortment/stock/list/name'
ALL_STK_URL = '%s%s/all.csv'
SINA_DD = '%s%s/quotes_service/api/%s/CN_Bill.GetBillList?symbol=%s&num=60&page=1&sort=ticktime&asc=0&volume=%s&amount=0&type=0&day=%s'
SINA_DD = '%s%s/quotes_service/view/%s?symbol=%s&num=60&page=1&sort=ticktime&asc=0&volume=%s&amount=0&type=0&day=%s'
BOX = 'boxOffice'
MOVIE_BOX = '%s%s/%s/GetHourBoxOffice?d=%s'
BOXOFFICE_DAY = '%s%s/%s/GetDayBoxOffice?num=%s&d=%s'
Expand Down Expand Up @@ -171,7 +169,7 @@
INDEX_HEADER = 'code,name,open,preclose,close,high,low,0,0,volume,amount,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,d,c,3\n'
INDEX_COLS = ['code', 'name', 'change', 'open', 'preclose', 'close', 'high', 'low', 'volume', 'amount']
HIST_FQ_COLS = ['date', 'open', 'high', 'close', 'low', 'volume', 'amount', 'factor']
SINA_DD_COLS = ['symbol', 'name', 'time', 'price', 'volume', 'prev_price', 'kind']
SINA_DD_COLS = ['code', 'name', 'time', 'price', 'volume', 'preprice', 'type']
GLOBAL_HQ_SYMBOL = 'sh000001,hkHSI,znb_UKX,znb_DAX,znb_INDEXCF,znb_CAC,znb_SMI,znb_FTSEMIB,znb_MADX,znb_OMX,znb_SPX,znb_HEX,znb_OSEAX,znb_ISEQ,znb_AEX,znb_ICEXI,znb_NKY,znb_TWSE,znb_FSSTI,znb_KOSPI,znb_FBMKLCI,znb_SET,znb_JCI,znb_PCOMP,znb_KSE100,znb_SENSEX,znb_VNINDEX,znb_CSEALL,znb_SASEIDX,znb_SPTSX,znb_MEXBOL,znb_IBOV,znb_MERVAL,znb_AS51,znb_NZSE50FG,znb_CASE,znb_JALSH,sz399001,znb_INDU,znb_CCMP'
GLOBAL_HQ_COLS = ['symbol', 'name', 'price', 'chga', 'chgp', 'datetime']
INST_PLK_F = 'ts_instrument.plk'
Expand Down Expand Up @@ -449,4 +447,4 @@ def _get_xxserver():
import random
ips = XXLIST
random.shuffle(ips)
return ips[0]
return ips[0]
4 changes: 4 additions & 0 deletions tushare/stock/reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -1081,8 +1081,12 @@ def stock_issuance(start_date='', end_date=''):
df['prem'] = df['prem'].astype(float)
return df


def _random(n=13):
from random import randint
start = 10**(n-1)
end = (10**n)-1
return str(randint(start, end))



Loading

0 comments on commit 9b46dcd

Please sign in to comment.