Skip to content

Commit 8e884e3

Browse files
author
Shlomi Kushchi
authored
Merge pull request #197 from alpacahq/rc4_new_data_schema
Support the new data schema
2 parents 97be1f8 + 56abf6e commit 8e884e3

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

alpaca_trade_api/entity.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -134,16 +134,20 @@ def __getattr__(self, key):
134134
if key in self._raw:
135135
val = self._raw[key]
136136
if key == 'timestamp':
137-
if val > 1000000000000000000:
138-
# this is for supporing timestamp represented in nanosecond.
139-
# the alpaca data api uses nanoseconds. polygon uses microseconds.
140-
return pd.Timestamp(val, tz=NY)
141-
return pd.Timestamp(val, tz=NY, unit='ms')
137+
return pd.Timestamp(val, tz=NY, unit=self.unit)
142138
return val
143139
return getattr(super(), key)
144140

145141

146-
class Agg(_Timestamped, Entity):
142+
class _NanoTimestamped(_Timestamped):
143+
unit = 'ns'
144+
145+
146+
class _MilliTimestamped(_Timestamped):
147+
unit = 'ms'
148+
149+
150+
class Agg(_MilliTimestamped, Entity):
147151
pass
148152

149153

@@ -189,11 +193,11 @@ def df(self):
189193
return self._df
190194

191195

192-
class Trade(_Timestamped, Entity):
196+
class Trade(_NanoTimestamped, Entity):
193197
pass
194198

195199

196-
class Quote(_Timestamped, Entity):
200+
class Quote(_NanoTimestamped, Entity):
197201
pass
198202

199203

@@ -251,7 +255,7 @@ def df(self):
251255

252256

253257
trade_mapping = {
254-
"sym": "symbol",
258+
"T": "symbol",
255259
"c": "conditions",
256260
"x": "exchange",
257261
"p": "price",
@@ -272,7 +276,7 @@ def df(self):
272276
}
273277

274278
agg_mapping = {
275-
"sym": "symbol",
279+
"T": "symbol",
276280
"o": "open",
277281
"c": "close",
278282
"h": "high",

tests/test_rest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ def test_data(reqmock):
399399
"cond2": 16,
400400
"cond3": 0,
401401
"cond4": 0,
402-
"timestamp": 1518086464720
402+
"timestamp": 1518101436000900000
403403
}
404404
}
405405
'''
@@ -422,7 +422,7 @@ def test_data(reqmock):
422422
"bidprice": 159.45,
423423
"bidsize": 20,
424424
"bidexchange": 12,
425-
"timestamp": 1518086601843
425+
"timestamp": 1518101436000900000
426426
}
427427
}'''
428428
)

0 commit comments

Comments
 (0)