alpacahq / alpacahq/Alpaca-API

Closed positions

Open
#163 0 comments 9 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
173
Forks
17
PR merge metrics
No merged PRs in 30d

Description

There is an excelent api function to get open positions, but currently we have no good way to display positions that have been closed / historical positions.

This is important information too see what you have done good and what have gone bad in your algorithm.

I know about three ways to solve this, but none of them are ideal combied with having the excact same output as open positions for closed positions:
1. Have a local database combined with using "client_order_id" and only submit orders (not close positions function because then you loose track)
2. Parse all account activities ascending from the beginning to the end then loop them and create new "position" element when quantity goes to 0.
3. Parse all orders, it's possible but better to parse all account activities since it's contains side "sell_short" when starting a short position.

It would have been much easier to get this directly from Alpaca.

Example on what that output could have contained (almost same as i posted in Slack):
[symbol] --ticker
[side] --long/short
[openOrders] --varchar with a array of the 3 order id's, also used for counting the times it have bought/sell orders
[openAmount] --sum quantity, so if i buy/sell 100 stocks three times it have 300
[openPriceAvg] --average price of the 3 orders
[openPriceSum] --just price * amount
[openFeeSum] --order object by alpaca dont contain fee, but for Live accounts it could have been added after midnight
[openFirstDate] --date of the first order that opened the position
[openLastDate] --if only one order it has the date of the first order, if multiple it has the last
[.....] --all the same columns as "open" except for being named close (closeAmount etc.)
[statistics] --json object containing lowestPrice and date, highestprice, percentage change etc. (these data are being updaded every minute after the position is opened if higher/lower)
[profitUSD] --updated when closing the position
[profitPc] --updated when closing the position

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.