Skip to content

Commit

Permalink
Merge branch 'main' into samtin0x/update-v2-client-readme
Browse files Browse the repository at this point in the history
  • Loading branch information
samtin0x committed Jun 24, 2024
2 parents f1628ae + 401c77c commit 4a358b7
Show file tree
Hide file tree
Showing 10 changed files with 836 additions and 55 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
v4-client-cpp/ @asnefedovv @dydxprotocol/eng
v4-client-py/ @kaloureyes3 @dydxprotocol/eng
v4-client-py-v2/ @samtin0x @therustmonk @dydxprotocol/eng
v4-client-py-v2/ @samtin0x @therustmonk @piwonskp @dydxprotocol/eng

* @dydxprotocol/eng
76 changes: 49 additions & 27 deletions .github/workflows/py-lint-test.yml
Original file line number Diff line number Diff line change
@@ -1,53 +1,75 @@
name: "[v4-client-py] Lint, Test"
name: "[v4-client-py-v2] Lint, Test"

on: # yamllint disable-line rule:truthy
pull_request:
paths:
- 'v4-client-py/**'
- 'v4-client-py-v2/**'
push:
paths:
- 'v4-client-py/**'
- 'v4-client-py-v2/**'
branches:
- main
- "release/*"

jobs:
# lint:
# runs-on: ubuntu-latest
# defaults:
# run:
# working-directory: ./v4-client-py
# steps:
# - name: Check out repository code
# uses: actions/checkout@v3

# - name: Set up Python 3.11
# uses: actions/setup-python@v4
# with:
# python-version: 3.11

# - name: Install Dependencies
# run: pip install -r requirements-lint.txt

# - name: Lint
# run: flake8
lint:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./v4-client-py-v2
steps:
- name: Check out repository code
uses: actions/checkout@v3

- name: Set up Python 3.12
uses: actions/setup-python@v4
with:
python-version: 3.12

- name: Cache poetry dependencies
uses: actions/cache@v3
with:
path: ~/.cache/pypoetry
key: ${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }}
restore-keys: |
${{ runner.os }}-poetry-
- name: Install poetry
run: pip install poetry

- name: Install Dependencies
run: poetry install

- name: Lint
run: poetry run black --check ./dydx_v4_client ./tests ./examples

test:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./v4-client-py
working-directory: ./v4-client-py-v2
steps:
- name: Check out repository code
uses: actions/checkout@v3

- name: Set up Python 3.11
- name: Set up Python 3.12
uses: actions/setup-python@v4
with:
python-version: 3.11
python-version: 3.12

- name: Cache poetry dependencies
uses: actions/cache@v3
with:
path: ~/.cache/pypoetry
key: ${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }}
restore-keys: |
${{ runner.os }}-poetry-
- name: Install poetry
run: pip install poetry

- name: Install Dependencies
run: sudo pip install -r requirements-test.txt
run: poetry install

- name: Run pytest
run: pytest
run: poetry run pytest
28 changes: 18 additions & 10 deletions .github/workflows/py-publish.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: "[v4-client-py] Publish to PyPI"
name: "[v4-client-py-v2] Publish to PyPI"

on: # yamllint disable-line rule:truthy
push:
paths:
- 'v4-client-py/**'
- 'v4-client-py-v2/**'
branches:
- main

Expand All @@ -13,21 +13,29 @@ jobs:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./v4-client-py
working-directory: ./v4-client-py-v2
steps:
- name: Check out repository code
uses: actions/checkout@v3

- name: Set up Python 3.11
- name: Set up Python 3.12
uses: actions/setup-python@v4
with:
python-version: 3.11
python-version: 3.12

- name: Install Dependencies
run: pip install -r requirements-publish.txt
- name: Cache poetry dependencies
uses: actions/cache@v3
with:
path: ~/.cache/pypoetry
key: ${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }}
restore-keys: |
${{ runner.os }}-poetry-
- name: Install Poetry dependencies
run: poetry install --no-root
- name: Install poetry
run: pip install poetry

- name: Install Dependencies
run: poetry install

- name: Build package
run: poetry build
Expand All @@ -37,4 +45,4 @@ jobs:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
run: |
twine upload -r pypi dist/*
poetry run twine upload -r pypi dist/*
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@
## v4-client-js
The dYdX Chain Client Typescript client is used for placing transactions and querying the dYdX chain.

## v4-client-py
Python client for dYdX Chain. Huge thanks to [kaloureyes3](https://github.com/kaloureyes3/v4-clients) for helping us
maintain this!

The library is currently tested against Python versions 3.9, and 3.11.
## v4-client-py-v2
Python client for dYdX Chain. Developed and maintained by the Nethermind team.
- [Saul M.](https://github.com/samtin0x)
- [Piotr P.](https://github.com/piwonskp)

## v4-client-cpp (Third Party Client)
To pull the latest C++ client, run `git submodule update --init --recursive`
Expand Down
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
2 changes: 1 addition & 1 deletion v4-client-js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dydxprotocol/v4-client-js",
"version": "1.1.22",
"version": "1.1.23",
"description": "General client library for the new dYdX system (v4 decentralized)",
"main": "build/src/index.js",
"scripts": {
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
2 changes: 1 addition & 1 deletion v4-client-py-v2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<div align="center">

### 📘 [Documentation](https://docs.dydx.exchange)
### 📘 [Documentation](https://docs.dydx.exchange)
### 📦 [Other implementations](https://github.com/dydxprotocol/v4-clients)

</div>
Expand Down
Loading

0 comments on commit 4a358b7

Please sign in to comment.