-
Notifications
You must be signed in to change notification settings - Fork 0
/
FetchData
47 lines (37 loc) · 1.32 KB
/
FetchData
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import requests
import pandas as pd
class StockBasic:
def FetchStockCode(self):
url = "http://114.215.202.25:8082/stockCode?ex=sh,sz"
stockpd = pd.read_csv(url, dtype={'code': object})
stockCode = stockpd.code.values.tolist()
return stockCode
class StockMarket:
def FetchStockBar(self, code, startdate, enddate):
startds = "&start=" + startdate
if enddate:
endds = "&end=" + enddate
else:
endds = "&end=" + startdate
baseurl = "http://114.215.202.25:8082/stockBar?m=1440" + startds + endds
if code.startswith("6"):
baseurl = baseurl + "&ex=sh" + "&code=" + code
else:
baseurl = baseurl + "&ex=sz" + "&code=" + code
# print(baseurl)
stockvalue = pd.read_csv(baseurl)
return stockvalue
def FetchAllStockBar(self, startdate, enddate):
stockbase = StockBasic()
stockcode = stockbase.FetchStockCode()
stockvalue = pd.DataFrame()
for item in stockcode:
stockm = StockMarket()
stockv = stockm.FetchStockBar(item, "20160215", "")
stockvalue = stockvalue.append(stockv)
# print(stockv)
# print(item)
return stockvalue
ss = StockMarket()
# print(ss.FetchAllStockBar("20160215",""))
#print stockv