Skip to content

Commit 99368c1

Browse files
authored
Merge pull request #113 from alpacahq/add-configs-and-replace-order
Add configs and replace order
2 parents b237367 + 735cbb8 commit 99368c1

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed

alpaca_trade_api/entity.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ class Account(Entity):
3939
pass
4040

4141

42+
class AccountConfigurations(Entity):
43+
pass
44+
45+
4246
class Asset(Entity):
4347
pass
4448

alpaca_trade_api/rest.py

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
get_api_version,
1111
)
1212
from .entity import (
13-
Account, Asset, Order, Position,
14-
BarSet, Clock, Calendar,
13+
Account, AccountConfigurations, Asset,
14+
Order, Position, BarSet, Clock, Calendar,
1515
)
1616
from . import polygon
1717

@@ -151,6 +151,9 @@ def get(self, path, data=None):
151151
def post(self, path, data=None):
152152
return self._request('POST', path, data)
153153

154+
def patch(self, path, data=None):
155+
return self._request('PATCH', path, data)
156+
154157
def delete(self, path, data=None):
155158
return self._request('DELETE', path, data)
156159

@@ -165,6 +168,31 @@ def get_account(self):
165168
resp = self.get('/account')
166169
return Account(resp)
167170

171+
def get_account_configurations(self):
172+
'''Get account configs'''
173+
resp = self.get('/account/configurations')
174+
return AccountConfigurations(resp)
175+
176+
def update_account_configurations(
177+
self,
178+
no_shorting=None,
179+
dtbp_check=None,
180+
trade_confirm_email=None,
181+
suspend_trade=None
182+
):
183+
'''Update account configs'''
184+
params = {}
185+
if no_shorting is not None:
186+
params['no_shorting'] = no_shorting
187+
if dtbp_check is not None:
188+
params['dtbp_check'] = dtbp_check
189+
if trade_confirm_email is not None:
190+
params['trade_confirm_email'] = trade_confirm_email
191+
if suspend_trade is not None:
192+
params['suspend_trade'] = suspend_trade
193+
resp = self.patch('/account/configurations', params)
194+
return AccountConfigurations(resp)
195+
168196
def list_orders(self, status=None, limit=None, after=None, until=None,
169197
direction=None, params=None):
170198
'''
@@ -220,6 +248,29 @@ def get_order(self, order_id):
220248
resp = self.get('/orders/{}'.format(order_id))
221249
return Order(resp)
222250

251+
def replace_order(
252+
self,
253+
order_id,
254+
qty=None,
255+
limit_price=None,
256+
stop_price=None,
257+
time_in_force=None,
258+
client_order_id=None
259+
):
260+
params = {}
261+
if qty is not None:
262+
params['qty'] = qty
263+
if limit_price is not None:
264+
params['limit_price'] = limit_price
265+
if stop_price is not None:
266+
params['stop_price'] = stop_price
267+
if time_in_force is not None:
268+
params['time_in_force'] = time_in_force
269+
if client_order_id is not None:
270+
params['client_order_id'] = client_order_id
271+
resp = self.patch('/orders/{}'.format(order_id), params)
272+
return Order(resp)
273+
223274
def cancel_order(self, order_id):
224275
'''Cancel an order'''
225276
self.delete('/orders/{}'.format(order_id))

0 commit comments

Comments
 (0)