Skip to content

Commit 2610d34

Browse files
author
Shlomi Kushchi
authored
Merge pull request #296 from alpacahq/feature/trailing-stop
Feature/trailing stop
2 parents 8e7bef4 + 4be49a5 commit 2610d34

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,5 +97,6 @@ ENV/
9797
# vim swap file
9898
*.swp
9999

100-
# vscode
101-
/.vscode/
100+
# IDE
101+
/.vscode/
102+
.idea/

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ Calls `GET /account` and returns an `Account` entity.
109109
Calls `GET /orders` and returns a list of `Order` entities.
110110
`after` and `until` need to be string format, which you can obtain by `pd.Timestamp().isoformat()`
111111

112-
### REST.submit_order(symbol, qty, side, type, time_in_force, limit_price=None, stop_price=None, client_order_id=None, order_class=None, take_profit=None, stop_loss=None)
112+
### REST.submit_order(symbol, qty, side, type, time_in_force, limit_price=None, stop_price=None, client_order_id=None, order_class=None, take_profit=None, stop_loss=None, trail_price=None, trail_percent=None)
113113
Calls `POST /orders` and returns an `Order` entity.
114114

115115
Below is an example of submitting a bracket order.

alpaca_trade_api/rest.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,8 @@ def submit_order(self,
257257
order_class: str = None,
258258
take_profit: dict = None,
259259
stop_loss: dict = None,
260-
**kwargs):
260+
trail_price: str = None,
261+
trail_percent: str = None):
261262
"""
262263
:param symbol: symbol or asset ID
263264
:param qty: int
@@ -274,15 +275,16 @@ def submit_order(self,
274275
{"limit_price": "298.95"}
275276
:param stop_loss: dict with fields "stop_price" and "limit_price" e.g
276277
{"stop_price": "297.95", "limit_price": "298.95"}
278+
:param trail_price: str of float
279+
:param trail_percent: str of float
277280
"""
278281
"""Request a new order"""
279282
params = {
280283
'symbol': symbol,
281284
'qty': qty,
282285
'side': side,
283286
'type': type,
284-
'time_in_force': time_in_force,
285-
**kwargs
287+
'time_in_force': time_in_force
286288
}
287289
if limit_price is not None:
288290
params['limit_price'] = FLOAT(limit_price)
@@ -304,6 +306,10 @@ def submit_order(self,
304306
if 'stop_price' in stop_loss:
305307
stop_loss['stop_price'] = FLOAT(stop_loss['stop_price'])
306308
params['stop_loss'] = stop_loss
309+
if trail_price is not None:
310+
params['trail_price'] = trail_price
311+
if trail_percent is not None:
312+
params['trail_percent'] = trail_percent
307313
resp = self.post('/orders', params)
308314
return Order(resp)
309315

requirements/requirements.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@ pandas # pyup: ignore
22
requests>2,<3
33
urllib3>1.24,<1.26
44
websocket-client>=0.56.0,<1
5-
websockets>=8.0,<9
6-
5+
websockets>=8.0,<9

0 commit comments

Comments
 (0)