Skip to content

Add tax lot endpoints and order_sell_tax_lot (closes #1631)#1648

Open
DhruvaBansal00 wants to merge 1 commit into
jmfernandes:masterfrom
DhruvaBansal00:feature/tax-lots
Open

Add tax lot endpoints and order_sell_tax_lot (closes #1631)#1648
DhruvaBansal00 wants to merge 1 commit into
jmfernandes:masterfrom
DhruvaBansal00:feature/tax-lots

Conversation

@DhruvaBansal00

Copy link
Copy Markdown

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 stock
  • get_selected_tax_lots(order_id, account_number=None, info=None) — lots tagged for a sell-by-lot order
  • get_closed_tax_lots(order_id, account_number=None, info=None) — settled lots from a sell order
  • order_sell_tax_lot(symbol, lots, account_number=None, timeInForce='gfd', extendedHours=False, jsonify=True, market_hours='regular_hours') — market sell that closes specific lots; lots is a list of {'open_lot_id': ..., 'quantity': ...} dicts

Endpoints wrapped

Method Path
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" + tax_lots: [...] + position_effect: "close"

The sell-by-lot order uses the same /orders/ endpoint as order(), just with three extra payload fields. Posted as JSON (the existing order() uses form-encoding, but the nested tax_lots list needs JSON).

Conventions followed

The three read functions are pure pass-through using request_get(url, 'pagination', payload) + filter_data, matching get_open_stock_positions, get_dividends, etc. No data enrichment, no cross-instrument helpers.

get_tax_lots rounds the price query param via round_price() — Robinhood rejects 6-decimal precision (raw get_latest_price output) with HTTP 400, so the rounding is necessary.

Tests

TestTaxLots in tests/test_robinhood.py:

  • test_get_tax_lots_for_held_position — picks a held symbol from get_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 — smoke
  • test_get_closed_tax_lots_returns_list — smoke

No tests for order_sell_tax_lot per 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_lot placed a sell that Robinhood queued with tax_lot_selection_type: "custom" echoed back in the response.

Contributing checklist

  • Only new code with new docstrings — no grammar/doc-only changes, so a single code commit is appropriate
  • __init__.py updated to import new functions
  • setup.py version bumped 3.4.03.5.0 (feature; YY incremented, ZZ zeroed)
  • Tests added for new read functions

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>
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.

Feature Request: Tax Lot Selling Support

1 participant