Example #1
0
def saveTradeData(stock):
	c = config()
	s = Stock()
	#获取股票对应的ID
	id = stock['id']
	stockName = stock['stockName']
	ticker = stock['ticker']
	#获取该股票的历史数据
	tradeData = s.getNewData(ticker)
	#判断该股票是否有当天的信息
	if tradeData['retCode'] != -1:
		t = tradeData["data"][0]
		print t
		url2 = c['url']+'/api/trades'
		turnoverVol= t['turnoverVol']
		turnoverRate = t['turnoverRate']
		turnoverValue = t['turnoverValue']
		tradeDate = t['tradeDate'].replace('-','')
		preClosePrice = t['preClosePrice']
		PE = t['PE']
		PB =t['PB']
		openPrice = t['openPrice']
		negMarketValue = t['negMarketValue']
		marketValue = t['marketValue']
		lowestPrice = t['lowestPrice']
		highestPrice = t['highestPrice']
		closePrice = t['closePrice']
		actPreClosePrice = t['actPreClosePrice']
		data = {'ticker':ticker,'StockId':id,'stockName':stockName,'turnoverVol':turnoverVol,'turnoverValue':turnoverValue,'turnoverRate':turnoverRate,'tradeDate':tradeDate,'preClosePrice':preClosePrice,'PE':PE,'PB':PB,'openPrice':openPrice,
		'negMarketValue':negMarketValue,'marketValue':marketValue,'lowestPrice':lowestPrice,'highestPrice':highestPrice,'closePrice':closePrice,'actPreClosePrice':actPreClosePrice}
		print data
		r = requests.post(url2,data = data)
		print r.text.encode('utf8')
	else:
		print "股票信息还未获取"
Example #2
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#获取每日最新的数据

import requests
from stockapi import Stock

stock = Stock()
a = stock.getNewStock()
i = 0
print 'begin'
if a['retCode'] == -1:
	print 'I can not get stock data'
else:
	while i<len(a['data']):
		r = requests.post('http://localhost:8080/api/stocks',data = a['data'][i])
		i = i+1
		print 'the %d stock is %s'%(i,r.text)
print 'down'
Example #3
0
# -*- coding: UTF-8 -*-
from stockapi import Stock
import requests
import json

#将股票的数据保存到数据库中
def save(stocklist):
	for stock in stocklist:
		c = config()
		ticker = stock['ticker']
		secShortName = stock['secShortName']
		data ={"ticker":ticker,"stockName":secShortName}
		url =c["url"]+"/api/stocks"
		r = requests.post(url,data=data)
		print r.text.encode('utf8')


#读取配置信息
def config():
	f = file("../config.json")
	s = json.load(f)
	return s['analyse']

if __name__ == '__main__':
	s = Stock()
	stocklist = s.getStockInfo()["data"]
	save(stocklist)