aboutsummaryrefslogtreecommitdiffstats
path: root/sql/dawn.sql
diff options
context:
space:
mode:
Diffstat (limited to 'sql/dawn.sql')
-rw-r--r--sql/dawn.sql6
1 files changed, 5 insertions, 1 deletions
diff --git a/sql/dawn.sql b/sql/dawn.sql
index eb6b60cd..8535d659 100644
--- a/sql/dawn.sql
+++ b/sql/dawn.sql
@@ -309,6 +309,8 @@ CREATE TABLE cds(id serial primary key,
stale bool default true,
traded_level numeric(9, 5) NULL,
exercised_from text REFERENCES swaptions(dealid),
+ delta_id integer REFERENCES cds(id),
+ delta_alloc float,
CONSTRAINT tranche_check CHECK ((
swap_type IN ('CD_INDEX_TRANCHE', 'BESPOKE') AND
(orig_attach IS NOT NULL AND orig_detach IS NOT NULL AND clearing_facility IS NULL))
@@ -495,6 +497,8 @@ CREATE TABLE swaptions(id serial PRIMARY KEY,
cpty_id text,
globeop_id int,
full_globeop_id text GENERATED ALWAYS AS ('SWO'||lpad(cast(globeop_id as text), 6, '0')|| 'K00SCLMA') STORED,
+ delta_id int REFERENCES cds(id),
+ delta_alloc float
);
CREATE TRIGGER swaptions_dealid BEFORE INSERT ON swaptions
@@ -517,7 +521,7 @@ CREATE OR REPLACE FUNCTION update_account()
RETURNS TRIGGER
AS $$
BEGIN
-SELECT cash_account INTO STRICT NEW.cash_account FROM accounts2 LEFT JOIN account_counterparty ON accounts2.id=account_id WHERE trade_type=TG_ARGV[0] AND fund=NEW.fund AND account_counterparty.cp_code=NEW.cp_code;
+SELECT cash_account INTO STRICT NEW.cash_account FROM accounts2 LEFT JOIN account_counterparty ON accounts2.id=account_id WHERE trade_type=TG_ARGV[0] AND fund=NEW.fund AND account_counterparty.cp_code=NEW.cp_code AND active;
RETURN NEW;
END
$$ LANGUAGE plpgsql;