Exemple #1
0
def main():
    client = Client()
    client.init('ed109e5b2acd1026f1ed8f9f9f4569ce8e32ba02c253b8d42606d74b46909814')
    print 'init ok'
    url = '/api/subject/getNewsByTickers.json?field=&secID=&exchangeCD=&ticker=600000&secShortName=&beginDate=20150301&endDate=20150305'
    code, result = client.getData(url)
    print code
    print result
Exemple #2
0
def dataYes():
    try:
        client = Client()
        client.init(
            '4b35b6b552ea66ef08186d267e693c86ed4726227979720aac8fb2d42a1c242a')
        url1 = '/api/market/getMktEqud.json?field=&beginDate=20170801&endDate=&secID=&ticker=000001&tradeDate='
        code, result = client.getData(url1)
        if code == 200:
            print(result)
            file_object = open('thefile.csv', 'w')
            file_object.write(result)
            file_object.close()
        else:
            print(code)
            print(result)
    except Exception as e:
        traceback.print_exc()
        raise e
Exemple #3
0
# -*- coding: utf-8 -*-
from dataapi import Client

if __name__ == "__main__":
    try:
        client = Client()
        client.init('e12468740a562e3ea838f0ea6bfd2a6ef3de7ae58453b8ce8fecd32c911e76b1')
        url1 = '/api/market/getMktEqud.json?field=,&beginDate=20161010&endDate=20161014&secID=&ticker=300431&tradeDate=20161013'
        code, result = client.getData(url1)
        if code == 200:
            print result
        else:
            print code
            print result
    except Exception, e:
        # traceback.print_exc()
        raise e
Exemple #4
0
@author: Administrator
"""
"""从通联因子数据(专业版)中提取移动平均线数据。
"""
from WindPy import w
w.start()

tradeDate = '20161010'
x = w.wset("sectorconstituent",
           "date=" + tradeDate + ";sectorid=a001010f00000000")

##判断股票池是否
from dataapi import Client
import pandas as pd
client = Client()
client.init('e97fd48ed3ada633e20848c501fa018db3a52734767bfedc20ce0f1ac3aea723')

url = '/api/equity/getEqu.json?field=&ticker=&secID=&equTypeCD=A&listStatusCD=L'
code, result = client.getData(url)
stocklist = result['ticker'].tolist()

import time
t1 = time.time()
wrong_list = []
temp = pd.DataFrame()
for ticker in stocklist:
    print(ticker)
    try:
        #        url = '/api/market/getMktStockFactorsDateRangePro.json?field=ticker,tradeDate,pe&secID=&ticker='+ticker+'&beginDate=20020101&endDate=20160831'
        #        url = '/api/market/getMktStockFactorsOneDayPro.json?field=ticker,tradeDate&secID=&ticker='+ticker+'&beginDate=20070101&endDate=20160831'
Exemple #5
0
# -*- coding: utf-8 -*-
from dataapi import Client
from datetime import date
from datetime import timedelta
import json
import csv
import code

if __name__ == "__main__":
    try:
        client = Client()
        
        ticker = '601988' # ZGYH
        lookBack = 60
        today = date.today()
        endDate = today.strftime('%Y%m%d')
        beginDate = (today - timedelta(days=lookBack)).strftime('%Y%m%d')
        exchangeCD = "XSHG"
        
        code, mktResult = client.getMarketDataByTicker(ticker, beginDate, endDate)
        if code==200:
            mktResult = unicode(mktResult, errors='ignore')
            decodedRes = json.loads(mktResult)
            
            mktFile = csv.writer(open("601988_mkt.csv", "wb+"))

            mktFile.writerow(decodedRes['data'][0].keys())
            for row in decodedRes['data']:
                mktFile.writerow(row.values())
        else:
            print code
Exemple #6
0
# -*- coding: utf-8 -*-
from dataapi import Client
if __name__ == "__main__":
    try:
        client = Client()
        client.init('26a0fa114b621a5b9755507e17b04600f01da7b41b7dc950e19b357fbd721123')
#         url1='/api/macro/getChinaDataGDP.csv?field=&indicID=M010000002&indicName=&beginDate=&endDate='
#         code, result = client.getData(url1)
#         if code==200:
#             print result
#         else:
#             print code
#             print result
        url2='/api/subject/getSocialDataXQByDate.csv?field=&statisticsDate=20150630'
        code, result = client.getData(url2)
        if(code==200):
            print result
        else:
            print code
            print result

    except Exception, e:
        #traceback.print_exc()
        raise e
Exemple #7
0
# -*- coding: utf-8 -*-
from dataapi import Client
if __name__ == "__main__":
    try:
        client = Client()
        client.init(
            'c5a5065318ff2e67a18ae6da29d6e10b22f2b7dc8d65d00e626fbb7de99feed0')
        url1 = '/api/macro/getChinaDataGDP.csv?field=&indicID=M010000002&indicName=&beginDate=&endDate='
        code, result = client.getData(url1)
        if code == 200:
            print(result)
        else:
            print(code)
            print(result)
        url2 = '/api/subject/getThemesContent.csv?field=&themeID=&themeName=&isMain=1&themeSource='
        code, result = client.getData(url2)
        if (code == 200):
            file_object = open('thefile.csv', 'w')
            file_object.write(result.decode())
            file_object.close()
        else:
            print(code)
            print(result)
    except Exception as e:
        #traceback.print_exc()
        raise e
def refresh(client, pause_sec):
    time.sleep(pause_sec)
    print 'sleeping'
    client = Client()
    client.init(token)
def writelogfile(stockuniv, errorstock, market):
    writer = csv.writer(open( data_dir + univ_file + market + '.csv', 'wb'))
    for item in stockuniv:
        writer.writerow([item])
    writer = csv.writer(open( data_dir + err_file + market + '.csv', 'wb'))
    for item in errorstock:
        writer.writerow([item])
    del writer

#%% Main Routine
if __name__ == "__main__":
    start = time.clock()
    for factor in factor_set:
        url_prefix = url_prefix + ',' + factor
    """ Initialize Client """
    client = Client()
    client.init(token)
    
    i = 1 # counter for stocks
    for market in markets:
        checkMarket(market) 
        stockuniv = [] #  list of stocks that can be successfully downloaded
        errorstock = [] # list of stocks that can't be downloaded
        stocklist = csv.reader(file(data_dir + ticker_file_prefix + market + '.csv', 'rb'))
        for stock in stocklist:
            if i%pause_count == 0:
                refresh(client, puase_sec)
            name = stock[0].split('.')[0]            
            url = url_prefix + '&secID=&ticker=' + name \
                  + '&beginDate=' + begin_date + '&endDate=' + end_date
            try:
Exemple #10
0
# -*- coding: utf-8 -*-
from dataapi import Client
if __name__ == "__main__":
    try:
        client = Client()
        client.init(
            "a9bd16e6728445fcc3168ef5729284aa5c27123a64b2fd2fec047ead1e7b7749")
        url1 = "/api/equity/getEqu.csv?field=&listStatusCD=&secID=&ticker=&equTypeCD=A"
        code, result = client.getData(url1)
        if (code == 200):
            print(str(result))
            file_object = open('thefile.csv', 'w')
            #file_object.write(str(result))
            file_object.close()
        else:
            print(code)
            print(result)
    except Exception as e:
        #traceback.print_exc()
        print(e)
Exemple #11
0
# -*- coding: utf-8 -*-
from dataapi import Client
if __name__ == "__main__":
    try:
        client = Client()
        client.init('db087ed39012466cf5a797e6a150aaaf788a103423a9ec2b172cc0e55768aed2')
        url1='/api/macro/getChinaDataGDP.csv?field=&indicID=M010000002&indicName=&beginDate=&endDate='
        code, result = client.getData(url1)
        if code==200:
            print result
        else:
            print code
            print result
        url2='/api/subject/getThemesContent.csv?field=&themeID=&themeName=&isMain=1&themeSource='
        code, result = client.getData(url2)
        if(code==200):
            file_object = open('thefile.csv', 'w')
            file_object.write(result)
            file_object.close( )
        else:
            print code
            print result
    except Exception, e:
        #traceback.print_exc()
        raise e
Exemple #12
0
# -*- coding: utf-8 -*-
from dataapi import Client
if __name__ == "__main__":
    try:
        client = Client()
        client.init('77ac42d684c5dedeca8aa6b62a1a8714f7aeaf6def3198d3a8307f8665c9f694')
        url1='/api/market/getMktIdxd.json?field=&beginDate=20160101&endDate=20160505&indexID=&ticker=399006&tradeDate='
        code, re = client.getData(url1)
        if code==200:
            print (re)
        else:
            print (code)
            print (re)
        url2='/api/market/getMktEqud.json?field=&beginDate=20160101&endDate=20160505&secID=&ticker=000762&tradeDate='
        code, result = client.getData(url2)
        if(code==200):
            file_object = open('thefile.csv', 'w')
            file_object.write(str(result))
            file_object.close( )
        else:
            print (code)
            print (result)
    except Exception as e:
        #traceback.print_exc()
        raise e
import pandas
import tushare as ts
ts.set_token('77ac42d684c5dedeca8aa6b62a1a8714f7aeaf6def3198d3a8307f8665c9f694')
st=ts.Market()
df = st.MktEqud(tradeDate='20160505', field='ticker,secShortName,preClosePrice,openPrice,highestPrice,lowestPrice,closePrice,turnoverVol,turnoverRate')
df1=st.MktEqud(ticker='600836',beginDate='20160101',endDate='20160507',field='ticker,secShortName,preClosePrice,openPrice,highestPrice,lowestPrice,closePrice,turnoverVol,turnoverVole,turnoverRate,negMarketValue,PE,PE1,PB')
Exemple #13
0
# -*- coding: utf-8 -*-
from dataapi import Client
from pandas import Series, DataFrame
import pandas as pd
import json
import datetime
client = Client()
client.init('a906948b06ab5c139d859606c08abb5a3fb3fd22d95369cbc345c809c9657b8d')
def get_foundlist():  #基金列表
    url = '/api/master/getSecID.json?field=&assetClass=F&ticker=&partyID=&cnSpell='
    code,result = client.getData(url)
    if code==200:
        jsonfile = json.loads(result.decode('gbk'))
        data = jsonfile['data']
        frame = DataFrame(data)
        return frame['ticker'].values

    else:
        print(code)
        print(result)
def getFundNav(datelist):
    for date in datelist:
        url = '/api/fund/getFundNav.json?field=&beginDate=&endDate=&secID=&ticker=&dataDate=%s' % date
        code,result = client.getData(url)
        if code==200:
            f=open('temp.json','w')
            f.write(result.decode('gbk'))
            f.close()
            jsonfile = json.loads(result.decode('gbk'))
            data = jsonfile['data']
            frame = DataFrame(data)
Exemple #14
0
# -*- coding: utf-8 -*-
#通联数据获取巨灵财经研报
from dataapi import Client
import pandas as pd
import os

df = pd.read_csv('stock_base.csv')
df['code'] = df['code'].map(lambda x: str(x).zfill(6))
for intcode in df['code']:
    if __name__ == "__main__":
        try:
            stcode = str(intcode)
            client = Client()
            client.init('xx')  #通联数据凭证
            #url1='/api/RRP/getReportJL.csv?field=&orgName=&BeginWriteDate=20161001&EndwriteDate=20170205&secID=&ticker='+stcode+'&title=&author='
            #code, result = client.getData(url1)
            #if code==200:
            #print result
            #else:
            #print code
            #print result
            if os.path.isfile('jlcjreport\\' + stcode + '.csv') == False:
                url2 = '/api/RRP/getReportJL.csv?field=&orgName=&BeginWriteDate=20161001&EndwriteDate=20170205&secID=&ticker=' + stcode + '&title=&author='
                code, result = client.getData(url2)
                if (code == 200 and result != '-1:No Data Returned'):
                    file_object = open('jlcjreport\\' + stcode + '.csv', 'w')
                    file_object.write(result)
                    file_object.close()
                else:
                    print code
                    print result