Skip to content

Commit

Permalink
Change polygon format
Browse files Browse the repository at this point in the history
  • Loading branch information
umitanuki committed Dec 23, 2018
1 parent 2561ff0 commit 665b7bc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions alpaca_trade_api/polygon/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ def df(self):
# polygon doesn't return in ascending order
# Do not rely on df.sort_values() as this library
# may be used with older pandas
keycol = 't' if size[0] == 'm' else 'd'
columns = ('o', 'h', 'l', 'c', 'v', keycol)
df = pd.DataFrame(
sorted(raw['ticks'], key=lambda d: d['d']),
columns=('o', 'h', 'l', 'c', 'v', 'd'),
sorted(raw['ticks'], key=lambda d: d[keycol]),
columns=columns,
)
df.columns = [raw['map'][c] for c in df.columns]
if size[0] == 'm':
Expand Down
4 changes: 2 additions & 2 deletions tests/test_polygon/test_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def test_polygon(reqmock):
"h": "high",
"l": "low",
"o": "open",
"d": "timestamp",
"t": "timestamp",
"v": "volume"
},
"status": "success",
Expand All @@ -162,7 +162,7 @@ def test_polygon(reqmock):
"l": 173.15,
"h": 173.21,
"v": 1800,
"d": 1517529605000
"t": 1517529605000
}
]
}''')
Expand Down

0 comments on commit 665b7bc

Please sign in to comment.