alpaca-trade-api-js icon indicating copy to clipboard operation
alpaca-trade-api-js copied to clipboard

Close Position by symbol not accepting qty - no of shares to liquidate

Open devansvd opened this issue 4 years ago • 1 comments

As per the Alpaca docs - Close a position by symbol endpoint - [DELETE]/v2/positions/{symbol} Accepts a query parameter qty - the number of shares to liquidate, But this nodejs implementation varient doesn't accepting qty query parameter.

docs url: https://alpaca.markets/docs/api-documentation/api-v2/positions

Screenshot 2021-02-24 at 12 40 33 PM

API usage:

Close a Position

Calls DELETE /positions/{symbol} and liquidates your position in the given symbol.

closePosition(symbol) => Promise

Notice No qty parameter here

Implementation - https://github.com/alpacahq/alpaca-trade-api-js/blob/master/lib/resources/position.js

function closeAll() {
  return this.httpRequest('/positions', null, null, 'DELETE')
}

Please Advise us on how to use utilize this. Basically want to achieve Close a position by symbol with N qty.

Thanks.

devansvd avatar Feb 24 '21 07:02 devansvd

As I understand from documentation, you just have to provide Query parametr, not Body/Post parameter. So simple:

closePosition(symbol) => Promise

closePosition("AAPL?qty=0.0001")

mr-smit avatar Feb 21 '22 16:02 mr-smit