Skip to content

Commit

Permalink
Fix long line issues (alpacahq#502)
Browse files Browse the repository at this point in the history
  • Loading branch information
gnvk authored Sep 30, 2021
1 parent 52c33ce commit a34b337
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
5 changes: 3 additions & 2 deletions alpaca_trade_api/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,14 @@ def validate(amount: int, unit: TimeFrameUnit):
raise "Amount must be a positive integer value."

if unit == TimeFrameUnit.Minute and amount > 59:
raise "Second or Minute units can only be used with amounts between 1-59."
raise "Second or Minute units can only be used " + \
"with amounts between 1-59."

if unit == TimeFrameUnit.Hour and amount > 23:
raise "Hour units can only be used with amounts 1-23"


# TimeFrame.Minute, TimeFrame.Hour and TimeFrame.Day kept for backwards compatibility
# These are kept for backwards compatibility
TimeFrame.Minute = TimeFrame(1, TimeFrameUnit.Minute)
TimeFrame.Hour = TimeFrame(1, TimeFrameUnit.Hour)
TimeFrame.Day = TimeFrame(1, TimeFrameUnit.Day)
Expand Down
9 changes: 6 additions & 3 deletions tests/test_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -791,15 +791,17 @@ def test_data(reqmock):

def test_timeframe(reqmock):
# Custom timeframe: Minutes
reqmock.get('https://data.alpaca.markets/v2/stocks/AAPL/bars?timeframe=45Min&adjustment=raw&'
reqmock.get('https://data.alpaca.markets/v2/stocks/AAPL/bars?'
'timeframe=45Min&adjustment=raw&'
'start=2021-06-08&end=2021-06-08', text='{}')
api = tradeapi.REST('key-id', 'secret-key', api_version='v1')
timeframe = tradeapi.TimeFrame(45, tradeapi.TimeFrameUnit.Minute)
api.get_bars('AAPL', timeframe, '2021-06-08', '2021-06-08')
assert reqmock.called

# Custom timeframe: Hours
reqmock.get('https://data.alpaca.markets/v2/stocks/AAPL/bars?timeframe=23Hour&adjustment=raw&'
reqmock.get('https://data.alpaca.markets/v2/stocks/AAPL/bars?'
'timeframe=23Hour&adjustment=raw&'
'start=2021-06-08&end=2021-06-08', text='{}')
timeframe = tradeapi.TimeFrame(23, tradeapi.TimeFrameUnit.Hour)
api.get_bars('AAPL', timeframe, '2021-06-08', '2021-06-08')
Expand All @@ -817,7 +819,8 @@ def test_timeframe(reqmock):
timeframe = tradeapi.TimeFrame(23, tradeapi.TimeFrameUnit.Hour)
timeframe.amount = 5
timeframe.unit = tradeapi.TimeFrameUnit.Minute
reqmock.get('https://data.alpaca.markets/v2/stocks/AAPL/bars?timeframe=5Min&adjustment=raw&'
reqmock.get('https://data.alpaca.markets/v2/stocks/AAPL/bars?'
'timeframe=5Min&adjustment=raw&'
'start=2021-06-08&end=2021-06-08', text='{}')
api.get_bars('AAPL', timeframe, '2021-06-08', '2021-06-08')
assert reqmock.called
Expand Down

0 comments on commit a34b337

Please sign in to comment.