trading_agent.terminal.formatter
¶
Formats money, numbers, durations and times the way the web page does.
Money uses Indian digit grouping and the rupee sign, and times are India clock times.
Typical usage example:
formatter = Formatter() formatter.money(123456.7) # '₹1,23,456.70' formatter.elapsed_text(137) # '2m 17s'
Formatter
¶
Turns numbers and moments into short text for the terminal.
grouped
¶
Writes a number with Indian digit grouping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
float
|
The number. |
required |
decimals
|
int
|
How many digits to keep after the point. |
2
|
Returns:
| Type | Description |
|---|---|
str
|
Such as "1,23,456.70" for 123456.7, with a leading "-" when negative. |
Source code in src/trading_agent/terminal/formatter.py
money
¶
Formats an amount of money.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
amount
|
float | None
|
The amount in rupees, or None. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Such as "₹1,23,456.70", or "—" when missing. |
Source code in src/trading_agent/terminal/formatter.py
signed_money
¶
Formats a profit or loss with its sign.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
amount
|
float | None
|
The amount in rupees, or None. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Such as "+₹1,250.00" or "−₹300.00", or "—" when missing. |
Source code in src/trading_agent/terminal/formatter.py
price_text
¶
Formats a price.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
float | None
|
The price, or None. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Such as "2,945.50", or "—" when missing. |
Source code in src/trading_agent/terminal/formatter.py
number
¶
Formats a whole number from an event payload.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
object
|
The value, which may be missing or not a number. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Such as "12,345", or "?" when the value is not a number. |
Source code in src/trading_agent/terminal/formatter.py
moment
¶
Reads an ISO timestamp from the gateway.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
iso_text
|
str
|
Such as "2026-10-19T04:30:00+00:00". |
required |
Returns:
| Type | Description |
|---|---|
datetime | None
|
The moment in India time, or None when the text is not a timestamp. |
Source code in src/trading_agent/terminal/formatter.py
time
¶
Formats a moment as an India clock time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
iso_text
|
str
|
An ISO timestamp. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Such as "10:04:31", or the text itself when it is not a timestamp. |
Source code in src/trading_agent/terminal/formatter.py
day_time
¶
Formats a moment as a day and an India clock time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
iso_text
|
str
|
An ISO timestamp. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Such as "19 Oct, 10:04", or the text itself when it is not a timestamp. |
Source code in src/trading_agent/terminal/formatter.py
file_size
¶
Formats a file size.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size_bytes
|
int
|
The size in bytes. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Such as "340 KB" or "2.4 MB". |
Source code in src/trading_agent/terminal/formatter.py
token_count
¶
Formats a token count.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tokens
|
float
|
The count. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Such as "850", "12.3k" or "1M". |
Source code in src/trading_agent/terminal/formatter.py
share
¶
Formats a part of a whole as a percentage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
part
|
float
|
The part. |
required |
whole
|
float
|
The whole. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Such as "34.2%", or "—" when the whole is not positive. |
Source code in src/trading_agent/terminal/formatter.py
elapsed_text
¶
Formats a duration the way Claude Code shows it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seconds
|
int
|
The duration in seconds. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Such as "12s" or "2m 17s". |