I am interested in possible methods of automatically converting the prices given when a web page is loaded from the currency given to a specified currency. Ideally, the conversion would also make use of the current exchange rate to give valid prices.
For example, in my specific case, I would like to convert the prices given in Euros (€) on this web site to Sterling (£).
I am looking at using a GreaseMonkey script for this conversion, but can anyone suggest other methods?
Thanks, MagicAndi.
Try the API: http://thecurrencygraph.com
It uses Geo Location scripts to detect the user's country and through that their native currency. It then converts your prices into their currency using the latest exchange rates
Hope this this helps!
W.
Since I dabble in AutoHotkey here's a potential solution using that scripting language, it retrieves the page source from a webpage that does the conversion and parses out the converted value. This requires the httpQuery library to be included:
#Include httpQuery.ahk
InputBox, n, EUR to GBP, Enter the number., , 150, 120
if (ErrorLevel || !n)
return
url := "http://www.xe.com/ucc/convert.cgi?Amount=" n "&From=EUR&To=GBP&image.x=55&image.y=8"
html := URLDownloadToVar(url)
Gui, Add, Edit, w125, % RegExMatch(html,"[\d\.]+(?= GBP)",m) ? m "£" : "The value could not be retrieved."
Gui, Show, AutoSize Center, GBP
VarSetCapacity(html,0)
Return
GuiClose:
GuiEscape:
Gui, Destroy
return
URLDownloadToVar(url){
if !RegExMatch(url,"^http://")
url := "http://" url
httpQuery(html,url)
VarSetCapacity(html, -1)
Return html
}
There are obviously more thorough (and complex) methods for solving this problem but this at least solves it with minimal effort.
The quick and easy answer is to make use of a Firefox add-on. There are a number of currency converters available as add-ons, but I ended up using Exch, as it suited my needs best.
Related
I've used https://github.com/691175002/BLPInterface as a wrapper to the terribly-documented (and non-supported by Bloomberg Help) Bloomberg python API. I use it to pull price histories, etc.
Lately I've needed to pull specific FX date values. In excel I do that as =#BFxForward("usdjpy",J10, "BidOutright") where J10 is a date.
I would like to pull this information via the Bloomberg Python API (or even better, with the BLPInterace wrapper) but it's not clear how to do it. I've seen someone ask a similar question for a .Net implementation, but the only answer cited page 207 of a developers guide. Every developer guide I can find on bloomberg is well less than 200 pages, and none of it mentions pulling fx values.
Wondering if anyone can point me at some examples or resources to build on to get this ?
It does take some finding, to be sure, but I tracked it down via the Bloomi Terminal. The way I found the information is as follows (for future reference):
Type DAPI in the Bloomberg Terminal
Choose 'Additional Resources' in the left hand panel
Choose 'Help Page for DAPI' in the right hand panel, and a window pops up
Choose 'Constructing Formulas' in the left hand panel
Choose 'FX Broken Dates Forwards Syntax' in the right hand panel
Or paste this link into Bloomi:
{LPHP DAPI:0:1 2277846 }
There are a lot of different examples and options (FX fwds are not my area of expertise), but simply using this format for the ticker seems to work:
ccy1/ccy2 mm/dd/yy Curncy
and then the field PX_BID. You can try this in a BDP call in Excel, for example:
=BDP("EUR/GBP 08/08/22 Curncy","PX_BID")
When it comes to Python, perhaps try using the xbbg python package (other wrappers are available): it does a good job of hiding all the intricacies of the low-level API.
Here's a code sample using xbbg, that pulls back the forward fx rate in the example:
from xbbg import blp
from datetime import datetime
ccy1 = 'EUR'
ccy2 = 'GBP'
fwdDate = datetime(2022,8,8)
ticker = '{0:}/{1:} {2:} Curncy'.format(ccy1,ccy2,fwdDate.strftime('%m/%d/%y'))
df = blp.bdp(ticker,'PX_BID')
print(df)
Output:
px_bid
EUR/GBP 08/08/22 Curncy 0.85344
EDIT: Looking at the OP's choice of Bloomi wrapper, the xbbg call could possibly be replaced by:
blp.referenceRequest(ticker, 'PX_BID')
I am trying to create a column that imports the analyst price target from TipRanks website.
I uploaded two images:
Image 1: you can see the cell that I want to import.
Image 2: you can see my function that doesn't work.
What should I change in order to get this live info?
Thanks.
The site you are checking is actually "javascript" generated thus import functions won't properly work on them.
To check, just try to import the whole site data. If it returns a javascript function, then it is javascript generated.
Sample (tipranks.com)
What you can do is actually try to find other sites that provide the same data.
I did find one with the same data you are looking for, 50.38 for csiq. Link is "https://www.marketwatch.com/investing/stock/csiq/analystestimates". And since data is shown as table, it would be easier to import using importhtml.
Cell formula is:
=INDEX(IMPORTHTML("https://www.marketwatch.com/investing/stock/csiq/analystestimates", "table", 5), 2, 2)
Sample output:
The table is the fifth one in the DOM, and INDEX(table, 2, 2) means getting the 2nd row 2nd column of the table.
If the site is no good for you, you can try finding other sites that would suit your needs. And then use either importhtml or importxml depending on the site structure.
When you inspect the network when the website is loading you will see that the prices come when calling the forecast endpoint https://www.tipranks.com/stocks/tsla/forecast. This in turn returns an html response which is probably generated with Javascript on the client because they use React on the frontend, but you can still see the preview in the Network tab of the browser dev tools.
You can then copy the preview in VSCode and prettify it, to try and pin point the span holding the price. Of course it won't be exact science, because the html tags are generated with some media queries, but you will get close enough to some extent.
After you get the xml path but you get an empty error, you can delete some tags until you get some text. Use search in google sheets to search for highest price label, and than continue adding tags until you get the desired value.
Here is what I managed to get:
Lowest price target:
=importxml("https://www.tipranks.com/stocks/snow/forecast", "/html/body/div[1]/div[1]/div[4]/div[1]/div[2]/div[1]/div[4]/div[2]/div[2]/div[4]/div[1]/div[1]/div[5]/span[2]")
Average price target:
=importxml("https://www.tipranks.com/stocks/snow/forecast", "/html/body/div[1]/div[1]/div[4]/div[1]/div[2]/div[1]/div[4]/div[2]/div[2]/div[4]/div[1]/div[1]/div[3]/span[2]")
Highest price target:
=importxml("https://www.tipranks.com/stocks/snow/forecast", "/html/body/div[1]/div[1]/div[4]/div[1]/div[2]/div[1]/div[4]/div[2]/div[2]/div[4]/div[1]/div[1]/div[1]/span[2]")
In time these methods might change depending on their development process, but you could use the above steps to update the script.
P.S. I wasn't satisfied with the marketwatch analyst price targets. I think the wisdom of the crowd is better on tipranks.
Try this one. Works perfectly fine on my personal Stock Portfolio on Google Sheets:
Lowest Price Target:
=importxml(CONCATENATE("https://www.tipranks.com/stocks/", A1,"/forecast"), "//*[#class='colorpurple-dark ml3 mobile_fontSize7 laptop_ml0']")
Average Price Target:
=importxml(CONCATENATE("https://www.tipranks.com/stocks/", A4,"/forecast"), "//*[#class='colorgray-1 ml3 mobile_fontSize7 laptop_ml0']")
Highest Price Target:
=importxml(CONCATENATE("https://www.tipranks.com/stocks/", A4,"/forecast"), "//*[#class='colorpale ml3 mobile_fontSize7 laptop_ml0']")
I'm a DNN beginner. I am currently building a module in which I can display statistics. My DotNetNuke Version is 7.0. The statistic is from Chartjs. For this statistic I would like to implement filters. These filters should be datepickers. As UI element I have now included a textbox with TextMode='Date'. But currently I have problems to set the default value of this field. The default value should be 01.01. of the current year.
I have already tried to set the value via C# server side. Unfortunately without success. I also tried to set the value on the client side via JavaScript. Unfortunately also without success.
These are some lines I tried in JavaScript:
document.getElementById(<%= this.DatumVon.AccessKey %>).value = "01.01.2019";
document.getElementById(<%= this.DatumVon.AccessKey %>).innerText = "01.01.2019";
document.getElementById("DatumVon").value = "01.01.2019";
These are some lines I tried in C# in the method "Page_Load" (server side):
this.DatumVon.Text = "01.01.2019";
I expected the value of the TextBox to be 01.01.2019. However, it currently only contains dd.mmm.yyyy. How can I change this?
Thank you.
There is something wrong with your localization. Please refer to the jQuery UI datepicker documentation (the "Localization" section), this should give you the answer.
wow... I solved it. I made it. Sometimes the solution is right in front of you and you don't see it. Michael Tobisch was absolutely right. When setting the value, the format is very important. I have always used the German format. A DNN TextBox with TextMode="Date" can't handle that. DNN converts this TextBox into an HTML input field. But this input field can only be clear with the format "yyyy-mm-dd". Depending on the geographical position of the client (at least that's what I think) the text displayed in the input field will be formatted. But the value of the input field always has the same format ("yyyy-mm-dd"). So very important here: the displayed text and the actual value have different formats.
Many thanks again to Michael Tobisch for the mental inspiration and the patience with me.
What is also important is that the access to the actual ID of a DNN element works as follows: this.Element.ClientID and not as I assumed before this.Element.AccessKey. This was also buggy.
I'm using the Dark Sky Forecast API to retrieve some weather information.
When I read the official doc, I found that the "option" section describes the usage of query parameters.
For example,
The API request may optionally be modified through the use of query parameters. It will respond to the following:
callback=[callback]: Return the API response as JSONP. Please use
caution when using this, since exposing your API key to the public is
a security hazard and, if abused, will result in the revokation of
your API key. However, if developing a personal- or internal-use app,
this is a convenient method of doing so.
units=[setting]: Return the
API response in units other than the default Imperial units. In
particular, the following settings are possible:
us: The default, as outlined above.
si: Returns results in SI units. In particular, properties now have the following units:
...
I know how to get the weather information by take advantages of the call
https://api.forecast.io/forecast/APIKEY/LATITUDE,LONGITUDE
But I don't know how to combine the query parameters with it.
Any ideas?
2015/10/23 UPDATE
Thank to Logan Kearns, using ? parameter solved my question. Make sure the query parameters are in lowercase.
https://api.forecast.io/forecast/APIKEY/LATITUDE,LONGITUDE?lang=zh-tw&units=si
This is how you change the units. I assume that other query parameters would be set in a similar manner, using the '?' to separate them.
https://api.forecast.io/forecast/APIKEY/LATITUDE,LONGITUDE?UNITS=us
Just an update, since url changed and with few other parameters:
You can add units to mention the type of unit conversion required
You can add exclude for excluding certain data in the response like hourly updates.
https://api.darksky.net/forecast/APIKEY/LAT,LONG?units=si&exclude=minutely,hourly,daily,alerts
I can select a currency with a currency column but the value is always in USD, is it possible to change the currency iso code?
E.g. $39.99 this is in Canadian dollars but always appears 39.99 USD.
I see you can use text but then i am stuck with the $ symbol.
Right now i have had to use a regular expression to drop the $
What is happening is that the price you see is through your own IP address, but when you run your API you are calling the API on our American servers for you. The website registers our servers' US IP address and display their price in US dollars instead. Unfortunately, at this time, you cannot change the currency.
If you are using a Crawler, in the Advanced Options (by toggling the Simple button to Advanced), choose to crawl Locally instead, this will use your own IP address, and should therefore display the price in your desired currency.
Thanks,
Meg