alpacahq / Alpaca-API

The Alpaca API is a developer interface for trading operations and market data reception through the Alpaca platform.
https://alpaca.markets/
143 stars 13 forks source link

start and stop in barset have no effect #34

Closed manurastogi closed 5 years ago

manurastogi commented 5 years ago

I ran the following code:

api.get_barset('AAPL', timeframe='15Min',start='cat',end='dog',limit=10) api.get_barset('AAPL', timeframe='15Min',start=1549051200,end = 1548997200) api.get_barset('AAPL', timeframe='15Min',start=pd.Timestamp(2019,1,30,9,31),end = pd.Timestamp(2019,1,30,9,40))

I get the same result it seems like the start and end have no effect. Or maybe I am doing something wrong.

Thanks

umitanuki commented 5 years ago

You need to use Timestamp().isoformat() from python. I agree it's not a good practice malformed parameters are silently ignored.

manurastogi commented 5 years ago

Thanks that works. Here is the correct code just in case someone comes looking at it again

api.get_barset('AAPL', timeframe='day',start=pd.Timestamp('2019-01-30 09:45',tz='America/New_York').isoformat(),end = pd.Timestamp('2019-02-4 09:45',tz='America/New_York').isoformat())

output: {'AAPL': [Bar({ 'c': 165.25, 'h': 166.15, 'l': 160.23, 'o': 163.25, 't': 1548824400, 'v': 60793770}), Bar({ 'c': 166.44, 'h': 169, 'l': 164.56, 'o': 166.11, 't': 1548910800, 'v': 40611481}), Bar({ 'c': 166.52, 'h': 168.98, 'l': 165.93, 'o': 166.96, 't': 1548997200, 'v': 32642411}), Bar({ 'c': 171.25, 'h': 171.655, 'l': 167.28, 'o': 167.41, 't': 1549256400, 'v': 31376272})]}

Validation pd.Timestamp(1548824400,unit='s')
Timestamp('2019-01-30 05:00:00')