Skip to content

Commit

Permalink
feat: add parent subaccount queries (#179)
Browse files Browse the repository at this point in the history
* feat: ✨ add parentSubaccountNumber queries

added queries for fills and transfers.

* test: ✅ add ParentSubaccountNumber tests
  • Loading branch information
DavideSegullo authored Jun 20, 2024
1 parent f8ecd19 commit 37299eb
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 0 deletions.
71 changes: 71 additions & 0 deletions v4-client-js/__tests__/modules/client/AccountEndpoints.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ describe('IndexerClient', () => {
}
});

it('Transfers ParentSubaccountNumber', async () => {
const response = await client.account.getParentSubaccountNumberTransfers(DYDX_TEST_ADDRESS, 0);
expect(response).not.toBeNull();
const transfers = response.transfers;
expect(transfers).not.toBeNull();
if (transfers.length > 0) {
const transfer = transfers[0];
expect(transfer).not.toBeNull();
}
});

it('Transfers Pagination', async () => {
const response = await client.account.getSubaccountTransfers(
DYDX_TEST_ADDRESS,
Expand All @@ -80,6 +91,30 @@ describe('IndexerClient', () => {
expect(response.offset).toStrictEqual(0);
});

it('Transfers ParentSubaccountNumber Pagination', async () => {
const response = await client.account.getParentSubaccountNumberTransfers(
DYDX_TEST_ADDRESS,
0,
1,
undefined,
undefined,
1,
);
expect(response).not.toBeNull();
const transfers = response.transfers;

expect(transfers).not.toBeNull();
if (transfers.length > 0) {
const transfer = transfers[0];
expect(transfer).not.toBeNull();

expect(response.totalResults).toBeGreaterThanOrEqual(1);
}

expect(response.pageSize).toStrictEqual(1);
expect(response.offset).toStrictEqual(0);
});

it('Orders', async () => {
const response = await client.account.getSubaccountOrders(DYDX_TEST_ADDRESS, 0);
expect(response).not.toBeNull();
Expand All @@ -102,6 +137,17 @@ describe('IndexerClient', () => {
}
});

it('Fills ParentSubaccountNumber', async () => {
const response = await client.account.getParentSubaccountNumberFills(DYDX_TEST_ADDRESS, 0);
expect(response).not.toBeNull();
const fills = response.fills;
expect(fills).not.toBeNull();
if (fills.length > 0) {
const fill = fills[0];
expect(fill).not.toBeNull();
}
});

it('Fills Pagination', async () => {
const response = await client.account.getSubaccountFills(
DYDX_TEST_ADDRESS,
Expand All @@ -127,6 +173,31 @@ describe('IndexerClient', () => {
expect(response.offset).toStrictEqual(0);
});

it('Fills ParentSubaccountNumber Pagination', async () => {
const response = await client.account.getParentSubaccountNumberFills(
DYDX_TEST_ADDRESS,
0,
undefined,
undefined,
1,
undefined,
undefined,
1,
);

expect(response).not.toBeNull();
const fills = response.fills;
expect(fills).not.toBeNull();
if (fills.length > 0) {
const fill = fills[0];
expect(fill).not.toBeNull();
expect(response.totalResults).toBeGreaterThanOrEqual(1);
}

expect(response.pageSize).toStrictEqual(1);
expect(response.offset).toStrictEqual(0);
});

it('Historical PNL', async () => {
const response = await client.account.getSubaccountHistoricalPNLs(DYDX_TEST_ADDRESS, 0);
expect(response).not.toBeNull();
Expand Down
42 changes: 42 additions & 0 deletions v4-client-js/src/clients/modules/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,25 @@ export default class AccountClient extends RestClient {
});
}

async getParentSubaccountNumberTransfers(
address: string,
parentSubaccountNumber: number,
limit?: number | null,
createdBeforeOrAtHeight?: number | null,
createdBeforeOrAt?: string | null,
page?: number | null,
): Promise<Data> {
const uri = '/v4/transfers/parentSubaccountNumber';
return this.get(uri, {
address,
parentSubaccountNumber,
limit,
createdBeforeOrAtHeight,
createdBeforeOrAt,
page,
});
}

async getSubaccountOrders(
address: string,
subaccountNumber: number,
Expand Down Expand Up @@ -130,6 +149,29 @@ export default class AccountClient extends RestClient {
});
}

async getParentSubaccountNumberFills(
address: string,
parentSubaccountNumber: number,
ticker?: string | null,
tickerType: TickerType = TickerType.PERPETUAL,
limit?: number | null,
createdBeforeOrAtHeight?: number | null,
createdBeforeOrAt?: string | null,
page?: number | null,
): Promise<Data> {
const uri = '/v4/fills/parentSubaccountNumber';
return this.get(uri, {
address,
parentSubaccountNumber,
ticker,
tickerType,
limit,
createdBeforeOrAtHeight,
createdBeforeOrAt,
page,
});
}

async getSubaccountHistoricalPNLs(
address: string,
subaccountNumber: number,
Expand Down

0 comments on commit 37299eb

Please sign in to comment.