ores.trading.trade_link
Table of Contents
One relation between two trades, with a direction, a type and nothing else. A close-out answers a live trade, a roll replaces one, an exercise produces one. The link holds no cash flow, no amount and no state: the trade id type pattern of a typed reference applies here as well, with the type carrying the role of each end.
The row is keyed by its two ends and its type, and the type is a trade link type code. It records the trade activity that made it, because a link is created by an amendment like anything else, and it copies the party of the from end so row level security can see it on every row.
A process that created a link records the run on the trade group, not here: a link holds nothing and stands alone.
1. Flags
2. Columns
2.1. from_trade_id
The trade the link starts at: the original a close-out ends, the transferred position a novation moves, the rolled trade a roll replaces.
ctx.generate_uuid()
2.2. to_trade_id
The trade the link ends at: the closing trade, the new counterparty's trade, the replacement a roll books.
ctx.generate_uuid()
2.3. link_type
The reason the two trades are joined, from the trade link types.
std::string("Roll")
2.4. trade_activity_id
The activity that made the link.
ctx.generate_uuid()
3. SQL
3.1. Flags
3.2. Checks
A link joins two trades, so it cannot join one to itself.
| expression |
|---|
| "from_trade_id" <> "to_trade_id" |
3.3. Extra drops
drop function if exists ores_trading_validate_trade_link_fn;
4. Foreign keys
4.1. from_trade_id
A database foreign key: the anchor is immutable.
4.2. to_trade_id
A database foreign key: the anchor is immutable.
4.3. link_type
The type catalogue is system reference data.
4.4. trade_activity_id
The activity that made the link. A database foreign key: the activity is immutable.
#include "ores.trading.api/generators/trade_activity_generator.hpp" #include "ores.trading.core/repository/trade_activity_repository.hpp"
{
auto activity = ores::trading::generators::generate_synthetic_trade_activity(ctx);
activity.party_id = *party_ctx.party_id();
ores::trading::repository::trade_activity_repository().write(party_ctx, activity);
v.trade_activity_id = activity.id;
}
5. C++
5.1. Flags
5.2. Repository
5.3. Domain includes
#include <string> #include <boost/uuid/uuid.hpp>
5.4. Conventions
5.5. Table display
| column | header |
|---|---|
| from_trade_id | From Trade |
| to_trade_id | To Trade |
| link_type | Link Type |
| modified_by | Modified By |
| version | Version |
5.6. Custom repository methods
6. See also
- ores.trading — component group overview.