Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
245 changes: 245 additions & 0 deletions docs/Document the Data Models.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,245 @@

# Data Models

This document describes the data models used within the application. Understanding these models is crucial for backend developers and database administrators to effectively work with the application's data. This includes the database schema and the data structures used in API requests and responses.

## Target Audience

* Backend Developers
* Database Administrators

## Data Models

This section provides an overview of the key data models used in the application.

### Database Schema

This section details the database schema, including tables, columns, relationships, data types, and constraints.

#### `documents` Table

*(This table is not explicitly defined in the provided OpenAPI spec, so a placeholder is used. Replace with actual schema details.)*

This table stores information about documents.

| Column Name | Data Type | Constraints | Description |
| ----------- | --------- | ----------- | ----------- |
| `id` | `INTEGER` | `PRIMARY KEY`, `AUTOINCREMENT` | Unique identifier for the document. |
| `title` | `VARCHAR(255)` | `NOT NULL` | Title of the document. |
| `created_at` | `TIMESTAMP` | `NOT NULL` | Timestamp indicating when the document was created. |
| `updated_at` | `TIMESTAMP` | | Timestamp indicating when the document was last updated. |

#### `document_sections` Table

*(This table is not explicitly defined in the provided OpenAPI spec, so a placeholder is used. Replace with actual schema details.)*

This table stores information about sections within a document.

| Column Name | Data Type | Constraints | Description |
| ----------- | --------- | ----------- | ----------- |
| `id` | `INTEGER` | `PRIMARY KEY`, `AUTOINCREMENT` | Unique identifier for the section. |
| `document_id` | `INTEGER` | `NOT NULL`, `FOREIGN KEY references documents(id)` | Foreign key referencing the `documents` table. |
| `title` | `VARCHAR(255)` | `NOT NULL` | Title of the section. |
| `content` | `TEXT` | | Content of the section. |
| `order` | `INTEGER` | `NOT NULL` | Order of the section within the document. |

#### `storage.objects` Table

*(This table is not explicitly defined in the provided OpenAPI spec, so a placeholder is used. Replace with actual schema details.)*

This table stores information about objects stored in a storage system (e.g., cloud storage).

| Column Name | Data Type | Constraints | Description |
| ----------- | --------- | ----------- | ----------- |
| `id` | `UUID` | `PRIMARY KEY` | Unique identifier for the object. |
| `bucket_id` | `VARCHAR(255)` | `NOT NULL` | Identifier of the bucket where the object is stored. |
| `name` | `VARCHAR(255)` | `NOT NULL` | Name of the object. |
| `size` | `BIGINT` | | Size of the object in bytes. |
| `created_at` | `TIMESTAMP` | `NOT NULL` | Timestamp indicating when the object was created. |

### API Data Structures

This section describes the data structures used in API requests and responses. The following examples are derived from the provided OpenAPI specification.

#### OrderRequest

This schema defines the structure for placing an order.

```json
{
"dhanClientId": "string",
"correlationId": "string",
"transactionType": "BUY",
"exchangeSegment": "NSE_EQ",
"productType": "CNC",
"orderType": "LIMIT",
"validity": "DAY",
"tradingSymbol": "string",
"securityId": "string",
"quantity": 100,
"disclosedQuantity": 50,
"price": 100.50,
"triggerPrice": 99.00,
"afterMarketOrder": false,
"amoTime": "OPEN",
"boProfitValue": 102.00,
"boStopLossValue": 98.00,
"drvExpiryDate": "2024-12-31",
"drvOptionType": "CALL",
"drvStrikePrice": 15000.00
}
```

**Fields:**

* `dhanClientId`: User specific identification generated by Dhan (string).
* `correlationId`: The user/partner generated id for tracking back (string).
* `transactionType`: Signifies the type of transaction wether it's BUY or SELL (string, enum: `BUY`, `SELL`).
* `exchangeSegment`: Exchange and segment (string, enum: `NSE_EQ`, `NSE_FNO`, `NSE_CURRENCY`, `BSE_EQ`, `BSE_FNO`, `BSE_CURRENCY`, `MCX_COMM`).
* `productType`: Product type (string, enum: `CNC`, `INTRADAY`, `MARGIN`, `MTF`, `CO`, `BO`).
* `orderType`: Order type (string, enum: `LIMIT`, `MARKET`, `STOP_LOSS`, `STOP_LOSS_MARKET`).
* `validity`: Order validity (string, enum: `DAY`, `IOC`, `GTC`, `GTD`).
* `tradingSymbol`: Exchange standard trading symbol (string).
* `securityId`: Exchange standard identification for each scrip (string).
* `quantity`: Number of shares for the order (integer).
* `disclosedQuantity`: Number shares visible in the market depth (integer).
* `price`: Price at which the order is requested to execute (number).
* `triggerPrice`: Price at which the order is triggered (number).
* `afterMarketOrder`: Flag to inform that the order placed is After Market Order (boolean).
* `amoTime`: Flag to inform after what time AMO is pumped (string, enum: `OPEN`, `OPEN_30`, `OPEN_60`).
* `boProfitValue`: Bracket order Target price (number).
* `boStopLossValue`: Bracket Order/Cover Order Stop Loss Price (number).
* `drvExpiryDate`: For F&O, expiry date of contract (string).
* `drvOptionType`: For Options, type CALL or PUT (string, enum: `CALL`, `PUT`, `NA`).
* `drvStrikePrice`: For Options, Strike Price (number).

#### OrderResponse

This schema defines the structure for the order response.

```json
{
"dhanClientId": "string",
"orderId": "string",
"exchangeOrderId": "string",
"correlationId": "string",
"orderStatus": "PENDING",
"transactionType": "BUY",
"exchangeSegment": "NSE_EQ",
"productType": "CNC",
"orderType": "LIMIT",
"validity": "DAY",
"tradingSymbol": "string",
"securityId": "string",
"quantity": 100,
"disclosedQuantity": 50,
"price": 100.50,
"triggerPrice": 99.00,
"afterMarketOrder": false,
"boProfitValue": 102.00,
"boStopLossValue": 98.00,
"legName": "NA",
"createTime": "string",
"updateTime": "string",
"exchangeTime": "string",
"drvExpiryDate": "2024-12-31",
"drvOptionType": "CALL",
"drvStrikePrice": 15000.00,
"omsErrorCode": "string",
"omsErrorDescription": "string",
"filled_qty": 0,
"algoId": "string"
}
```

**Fields:**

* `dhanClientId`: User specific identification generated by Dhan (string).
* `orderId`: Order specific identification generated by Dhan (string).
* `exchangeOrderId`: Order specific identification generated by Exchange (string).
* `correlationId`: The user/partner generated id for tracking back (string).
* `orderStatus`: Order status (string, enum: `TRANSIT`, `PENDING`, `REJECTED`, `CANCELLED`, `TRADED`, `EXPIRED`).
* `transactionType`: Signifies the type of transaction wether it's BUY or SELL (string, enum: `BUY`, `SELL`).
* `exchangeSegment`: Exchange and segment (string, enum: `NSE_EQ`, `NSE_FNO`, `NSE_CURRENCY`, `BSE_EQ`, `BSE_FNO`, `BSE_CURRENCY`, `MCX_COMM`).
* `productType`: Product type (string, enum: `CNC`, `INTRADAY`, `MARGIN`, `MTF`, `CO`, `BO`).
* `orderType`: Order type (string, enum: `LIMIT`, `MARKET`, `STOP_LOSS`, `STOP_LOSS_MARKET`).
* `validity`: Order validity (string, enum: `DAY`, `IOC`, `GTC`, `GTD`).
* `tradingSymbol`: Exchange standard trading symbol (string).
* `securityId`: Exchange standard identification for each scrip (string).
* `quantity`: Number of shares for the order (integer).
* `disclosedQuantity`: Number shares visible in the market depth (integer).
* `price`: Price at which the order is requested to execute (number).
* `triggerPrice`: Price at which the order is triggered (number).
* `afterMarketOrder`: Flag to inform that the order placed is After Market Order (boolean).
* `boProfitValue`: Bracket order Target price (number).
* `boStopLossValue`: Bracket Order/Cover Order Stop Loss Price (number).
* `legName`: (string, enum: `ENTRY_LEG`, `STOP_LOSS_LEG`, `TARGET_LEG`, `NA`).
* `createTime`: Time at which the record is created (string).
* `updateTime`: Time at which the record is updated (string).
* `exchangeTime`: Time at which order reached at exchange end (string).
* `drvExpiryDate`: For F&O, expiry date of contract (string).
* `drvOptionType`: For Options, type CALL or PUT (string, enum: `CALL`, `PUT`, `NA`).
* `drvStrikePrice`: For Options, Strike Price (number).
* `omsErrorCode`: When order is rejected or failed, omsErrorCode would be populated (string).
* `omsErrorDescription`: When order is rejected or failed, omsErrorDescription would be populated (string).
* `filled_qty`: Filled Quantity (integer).
* `algoId`: Algo_ID (string).

#### PositionConversionRequest

This schema defines the structure for converting a position.

```json
{
"dhanClientId": "string",
"fromProductType": "CNC",
"exchangeSegment": "NSE_EQ",
"positionType": "LONG",
"securityId": "string",
"tradingSymbol": "string",
"convertQty": 10,
"toProductType": "INTRADAY"
}
```

**Fields:**

* `dhanClientId`: User specific identification generated by Dhan (string).
* `fromProductType`: (string, enum: `CNC`, `INTRADAY`, `MARGIN`, `MTF`, `CO`, `BO`).
* `exchangeSegment`: Exchange and segment (string, enum: `NSE_EQ`, `NSE_FNO`, `NSE_CURRENCY`, `BSE_EQ`, `BSE_FNO`, `BSE_CURRENCY`, `MCX_COMM`).
* `positionType`: (string, enum: `LONG`, `SHORT`, `CLOSED`).
* `securityId`: Exchange standard identification for each scrip (string).
* `tradingSymbol`: Exchange standard trading symbol (string).
* `convertQty`: Number of shares for the conversion (integer).
* `toProductType`: (string, enum: `CNC`, `INTRADAY`, `MARGIN`, `MTF`, `CO`, `BO`).

#### Enums

Many of the schemas use enums. Here's a consolidated list of the enums and their meanings:

* **TransactionType**: `BUY`, `SELL`
* **ExchangeSegment**: `NSE_EQ`, `NSE_FNO`, `NSE_CURRENCY`, `BSE_EQ`, `BSE_FNO`, `BSE_CURRENCY`, `MCX_COMM`, `IDX_I`
* **ProductType**: `CNC`, `INTRADAY`, `MARGIN`, `MTF`, `CO`, `BO`
* **OrderType**: `LIMIT`, `MARKET`, `STOP_LOSS`, `STOP_LOSS_MARKET`
* **Validity**: `DAY`, `IOC`, `GTC`, `GTD`
* **OrderStatus**: `TRANSIT`, `PENDING`, `REJECTED`, `CANCELLED`, `TRADED`, `EXPIRED`
* **PositionType**: `LONG`, `SHORT`, `CLOSED`
* **DrvOptionType**: `CALL`, `PUT`, `NA`
* **AmoTime**: `OPEN`, `OPEN_30`, `OPEN_60`
* **KillSwitchStatus**: `ACTIVATE`, `DEACTIVATE`
* **Exchange**: `NSE`, `BSE`, `MCX`, `ALL`
* **Segment**: `EQ`, `COMM`, `FNO`, `CURR`
* **Instrument**: `INDEX`, `FUTIDX`, `OPTIDX`, `EQUITY`, `FUTSTK`, `OPTSTK`, `FUTCOM`, `OPTFUT`, `FUTCUR`, `OPTCUR`
* **LegName**: `ENTRY_LEG`, `STOP_LOSS_LEG`, `TARGET_LEG`, `NA`

### Schema Diagrams

*(This section is a placeholder. Ideally, include visual schema diagrams here, generated from the database schema. Tools like dbdiagram.io or similar can be used to create these diagrams.)*

[Placeholder for Database Schema Diagram]

### Data Dictionaries

*(This section is a placeholder. A more comprehensive data dictionary, perhaps exported from the database itself, would be beneficial here.)*

[Placeholder for Comprehensive Data Dictionary]