Skip to content

Commit db47082

Browse files
authored
Merge pull request #101 from alpacahq/feature/liquidate-all-positions
Add position liquidation endpoints
2 parents 653b607 + 6436bbf commit db47082

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

alpaca_trade_api/polygon/rest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def news(self, symbol):
150150
return NewsList(self.get(path))
151151

152152
def gainers_losers(self, direction="gainers"):
153-
path = '/snapshot/locale/us/markets/stocks/{}'.format(direction)
153+
path = '/snapshot/locale/us/markets/stocks/{}'.format(direction)
154154
return [
155155
Ticker(ticker) for ticker in
156156
self.get(path, version='v2')['tickers']

alpaca_trade_api/rest.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,14 @@ def get_position(self, symbol):
234234
resp = self.get('/positions/{}'.format(symbol))
235235
return Position(resp)
236236

237+
def close_position(self, symbol):
238+
'''Liquidates the position for the given symbol at market price'''
239+
self.delete('/positions/{}'.format(symbol))
240+
241+
def close_all_positions(self, symbol):
242+
'''Liquidates all open positions at market price'''
243+
self.delete('/positions')
244+
237245
def list_assets(self, status=None, asset_class=None):
238246
'''Get a list of assets'''
239247
params = {

0 commit comments

Comments
 (0)