1

Stock Quote API returning commas in data items

Hi,

I am writing an application (for personal use) which uses yahoo's Stock Quote API (i.e. http://download.finance.yahoo.com/d/quotes.csv) for fetching the stock information. Since the data items are supposed to be separated by comma so I was simply splitting returned string by comma. This way I was able to successfully convert the long string into an array of string

This was working fine untill I hit a situation where the data for one the stock itself contains commas.

i.e. if you look at the below URL, you will find that I have requested 7 flags viz

n(Name)
k3(Last Trade Size)
f6(Float Shares)
b(Bid)
c1(Change)
b4(Book Value)
m4(200-day Moving Average)

http://download.finance.yahoo.com/d/quotes...;f=nk3f6bc1b4m4

It returns following string

"Microsoft Corpora",2,106,173, 7,637,082,000,18.18,+0.05,3.879,22.5647

since the data item for k3 and f6 itself contains comma, so splitting this into array returned me 12 items instead of 7.

It seems the service is applying some data formatting for k3 and f6 before returning it to user.

Is there any way to prevent this or is there any flag or any option that I am missing?

Ishwar Jindal

by
4 Replies
  • QUOTE (Ishwar Jindal @ Feb 12 2009, 09:49 PM) <{POST_SNAPBACK}>
    It returns following string

    "Microsoft Corpora",2,106,173, 7,637,082,000,18.18,+0.05,3.879,22.5647

    since the data item for k3 and f6 itself contains comma, so splitting this into array returned me 12 items instead of 7.

    the only way i can think of getting around this would be to make 3 separate queries: one for the name, bid, change, book value, and 200-day average; one for just k3; one for just f6. this way you could be absolutely sure about what you're getting and it wouldn't be too hard to piece the results of these three individual queries back together in your code

    hope this is still relevant. cheers
    1
  • QUOTE (thomat65 @ Jul 28 2009, 05:45 PM) <{POST_SNAPBACK}>
    the only way i can think of getting around this would be to make 3 separate queries: one for the name, bid, change, book value, and 200-day average; one for just k3; one for just f6. this way you could be absolutely sure about what you're getting and it wouldn't be too hard to piece the results of these three individual queries back together in your code

    hope this is still relevant. cheers


    Does the finance open data table suffice that's checked into the community open data tables?

    http://developer.yahoo.com/yql/console/?q=...2Falltables.env

    You can even browse the source to see how it did the job.

    There's also a blog posting describing how it was built on the main yqlblog.net site:
    http://www.yqlblog.net/blog/2009/06/02/get...en-data-tables/

    Jonathan
    0
  • This is still happening. k3 still returns a number formatted with commas, English-style.

    How do we get this fixed?

    0
  • The following is a little inelegant, but works. Symbols(s) and names return alphanumerics in quotes, followed by comma. Numbers (k3,f6) have commas within numbers and comma at end.

    One should intersperse number data items (k3,f6) with alpha data items (s). Example lets say we need for one ticker IBM we need s k3 f6. query string should be "&f=sk3sf6"

    Return string sRet= "IBM",43,300,"IBM",9,800 Now we must do two replacements 1. Change every (",) to a arbitrary delimiter (|}.

    We get sRet="IBM|43,300,"IBM|9,800

    1. Eliminate " We get sRet = IBM |43,300,IBM|9,800

    2. Eliminate comma , we get sRet =IBM|433300|IBM|9800

    4, Now we can split string into array using delimiter |

    Note: Procedure is a pain, but computers are fast.

    0

Recent Posts

in YQL