Skip to content

Commit f25d4e0

Browse files
author
Shlomi Kushchi
authored
Merge pull request #300 from alpacahq/add_trail_to_replace_order
Add support for replacing a trailing_stop order
2 parents aa49139 + 7187702 commit f25d4e0

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

alpaca_trade_api/rest.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ def replace_order(
333333
qty: str = None,
334334
limit_price: str = None,
335335
stop_price: str = None,
336+
trail: str = None,
336337
time_in_force: str = None,
337338
client_order_id: str = None
338339
) -> Order:
@@ -341,7 +342,12 @@ def replace_order(
341342
:param qty: str of int
342343
:param limit_price: str of float
343344
:param stop_price: str of float
345+
:param trail: str of float, represents trailing_price or
346+
trailing_percent. determined by the original order.
344347
:param time_in_force: day, gtc, opg, cls, ioc, fok
348+
349+
note: you cannot replace type of order. so, it was trailing_stop(e.g)
350+
it will remain trailing_stop.
345351
"""
346352
params = {}
347353
if qty is not None:
@@ -350,6 +356,8 @@ def replace_order(
350356
params['limit_price'] = FLOAT(limit_price)
351357
if stop_price is not None:
352358
params['stop_price'] = FLOAT(stop_price)
359+
if trail is not None:
360+
params['trail'] = FLOAT(trail)
353361
if time_in_force is not None:
354362
params['time_in_force'] = time_in_force
355363
if client_order_id is not None:

tests/test_rest.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ def test_orders(reqmock):
102102
"filled_at": "2018-03-09T19:05:27Z",
103103
"failed_at": "2018-03-09T19:05:27Z",
104104
"filled_qty": "0",
105+
"hwm": null,
106+
"trail_percent": null,
107+
"trail_price": null,
105108
"failured_reason": "string",
106109
"cancel_requested_at": "2018-03-09T19:05:27Z",
107110
"submitted_at": "2018-03-09T19:05:27Z"
@@ -133,6 +136,9 @@ def test_orders(reqmock):
133136
"filled_at": "2018-03-09T19:05:27Z",
134137
"failed_at": "2018-03-09T19:05:27Z",
135138
"filled_qty": "0",
139+
"hwm": null,
140+
"trail_percent": null,
141+
"trail_price": null,
136142
"failured_reason": "string",
137143
"cancel_requested_at": "2018-03-09T19:05:27Z",
138144
"submitted_at": "2018-03-09T19:05:27Z"
@@ -218,6 +224,9 @@ def test_orders(reqmock):
218224
"filled_at": "2018-03-09T05:50:50Z",
219225
"failed_at": "2018-03-09T05:50:50Z",
220226
"filled_qty": "0",
227+
"hwm": null,
228+
"trail_percent": null,
229+
"trail_price": null,
221230
"failured_reason": "string",
222231
"cancel_requested_at": "2018-03-09T05:50:50Z",
223232
"submitted_at": "2018-03-09T05:50:50Z"
@@ -249,6 +258,9 @@ def test_orders(reqmock):
249258
"filled_at": "2018-03-09T05:50:50Z",
250259
"failed_at": "2018-03-09T05:50:50Z",
251260
"filled_qty": "0",
261+
"hwm": null,
262+
"trail_percent": null,
263+
"trail_price": null,
252264
"failured_reason": "string",
253265
"cancel_requested_at": "2018-03-09T05:50:50Z",
254266
"submitted_at": "2018-03-09T05:50:50Z"

0 commit comments

Comments
 (0)