Add support for dividend, deposit, withdrawal, and interest trade types to Trades API (#1761)

* Update trades api with support for additional types

* rubocop fixes

* fix missing amount validation for interest type

* define missing schema reference

* fix test api_headers to use display_key per guidelines

* expand test coverage

* replaced duplicate JSON response blocks with helper method

* Add DB assertions to linked transfer test and fix invalid date test

* update brakeman.ignore fingerpint for refactored code

* Update the Brakeman ignore note to document validation for newly permitted keys

* fix API key auth in Minitest test to follow correct pattern

* update required in trades rswag spec to match the minimum fields that apply to all types

* extract dividend handling from build_investment_trade_params to dedicated method

* adjust response format to use the existing jbuilder views for Transfers and Transactions

* normalize type before passing to create form

* validate amount as a positive numeric value + tests

* rubocop fixes

* Add missing Trades API test coverage and docs

- Add Minitest tests for withdrawal (422, transfer linking), interest
  (explicit ticker), and dividend update
- Add rswag 401/403/404/422 response docs for create, update, destroy
- Regenerate docs/api/openapi.yaml

* Update Security.find line reference in brakeman.ignore note

* Mark TransactionResponse account_type as nullable in rswag docs
This commit is contained in:
thebandit
2026-06-13 05:55:16 -04:00
committed by GitHub
parent f7c633ef20
commit 64b4c0fee4
8 changed files with 1349 additions and 31 deletions

View File

@@ -1676,6 +1676,46 @@ components:
properties:
message:
type: string
TransactionResponse:
type: object
required:
- id
- date
- amount
- currency
- name
- entryable_type
- account
properties:
id:
type: string
format: uuid
date:
type: string
format: date
amount:
type: string
currency:
type: string
name:
type: string
entryable_type:
type: string
account:
type: object
required:
- id
- name
- account_type
properties:
id:
type: string
format: uuid
name:
type: string
account_type:
type: string
nullable: true
ImportConfiguration:
type: object
properties:
@@ -6864,13 +6904,25 @@ paths:
parameters: []
responses:
'201':
description: trade created
description: interest created
content:
application/json:
schema:
"$ref": "#/components/schemas/Trade"
"$ref": "#/components/schemas/TransactionResponse"
'403':
description: forbidden - api key missing read_write scope
content:
application/json:
schema:
"$ref": "#/components/schemas/ErrorResponse"
'401':
description: unauthorized - missing api key
content:
application/json:
schema:
"$ref": "#/components/schemas/ErrorResponse"
'422':
description: validation error - missing security identifier
description: deposit without amount returns error
content:
application/json:
schema:
@@ -6900,15 +6952,23 @@ paths:
description: Trade date (required)
qty:
type: number
description: Quantity (required)
description: Quantity (required for buy/sell)
price:
type: number
description: Price (required)
description: Price (required for buy/sell)
amount:
type: number
description: Amount (required for dividend, deposit, withdrawal,
interest)
type:
type: string
enum:
- buy
- sell
- dividend
- deposit
- withdrawal
- interest
description: Trade type (required)
security_id:
type: string
@@ -6931,11 +6991,13 @@ paths:
type: string
format: uuid
description: Category ID
transfer_account_id:
type: string
format: uuid
description: Destination/source account ID for linked transfers
required:
- account_id
- date
- qty
- price
- type
required:
- trade
@@ -6987,6 +7049,18 @@ paths:
application/json:
schema:
"$ref": "#/components/schemas/Trade"
'401':
description: unauthorized
content:
application/json:
schema:
"$ref": "#/components/schemas/ErrorResponse"
'403':
description: forbidden - api key missing read_write scope
content:
application/json:
schema:
"$ref": "#/components/schemas/ErrorResponse"
'404':
description: trade not found
content:
@@ -7014,6 +7088,10 @@ paths:
enum:
- buy
- sell
- dividend
- deposit
- withdrawal
- interest
nature:
type: string
enum:
@@ -7044,6 +7122,18 @@ paths:
application/json:
schema:
"$ref": "#/components/schemas/DeleteResponse"
'401':
description: unauthorized
content:
application/json:
schema:
"$ref": "#/components/schemas/ErrorResponse"
'403':
description: forbidden - api key missing read_write scope
content:
application/json:
schema:
"$ref": "#/components/schemas/ErrorResponse"
'404':
description: trade not found
content: