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