Add tax lot endpoints and order_sell_tax_lot (closes #1631)#1648
Open
DhruvaBansal00 wants to merge 1 commit into
Open
Add tax lot endpoints and order_sell_tax_lot (closes #1631)#1648DhruvaBansal00 wants to merge 1 commit into
DhruvaBansal00 wants to merge 1 commit into
Conversation
Wraps four Robinhood APIs for tax-lot management:
GET /tax_lots/open/{account_number}/{instrument_id}/
GET /tax_lots/order/{order_id}/selected/
GET /tax_lots/order/{order_id}/closed/
POST /orders/ with tax_lot_selection_type="custom" and a tax_lots list
New functions:
account.get_tax_lots(symbol, account_number=None, info=None)
account.get_selected_tax_lots(order_id, account_number=None, info=None)
account.get_closed_tax_lots(order_id, account_number=None, info=None)
orders.order_sell_tax_lot(symbol, lots, ...)
The three read functions are pure pass-through over filter_data, following
the existing get_open_stock_positions / get_dividends pattern.
order_sell_tax_lot builds the same payload that order() builds and adds
tax_lot_selection_type, tax_lots, and position_effect; it POSTs as JSON
since tax_lots is a nested list.
Tests added under TestTaxLots in test_robinhood.py for the three read
functions. No tests for order_sell_tax_lot per contributing.md (would
place real orders).
setup.py version bumped 3.4.0 -> 3.5.0.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #1631 by adding Robinhood tax-lot support: three read endpoints and the
sell-by-lot order variant.
New functions (exposed via
robin_stocks.robinhood)get_tax_lots(symbol, account_number=None, info=None)— open tax lots for a stockget_selected_tax_lots(order_id, account_number=None, info=None)— lots tagged for a sell-by-lot orderget_closed_tax_lots(order_id, account_number=None, info=None)— settled lots from a sell orderorder_sell_tax_lot(symbol, lots, account_number=None, timeInForce='gfd', extendedHours=False, jsonify=True, market_hours='regular_hours')— market sell that closes specific lots;lotsis a list of{'open_lot_id': ..., 'quantity': ...}dictsEndpoints wrapped
/tax_lots/open/{account_number}/{instrument_id}//tax_lots/order/{order_id}/selected//tax_lots/order/{order_id}/closed//orders/withtax_lot_selection_type: "custom"+tax_lots: [...]+position_effect: "close"The sell-by-lot order uses the same
/orders/endpoint asorder(), just with three extra payload fields. Posted as JSON (the existingorder()uses form-encoding, but the nestedtax_lotslist needs JSON).Conventions followed
The three read functions are pure pass-through using
request_get(url, 'pagination', payload)+filter_data, matchingget_open_stock_positions,get_dividends, etc. No data enrichment, no cross-instrument helpers.get_tax_lotsrounds thepricequery param viaround_price()— Robinhood rejects 6-decimal precision (rawget_latest_priceoutput) with HTTP 400, so the rounding is necessary.Tests
TestTaxLotsintests/test_robinhood.py:test_get_tax_lots_for_held_position— picks a held symbol fromget_open_stock_positions()and asserts the full lot schema (all 14 keys documented in the docstring)test_get_tax_lots_unknown_symbol— fake ticker →[None]test_get_selected_tax_lots_returns_list— smoketest_get_closed_tax_lots_returns_list— smokeNo tests for
order_sell_tax_lotper the contributing guide's no-real-orders rule.Verified against a live account
End-to-end: read paths returned correct schemas and paginated cleanly across many pages;
order_sell_tax_lotplaced a sell that Robinhood queued withtax_lot_selection_type: "custom"echoed back in the response.Contributing checklist
__init__.pyupdated to import new functionssetup.pyversion bumped3.4.0→3.5.0(feature; YY incremented, ZZ zeroed)