business-science / riingo

An R interface to the Tiingo stock price API
https://business-science.github.io/riingo/
Other
51 stars 9 forks source link

Tibble display not useful #4

Closed eddelbuettel closed 4 years ago

eddelbuettel commented 6 years ago
R> res <- riingo_iex_latest("SPY")
R> tail(res)
# A tibble: 6 x 6
  ticker date                 open  high   low close
  <chr>  <dttm>              <dbl> <dbl> <dbl> <dbl>
1 SPY    2018-04-16 13:49:00.000000  267.  267.  267.  267.
2 SPY    2018-04-16 13:50:00.000000  267.  267.  267.  267.
3 SPY    2018-04-16 13:51:00.000000  266.  266.  266.  266.
4 SPY    2018-04-16 13:52:00.000000  266.  266.  266.  266.
5 SPY    2018-04-16 13:53:00.000000  266.  266.  266.  266.
6 SPY    2018-04-16 13:54:00.000000  266.  266.  266.  266.
R> 

The time should be aware of localtime, and the resolution is simply not useful for pricing data.

DavisVaughan commented 6 years ago

Agreed. I already include convert_to_local_time() because I was unsure of what the best thing to do here was, but can default to local time. I can make the resolution dependent on the resample_frequency and return Date when appropriate rather than POSIXct

eddelbuettel commented 6 years ago

Also omitting the pennies when the only difference is in pennies is ... not good. These are prices (and OHLC aren't even computed aggregates). Can we not always show two digits?

Also not how my options(digits.secs=6) creeps in and messes up the column alignment, but I guess that may be a tibble issue.

DavisVaughan commented 6 years ago

Re digits.secs) Yes ive reported that https://github.com/r-lib/pillar/issues/102

Re pennies) Another pillar issue. Aggressive truncation. Try) options(pillar.sigfig = 6)

eddelbuettel commented 6 years ago

sigfig=6 may still fail on high priced stocks.But I guess this is a new bug :-/

R> res <- riingo_iex_latest("BRK.A")
Error: lexical error: invalid char in json text.
                                       <h1>Not Found</h1><p>The reques
                     (right here) ------^
R> 

Also affects ringo_latest.

DavisVaughan commented 6 years ago

Frustrating. I can catch riingo_iex_latest("abcde") because it returns actual JSON. riingo_iex_latest("BRK.A") returns HTML which gets converted into an xml_document

tiingo commented 6 years ago

Hi all,

Thanks for the great work @DavisVaughan

The reason for the URL handling is that we do not use "." in our ticker methodology. Let me talk to my team and see if we can implement a better JSON-encoded 404 for when "." are used. This should make it consistent. Thank you for the catch.

DavisVaughan commented 6 years ago

Thanks @tiingo for the great support.

In the mean time, the dev version catches it with a slightly more informative error:

> riingo::riingo_iex_latest("BRK.A")
Error: The ticker name, BRK.A, is invalid or data is currently not available. Check ticker validity with is_supported_ticker().
Tiingo msg) <h1>Not Found</h1><p>The requested URL /iex/BRK.A/prices was not found on this server.</p>

Which is still somewhat frustrating because:

> is_supported_ticker("BRK.A", "iex")
[1] TRUE

IEX supported tickers data come from: https://iextrading.com/api/mobile/refdata

tiingo commented 6 years ago

@DavisVaughan We are able to return a JSON error message on a 404 with a ticker with a ".".

For "is_supported_ticker" would you be open to querying a Tiingo endpoint to see if the ticker is available?

Holding off pushing the API change for the 404 error depending on your answer to is_supported_ticker

DavisVaughan commented 6 years ago

@tiingo Yea that'd be great

tiingo commented 6 years ago

You should now see a consistent error message if the ticker contains a "."

E.g. https://api.tiingo.com/tiingo/daily/brk.a/prices?startDate=2017-1-1

Additionally, you can use the meta endpoint to see if a ticker exists, which is simply: https://api.tiingo.com/tiingo/daily/brk.a

Let me know if this works @DavisVaughan

Thanks all

eddelbuettel commented 6 years ago

But ... BRK.A is a valid symbol and known / traded on IEX rfom what I can tell.

tiingo commented 6 years ago

@eddelbuettel We use "-" instead of "."

e.g. https://api.tiingo.com/tiingo/daily/brk-b/prices?startDate=2017-1-1 or https://api.tiingo.com/iex/brk-b/prices?startDate=2018-04-16&resampleFreq=5min