Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Transaction type + add Order Details function #7

Closed
wants to merge 7 commits into from
Closed

Update Transaction type + add Order Details function #7

wants to merge 7 commits into from

Conversation

ebarr006
Copy link

@ebarr006 ebarr006 commented Dec 15, 2022

Background

While working with the Transaction object, we noticed that E*Trade's List Transactions endpoint and Transaction Details endpoint return slightly different versions of that object.

  • The List endpoint returns Transactions with lower-cased category, brokerage, and brokerage.product
  • The Details endpoint returns a Transaction with capitalized Category, Brokerage, and Brokerage.Product.
  • See E*Trade docs sample responses.

Also, while not officially documented, there is an order details style endpoint that follows the same url pattern as the Transaction Details endpoint. Ex., /v1/accounts/{accountIdKey}/orders/{orderId}.json. I'd like to be able to access that endpoint through your project.

How did I Implement

Transaction type update:

  • Added TransactionBase and BrokerageBase interfaces
  • Extend the -Base interfaces with either capitalized or lower-cased keys, depending on the endpoint

List Order Details function

  • Added ListOrderDetailsRequest,ListOrderDetailsResponse, OrderEvents, and Event
  • Added listOrderDetails({ accountIdKey, orderId }: ListOrderDetailsRequest): Promise<ListOrderDetailsResponse>
  • The raw response from https://api.etrade.com/v1/accounts/{accountIdKey}/orders/{orderId}.json looks like this
{
    "OrdersResponse": {
        "Order": [
            {
                "orderId": 40,
                "orderType": "EQ",
                "OrderDetail": [
                    {
                        "placedTime": 1671027410804,
                        "executedTime": 1671028202948,
                        "orderValue": 145.4665,
                        "status": "EXECUTED",
                        "orderTerm": "GOOD_UNTIL_CANCEL",
                        "priceType": "MARKET",
                        "limitPrice": 0,
                        "stopPrice": 0,
                        "marketSession": "REGULAR",
                        "allOrNone": false,
                        "netPrice": 0,
                        "netBid": 0,
                        "netAsk": 0,
                        "gcd": 0,
                        "ratio": "",
                        "Instrument": [
                            {
                                "symbolDescription": "APPLE INC COM",
                                "orderAction": "SELL",
                                "quantityType": "QUANTITY",
                                "orderedQuantity": 1,
                                "filledQuantity": 1.0,
                                "averageExecutionPrice": 145.32,
                                "estimatedCommission": 0.0001,
                                "estimatedFees": 0.0033,
                                "Product": {
                                    "symbol": "AAPL",
                                    "securityType": "EQ"
                                }
                            }
                        ]
                    }
                ],
                "Events": {
                    "Event": [
                        {
                            "name": "ORDER_PLACED",
                            "dateTime": 1671027410804,
                            "Instrument": [
                                {
                                    "symbolDescription": "APPLE INC COM",
                                    "orderAction": "SELL",
                                    "quantityType": "QUANTITY",
                                    "orderedQuantity": 1,
                                    "filledQuantity": 1.0,
                                    "averageExecutionPrice": 145.32,
                                    "estimatedCommission": 0.0001,
                                    "estimatedFees": 0.0033,
                                    "Product": {
                                        "symbol": "AAPL",
                                        "securityType": "EQ"
                                    }
                                }
                            ]
                        },
                        {
                            "name": "ORDER_EXECUTED",
                            "dateTime": 1671028202948,
                            "Instrument": [
                                {
                                    "symbolDescription": "APPLE INC COM",
                                    "orderAction": "SELL",
                                    "quantityType": "QUANTITY",
                                    "orderedQuantity": 1,
                                    "filledQuantity": 1.0,
                                    "averageExecutionPrice": 145.32,
                                    "estimatedCommission": 0.0001,
                                    "estimatedFees": 0.01,
                                    "Product": {
                                        "symbol": "AAPL",
                                        "securityType": "EQ"
                                    }
                                }
                            ]
                        }
                    ]
                }
            }
        ]
    }
}
  • After getting this response, only return OrdersResponse.Order[0]

Samples

const { orderId, orderType, OrderDetail } = await etrade.listOrderDetails({
   accountIdKey: <yourId>,
   orderId: 40
});
console.log(`${orderId}\n${orderType}\n${OrderDetail[0].orderValue}`);
40
EQ
145.4665   // matches result above

@ebarr006
Copy link
Author

@aldenquimby

@tflanagan
Copy link
Owner

@ebarr006 Thanks for the PR! Just wanted to confirm I saw this, but let you know I won't be near a computer until Tuesday next week.

Initial looks are good, but it looks like there are some minor indentation issues near TransactionBase

@ebarr006
Copy link
Author

@tflanagan no problem!

I think i fixed the indentation in my last commit, but we can review again on Tuesday.

@ebarr006 ebarr006 closed this by deleting the head repository Dec 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants