get quote price from FT
This commit is contained in:
@@ -153,9 +153,9 @@ def getCurrencyRate(currency):
|
||||
rate = divs[1].span.text
|
||||
return float(rate.replace(',','.'))
|
||||
|
||||
def getYahooQuote(ticker):
|
||||
# specify the url
|
||||
quote_page = 'https://finance.yahoo.com/quote/%s/history/' % ticker
|
||||
def getFTQuote(ticker):
|
||||
# specify the url of The Financial Times
|
||||
quote_page = 'https://markets.ft.com/data/funds/tearsheet/historical?s=%s' % ticker
|
||||
|
||||
# query & parse the html using beautiful soap and store in variable `soup`
|
||||
soup = BeautifulSoup(urllib2.urlopen(quote_page), 'html.parser')
|
||||
@@ -164,11 +164,10 @@ def getYahooQuote(ticker):
|
||||
rows = soup.findAll('table')[0].tbody.findAll('tr')
|
||||
for each_row in rows:
|
||||
divs = each_row.findAll('td')
|
||||
if divs[1].span.text != 'Dividend': #Ignore this row in the table
|
||||
#I'm only interested in 'Close' price;
|
||||
data.append({'Date': divs[0].span.text, 'Close': float(divs[5].span.text.replace(',',''))})
|
||||
quote_price = float(divs[4].text.replace(',',''))
|
||||
break
|
||||
|
||||
# retourne la prière ligne
|
||||
return data[0]
|
||||
return quote_price
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-xs-2 control-label">Symbole Yahoo</label>
|
||||
<label class="col-xs-2 control-label">Symbole FT</label>
|
||||
<div class="col-xs-4">
|
||||
<input class="form-control" type="text" name="symbole"
|
||||
value="${actif.symbole}" placeholder="15 caractères maximum"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<metal:block use-macro="main_template">
|
||||
<div metal:fill-slot="content">
|
||||
|
||||
<div tal:condition="message" tal:content="message" class="alert alert-danger" />
|
||||
<div tal:condition="message" tal:content="message" class="alert alert-success" />
|
||||
|
||||
<p>
|
||||
<a href="allocation_edit/0" class="btn btn-success" role="button">
|
||||
|
||||
@@ -69,13 +69,13 @@ def actif_edit(request):
|
||||
new_values[param] = request.params[param]
|
||||
|
||||
if new_values:
|
||||
# récupérer les infos du symbole de Yahoo finance
|
||||
# récupérer les infos du symbole de FT finance
|
||||
if 'symbole' in request.params:
|
||||
symbole = request.params['symbole']
|
||||
else:
|
||||
symbole = actif.symbole
|
||||
|
||||
quote_price = getYahooQuote(symbole)
|
||||
quote_price = getFTQuote(symbole)
|
||||
if quote_price:
|
||||
new_values['cours'] = quote_price['Close']
|
||||
|
||||
@@ -247,8 +247,7 @@ def histo_edit(request):
|
||||
|
||||
if new_values:
|
||||
# lire le cours de l'indice de réfence : Carmignac Investissement A EUR Acc
|
||||
sym = Share('FR0010148981.PA')
|
||||
new_values['cours_ref'] = sym.get_price()
|
||||
new_values['cours_ref'] = getFTQuote('FR0010148981:EUR')
|
||||
|
||||
update_histo(request, no_id, new_values)
|
||||
request.session.flash(u"La fiche a été mise à jour avec succès.", 'success')
|
||||
|
||||
@@ -110,8 +110,8 @@ def home(request):
|
||||
|
||||
for item in actifs:
|
||||
if item.type == 'ACTION':
|
||||
# get yahoo price
|
||||
quote_price = getYahooQuote(item.symbole)
|
||||
# get FT price
|
||||
quote_price = getFTQuote(item.symbole)
|
||||
if quote_price:
|
||||
update_actif_valeur(request, item.symbole, quote_price['Close'])
|
||||
time.sleep(2) # attendre 2 secondes
|
||||
|
||||
Reference in New Issue
Block a user