Skip to content

Commit d560c9b

Browse files
authored
Add Week and Month timeframe units (#583)
1 parent 80d27c7 commit d560c9b

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

alpaca_trade_api/rest.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ class TimeFrameUnit(Enum):
8080
Minute = "Min"
8181
Hour = "Hour"
8282
Day = "Day"
83+
Week = "Week"
84+
Month = "Month"
8385

8486

8587
class TimeFrame:
@@ -126,11 +128,21 @@ def validate(amount: int, unit: TimeFrameUnit):
126128
if unit == TimeFrameUnit.Hour and amount > 23:
127129
raise ValueError("Hour units can only be used with amounts 1-23")
128130

131+
if unit in (TimeFrameUnit.Day, TimeFrameUnit.Week) and amount != 1:
132+
raise ValueError(
133+
"Day and Week units can only be used with amount 1")
134+
135+
if unit == TimeFrameUnit.Month and amount not in (1, 2, 3, 6, 12):
136+
raise ValueError(
137+
"Month units can only be used with amount 1, 2, 3, 6 and 12")
138+
129139

130140
# These are kept for backwards compatibility
131141
TimeFrame.Minute = TimeFrame(1, TimeFrameUnit.Minute)
132142
TimeFrame.Hour = TimeFrame(1, TimeFrameUnit.Hour)
133143
TimeFrame.Day = TimeFrame(1, TimeFrameUnit.Day)
144+
TimeFrame.Week = TimeFrame(1, TimeFrameUnit.Week)
145+
TimeFrame.Month = TimeFrame(1, TimeFrameUnit.Month)
134146

135147

136148
class Sort(Enum):

0 commit comments

Comments
 (0)