Skip to content

Commit

Permalink
[TRA-107] Add parentSubaccountNumber endpoint for historical-pnl (#1476)
Browse files Browse the repository at this point in the history
Signed-off-by: Shrenuj Bansal <[email protected]>
  • Loading branch information
shrenujb authored May 8, 2024
1 parent 7e87c2e commit eadfc82
Show file tree
Hide file tree
Showing 5 changed files with 363 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -207,5 +207,65 @@ describe('pnlTicks-controller#V4', () => {
],
});
});

it('Get /historical-pnl/parentSubaccountNumber', async () => {
await testMocks.seedData();
const pnlTick2: PnlTicksCreateObject = {
...testConstants.defaultPnlTick,
subaccountId: testConstants.isolatedSubaccountId,
};
await Promise.all([
PnlTicksTable.create(testConstants.defaultPnlTick),
PnlTicksTable.create(pnlTick2),
]);

const parentSubaccountNumber: number = 0;
const response: request.Response = await sendRequest({
type: RequestMethod.GET,
path: `/v4/historical-pnl/parentSubaccountNumber?address=${testConstants.defaultAddress}` +
`&parentSubaccountNumber=${parentSubaccountNumber}`,
});

const expectedPnlTickResponse: any = {
// id and subaccountId don't matter
equity: (parseFloat(testConstants.defaultPnlTick.equity) +
parseFloat(pnlTick2.equity)).toString(),
totalPnl: (parseFloat(testConstants.defaultPnlTick.totalPnl) +
parseFloat(pnlTick2.totalPnl)).toString(),
netTransfers: (parseFloat(testConstants.defaultPnlTick.netTransfers) +
parseFloat(pnlTick2.netTransfers)).toString(),
createdAt: testConstants.defaultPnlTick.createdAt,
blockHeight: testConstants.defaultPnlTick.blockHeight,
blockTime: testConstants.defaultPnlTick.blockTime,
};

expect(response.body.historicalPnl).toEqual(
expect.arrayContaining([
expect.objectContaining({
...expectedPnlTickResponse,
}),
]),
);
});
});

it('Get /historical-pnl/parentSubaccountNumber with invalid subaccount number returns error', async () => {
const response: request.Response = await sendRequest({
type: RequestMethod.GET,
path: `/v4/historical-pnl/parentSubaccountNumber?address=${testConstants.defaultAddress}` +
'&parentSubaccountNumber=128',
expectedStatus: 400,
});

expect(response.body).toEqual({
errors: [
{
location: 'query',
msg: 'parentSubaccountNumber must be a non-negative integer less than 128',
param: 'parentSubaccountNumber',
value: '128',
},
],
});
});
});
85 changes: 85 additions & 0 deletions indexer/services/comlink/public/api-documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -1213,6 +1213,91 @@ fetch('https://dydx-testnet.imperator.co/v4/historical-pnl?address=string&subacc
This operation does not require authentication
</aside>

## GetHistoricalPnlForParentSubaccount

<a id="opIdGetHistoricalPnlForParentSubaccount"></a>

> Code samples
```python
import requests
headers = {
'Accept': 'application/json'
}

r = requests.get('https://dydx-testnet.imperator.co/v4/historical-pnl/parentSubaccount', params={
'address': 'string', 'parentSubaccountNumber': '0'
}, headers = headers)

print(r.json())

```

```javascript

const headers = {
'Accept':'application/json'
};

fetch('https://dydx-testnet.imperator.co/v4/historical-pnl/parentSubaccount?address=string&parentSubaccountNumber=0',
{
method: 'GET',

headers: headers
})
.then(function(res) {
return res.json();
}).then(function(body) {
console.log(body);
});

```

`GET /historical-pnl/parentSubaccount`

### Parameters

|Name|In|Type|Required|Description|
|---|---|---|---|---|
|address|query|string|true|none|
|parentSubaccountNumber|query|number(double)|true|none|
|limit|query|number(double)|false|none|
|createdBeforeOrAtHeight|query|number(double)|false|none|
|createdBeforeOrAt|query|[IsoString](#schemaisostring)|false|none|
|createdOnOrAfterHeight|query|number(double)|false|none|
|createdOnOrAfter|query|[IsoString](#schemaisostring)|false|none|

> Example responses
> 200 Response
```json
{
"historicalPnl": [
{
"id": "string",
"subaccountId": "string",
"equity": "string",
"totalPnl": "string",
"netTransfers": "string",
"createdAt": "string",
"blockHeight": "string",
"blockTime": "string"
}
]
}
```

### Responses

|Status|Meaning|Description|Schema|
|---|---|---|---|
|200|[OK](https://tools.ietf.org/html/rfc7231#section-6.3.1)|Ok|[HistoricalPnlResponse](#schemahistoricalpnlresponse)|

<aside class="success">
This operation does not require authentication
</aside>

## GetAggregations

<a id="opIdGetAggregations"></a>
Expand Down
80 changes: 80 additions & 0 deletions indexer/services/comlink/public/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1887,6 +1887,86 @@
]
}
},
"/historical-pnl/parentSubaccount": {
"get": {
"operationId": "GetHistoricalPnlForParentSubaccount",
"responses": {
"200": {
"description": "Ok",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HistoricalPnlResponse"
}
}
}
}
},
"security": [],
"parameters": [
{
"in": "query",
"name": "address",
"required": true,
"schema": {
"type": "string"
}
},
{
"in": "query",
"name": "parentSubaccountNumber",
"required": true,
"schema": {
"format": "double",
"type": "number"
}
},
{
"in": "query",
"name": "limit",
"required": false,
"schema": {
"format": "double",
"type": "number"
}
},
{
"in": "query",
"name": "createdBeforeOrAtHeight",
"required": false,
"schema": {
"format": "double",
"type": "number"
}
},
{
"in": "query",
"name": "createdBeforeOrAt",
"required": false,
"schema": {
"$ref": "#/components/schemas/IsoString"
}
},
{
"in": "query",
"name": "createdOnOrAfterHeight",
"required": false,
"schema": {
"format": "double",
"type": "number"
}
},
{
"in": "query",
"name": "createdOnOrAfter",
"required": false,
"schema": {
"$ref": "#/components/schemas/IsoString"
}
}
]
}
},
"/historicalTradingRewardAggregations/{address}": {
"get": {
"operationId": "GetAggregations",
Expand Down
Loading

0 comments on commit eadfc82

Please sign in to comment.