From d2a6a2bd2a14551c972beeef757977329721b142 Mon Sep 17 00:00:00 2001 From: Jiajia-Cui Date: Thu, 1 Aug 2024 16:20:33 +0100 Subject: [PATCH 1/2] feat: add position API --- protocol/0007-POSN-non_core_positions_api.md | 40 ++++++++++++++++++-- protocol/features.json | 22 +++++++++++ 2 files changed, 58 insertions(+), 4 deletions(-) diff --git a/protocol/0007-POSN-non_core_positions_api.md b/protocol/0007-POSN-non_core_positions_api.md index 741366623..f11595c9f 100644 --- a/protocol/0007-POSN-non_core_positions_api.md +++ b/protocol/0007-POSN-non_core_positions_api.md @@ -44,10 +44,25 @@ The API is expected to expose: ### Position -- Open volume (this is a core API) -- Unrealised P&L (method = averaged) -- Realised P&L (method = averaged) -- Open volume average entry price (method = averaged) +The following must be available for each market and for each key using the P&L method "averaged" (as opposed to FIFO): + +- Position volume (this is a core API). +- Position average entry price. +- Unrealised P&L. +- Realised P&L. +- Realised P&L since the last time the position changed from 0 or flipped sign. +- Realised P&L including fees. +- Realised P&L including fees since the last time the position changed from 0 or flipped sign. +- Realised P&L including funding. +- Realised P&L including funding since the last time the position changed from 0 or flipped sign. +- Realised P&L including both fees and funding. +- Realised P&L including both fees and funding since the last time the position changed from 0 or flipped sign. +- Taker fees paid. +- Taker fees paid since the last time the position changed from 0 or flipped sign. +- Maker fees received. +- Maker fees received since the last time the position changed from 0 or flipped sign. +- Funding total. +- Funding total since the last time the position changed from 0 or flipped sign. ### Trade @@ -58,10 +73,27 @@ The API is expected to expose: - When a party has never had a position, the realised PnL and unrealised PnL should be 0 (0007-POSN-009) - When a party has a non-zero position, and has not closed any part of it, only the unrealised PnL should be changed by increase in position or change of mark price while realised PnL should stay constant in absence of loss socialisation (0007-POSN-010) +- Unrealised P&L should be correct and accessible from API.(0007-POSN-020) - When a party has a position which gets (partially) closed-out, the unrealised PnL should reflect the change of position while the realised PnL reflect the closed-out position (0007-POSN-011) - During settlement, all the parties' position should become 0, unrealised PnL should become 0 and realised PnL should update based on settlement price (0007-POSN-012) - If a party is subject to loss socialisation (its MTM gains get scaled down) the loss amount (forgone profit) should get recorded in realised PnL(0007-POSN-013) - If a party is subject to loss socialisation, the profits that could not be paid out due to loss socialisation is logged as "loss socialisation amount" which is accessible from API (0007-POSN-014) +- Position volume should be accessible from API.(0007-POSN-018) +- Position average entry price should be accessible from API.(0007-POSN-019) +- When a party has a position which gets (partially) closed-out, realised P&L should be showing correct number and should be accessible from API.(0007-POSN-021) +- Realised P&L since the last time the position changed from 0 or flipped sign should be showing correct number and should be accessible from API.(0007-POSN-022) +- When a party has a position which gets (partially) closed-out, realised P&L including fees should be showing correct number and accessible from API.(0007-POSN-023) +- Realised P&L including fees since the last time the position changed from 0 or flipped sign should be showing correct number and accessible from API.(0007-POSN-024) +- When a party has a position which gets (partially) closed-out, realised P&L including funding should be showing correct number and accessible from API.(0007-POSN-025) +- Realised P&L including funding since the last time the position changed from 0 or flipped sign should be accessible from API.(0007-POSN-026) +- When a party has a position which gets (partially) closed-out, realised P&L including both fees and funding should be showing correct number and accessible from API.(0007-POSN-027) +- Realised P&L including both fees and funding since the last time the position changed from 0 or flipped sign should be showing correct number and accessible from API.(0007-POSN-028) +- Taker fees paid should be correct and accessible from API.(0007-POSN-029) +- Taker fees paid since the last time the position changed from 0 or flipped sign should be correct and accessible from AP.(0007-POSN-030) +- Maker fees received should be correct and accessible from API .(0007-POSN-031) +- Maker fees received since the last time the position changed from 0 or flipped sign should be correct and accessible from API .(0007-POSN-032) +- Funding total should be correct and accessible from API .(0007-POSN-033) +- Funding total since the last time the position changed from 0 or flipped sign should be correct and accessible from API.(0007-POSN-034) ## Definitions / glossary diff --git a/protocol/features.json b/protocol/features.json index f68d5b7af..a9f180c7c 100644 --- a/protocol/features.json +++ b/protocol/features.json @@ -212,6 +212,28 @@ "0080-SPOT-029" ] }, + "Position API": { + "milestone": "colosseo_II", + "acs": [ + "0007-POSN-018", + "0007-POSN-019", + "0007-POSN-020", + "0007-POSN-021", + "0007-POSN-022", + "0007-POSN-023", + "0007-POSN-024", + "0007-POSN-025", + "0007-POSN-026", + "0007-POSN-027", + "0007-POSN-028", + "0007-POSN-029", + "0007-POSN-030", + "0007-POSN-031", + "0007-POSN-032", + "0007-POSN-033", + "0007-POSN-034" + ] + }, "Unknown": { "milestone": "unknown", "acs": [] From 276430dcad6977e8d3842a3133f76da6c1602e40 Mon Sep 17 00:00:00 2001 From: Jiajia-Cui Date: Thu, 1 Aug 2024 16:31:02 +0100 Subject: [PATCH 2/2] chore: tidy up --- protocol/0007-POSN-non_core_positions_api.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/protocol/0007-POSN-non_core_positions_api.md b/protocol/0007-POSN-non_core_positions_api.md index f11595c9f..db164bcb1 100644 --- a/protocol/0007-POSN-non_core_positions_api.md +++ b/protocol/0007-POSN-non_core_positions_api.md @@ -84,15 +84,15 @@ The following must be available for each market and for each key using the P&L m - Realised P&L since the last time the position changed from 0 or flipped sign should be showing correct number and should be accessible from API.(0007-POSN-022) - When a party has a position which gets (partially) closed-out, realised P&L including fees should be showing correct number and accessible from API.(0007-POSN-023) - Realised P&L including fees since the last time the position changed from 0 or flipped sign should be showing correct number and accessible from API.(0007-POSN-024) -- When a party has a position which gets (partially) closed-out, realised P&L including funding should be showing correct number and accessible from API.(0007-POSN-025) -- Realised P&L including funding since the last time the position changed from 0 or flipped sign should be accessible from API.(0007-POSN-026) -- When a party has a position which gets (partially) closed-out, realised P&L including both fees and funding should be showing correct number and accessible from API.(0007-POSN-027) -- Realised P&L including both fees and funding since the last time the position changed from 0 or flipped sign should be showing correct number and accessible from API.(0007-POSN-028) +- When a party has a position which gets (partially) closed-out and the funding has happened, realised P&L including funding should be showing correct number and accessible from API.(0007-POSN-025) +- Realised P&L including funding since the last time the position changed from 0 or flipped sign and the funding has happened, should be accessible from API.(0007-POSN-026) +- When a party has a position which gets (partially) closed-out and the funding has happened, realised P&L including both fees and funding should be showing correct number and accessible from API.(0007-POSN-027) +- Realised P&L including both fees and funding since the last time the position changed from 0 or flipped sign and the funding has happened should be showing correct number and accessible from API.(0007-POSN-028) - Taker fees paid should be correct and accessible from API.(0007-POSN-029) - Taker fees paid since the last time the position changed from 0 or flipped sign should be correct and accessible from AP.(0007-POSN-030) -- Maker fees received should be correct and accessible from API .(0007-POSN-031) +- Maker fees received should be correct and accessible from API.(0007-POSN-031) - Maker fees received since the last time the position changed from 0 or flipped sign should be correct and accessible from API .(0007-POSN-032) -- Funding total should be correct and accessible from API .(0007-POSN-033) +- Funding total should be correct and accessible from API.(0007-POSN-033) - Funding total since the last time the position changed from 0 or flipped sign should be correct and accessible from API.(0007-POSN-034) ## Definitions / glossary