Skip to content

Commit

Permalink
Added account_config and replace_order endpoints
Browse files Browse the repository at this point in the history
Still need to test account_config
  • Loading branch information
andrewkim316 committed Sep 11, 2019
1 parent b237367 commit 083a12d
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions alpaca_trade_api/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ def get(self, path, data=None):

def post(self, path, data=None):
return self._request('POST', path, data)

def patch(self, path, data=None):
return self._request('PATCH', path, data)

def delete(self, path, data=None):
return self._request('DELETE', path, data)
Expand All @@ -165,6 +168,25 @@ def get_account(self):
resp = self.get('/account')
return Account(resp)

def get_account_configs(self):
'''Get account configs'''
resp = self.get('/account/configurations')
return Account(resp)

def edit_account_configs(self, no_shorting=None, dtbp_check=None, trade_confirm_email=None, suspend_trade=None):
'''Edit account configs'''
params = {}
if no_shorting is not None:
params['no_shorting'] = no_shorting
if dtbp_check is not None:
params['dtbp_check'] = dtbp_check
if trade_confirm_email is not None:
params['trade_confirm_email'] = trade_confirm_email
if suspend_trade is not None:
params['suspend_trade'] = suspend_trade
resp = self.patch('/account/configurations',params)
return Account(resp)

def list_orders(self, status=None, limit=None, after=None, until=None,
direction=None, params=None):
'''
Expand Down Expand Up @@ -220,6 +242,21 @@ def get_order(self, order_id):
resp = self.get('/orders/{}'.format(order_id))
return Order(resp)

def replace_order(self, order_id, qty=None, limit_price=None, stop_price=None, time_in_force=None, client_order_id=None):
params = {}
if qty is not None:
params['qty'] = qty
if limit_price is not None:
params['limit_price'] = limit_price
if stop_price is not None:
params['stop_price'] = stop_price
if time_in_force is not None:
params['time_in_force'] = time_in_force
if client_order_id is not None:
params['client_order_id'] = client_order_id
resp = self.patch('/orders/{}'.format(order_id), params)
return Order(resp)

def cancel_order(self, order_id):
'''Cancel an order'''
self.delete('/orders/{}'.format(order_id))
Expand Down

0 comments on commit 083a12d

Please sign in to comment.