question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Missing Key 'n' in entity mapping

See original GitHub issue

Hi!

It looks like web api was updated recently, with two extra fields: ‘n’, ‘vw’ {'t': '2021-06-28T04:00:00Z', 'o': 10.15, 'h': 10.3, 'l': 10.04, 'c': 10.04, 'v': 20356, 'n': 111, 'vw': 10.113978} So now conversion to pandas dataframe using ‘.df’ method fails with exception

Traceback (most recent call last):
  File "\divscan.py", line 548, in <module>
  File "\divscan.py", line 293, in prepareData
    data = fetchDelta(ticker, TimeFrame.Day, minBars, past, now)
  File "\divscan.py", line 279, in fetchDelta
    df = fetchData(ticker, tf, start, end)
  File "\divscan.py", line 258, in fetchData
    return data.df
  File "\lib\site-packages\alpaca_trade_api\entity_v2.py", line 61, in df
    df.columns = [self.mapping[c] for c in df.columns]
  File "\lib\site-packages\alpaca_trade_api\entity_v2.py", line 61, in <listcomp>
    df.columns = [self.mapping[c] for c in df.columns]
KeyError: 'n'

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
erickalfarocommented, Jun 30, 2021

Simple solution:

r = alpaca_api.get_bars('AAPL'
, TimeFrame.Minute
, pd.Timestamp('2021-02-01 00:00:00', tz=timezone('UTC')).isoformat() # start.tz_convert('UTC').isoformat()
, pd.Timestamp('2021-03-01 00:00:00', tz=timezone('UTC')).isoformat() # end.tz_convert('UTC').isoformat()
, limit=4
, adjustment='raw')
df = pd.read_json(json.dumps(r._raw))
2reactions
erickalfarocommented, Jun 30, 2021

I dont want to speculate but this API returns exactly what the Polygon API aggregate_bars API returns.

VW stands for volume weighted average price.

https://polygon.io/docs/get_v2_aggs_ticker__stocksTicker__range__multiplier___timespan___from___to__anchor

Read more comments on GitHub >

github_iconTop Results From Across the Web

Mapping entity without key - Stack Overflow
I've got two tables in database: Table A (parent) has a primary key column and Table B (child) doesn't have a key at...
Read more >
Data Mapping Troubleshooting - Amazon AWS
For an Unfamiliar Dimension that has multiple values for every Entity Key, you may notice that you have 'lost' Dimension values i.e., instead...
Read more >
Entity Types - EF Core - Microsoft Learn
How to configure and map entity types using Entity Framework Core. ... If no DbSet exists for the given entity, the class name...
Read more >
Hibernate Mapping Exception – Unknown Entity - Baeldung
MappingException : Unknown entity issue and solutions, both for Hibernate as well as for a Spring and Hibernate environment.
Read more >
Configuring One To Many Relationships in Entity Framework ...
The With side of the relationship is represented by the WithOne and ... defined in the dependent entity ( Employee ) but no...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found