Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Balance] fetch historical balance #147

Merged
merged 20 commits into from
Aug 12, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix format
xinyu-li-cb committed Aug 12, 2024
commit 228d5a9a4c30a2a22f81d65990d4752f9e7db6db
17 changes: 9 additions & 8 deletions src/coinbase/address.ts
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@
Amount,
StakeOptionsMode,
ListHistoricalBalancesResult,
ListHistoricalBalancesOptions
ListHistoricalBalancesOptions,
} from "./types";
import { formatDate, getWeekBackDate } from "./utils";
import { StakingRewardFormat } from "../client";
@@ -90,16 +90,17 @@
/**
* Returns the historical balances of the provided asset.
*
* @param assetId - The asset ID.
* @param limit - A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10.
* @param page - A cursor for pagination across multiple pages of results. Don\'t include this parameter on the first call. Use the next_page value returned in a previous response to request subsequent results.
* @param options - The options to list historical balances.
* @param options.assetId - The asset ID.
* @param options.limit - A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10.
* @param options.page - A cursor for pagination across multiple pages of results. Don\'t include this parameter on the first call. Use the next_page value returned in a previous response to request subsequent results.
* @returns The list of historical balance of the asset and next page token.
*/
public async listHistoricalBalances({
assetId: string,
limit?: number,
page?: string,
}: ListHistoricalBalancesOptions): Promise<ListHistoricalBalancesResult> {
assetId,
limit,
page,
}: ListHistoricalBalancesOptions) : Promise<ListHistoricalBalancesResult> {

Check failure on line 103 in src/coinbase/address.ts

GitHub Actions / lint

Delete `·`
const historyList: HistoricalBalance[] = [];

if (limit !== undefined) {
6 changes: 3 additions & 3 deletions src/coinbase/types.ts
Original file line number Diff line number Diff line change
@@ -798,10 +798,10 @@
* Options for listing historical balances of an address.
*/
export type ListHistoricalBalancesOptions = {
assetId: string,
limit?: number,
page?: string,
assetId: string;
limit?: number;
page?: string;
}

Check failure on line 804 in src/coinbase/types.ts

GitHub Actions / lint

Insert `;`

/**
* Result of ListHistoricalBalances.
13 changes: 10 additions & 3 deletions src/tests/address_test.ts
Original file line number Diff line number Diff line change
@@ -72,7 +72,9 @@ describe("Address", () => {
});

it("should return results with USDC historical balance", async () => {
const historicalBalancesResult = await address.listHistoricalBalances(Coinbase.assets.Usdc);
const historicalBalancesResult = await address.listHistoricalBalances({
assetId: Coinbase.assets.Usdc,
});
expect(historicalBalancesResult.historicalBalances.length).toEqual(2);
expect(historicalBalancesResult.historicalBalances[0].amount).toEqual(new Decimal(1));
expect(historicalBalancesResult.historicalBalances[1].amount).toEqual(new Decimal(5));
@@ -95,7 +97,9 @@ describe("Address", () => {
has_more: false,
next_page: "",
});
const historicalBalancesResult = await address.listHistoricalBalances(Coinbase.assets.Usdc);
const historicalBalancesResult = await address.listHistoricalBalances({
assetId: Coinbase.assets.Usdc,
});
expect(historicalBalancesResult.historicalBalances.length).toEqual(0);
expect(
Coinbase.apiClients.externalAddress!.listAddressHistoricalBalance,
@@ -128,7 +132,10 @@ describe("Address", () => {
next_page: "next page",
});

const historicalBalancesResult = await address.listHistoricalBalances(Coinbase.assets.Usdc, 1);
const historicalBalancesResult = await address.listHistoricalBalances({
assetId: Coinbase.assets.Usdc,
limit: 1
});
expect(historicalBalancesResult.historicalBalances.length).toEqual(1);
expect(historicalBalancesResult.historicalBalances[0].amount).toEqual(new Decimal(5));
expect(