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

feat(): Added CBApp data endpoints #22

Merged
merged 2 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
123 changes: 123 additions & 0 deletions src/CBAppClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ import {
import {
CBAppAccount,
CBAppAddress,
CBAppCryptocurrency,
CBAppDepositWithdrawal,
CBAppFiatCurrency,
CBAppPagination,
CBAppTransaction,
} from './types/response/coinbase-app-client.js';
Expand Down Expand Up @@ -355,4 +357,125 @@ export class CBAppClient extends BaseRestClient {
`/v2/accounts/${params.accountId}/withdrawals/${params.withdrawalId}`,
);
}

/**
*
* DATA - Currencies Endpoints
*
*/

/**
* Get Fiat Currencies
*
* Lists known fiat currencies. Currency codes conform to the ISO 4217 standard where possible.
* Currencies with no representation in ISO 4217 may use a custom code.
*/
getFiatCurrencies(): Promise<{
data: CBAppFiatCurrency[];
}> {
return this.get('/v2/currencies');
}

/**
* Get Cryptocurrencies
*
* Lists known cryptocurrencies.
*/
getCryptocurrencies(): Promise<CBAppCryptocurrency[]> {
return this.get('/v2/currencies/crypto');
}

/**
*
* DATA- Exchange rates Endpoints
*
*/

/**
* Get Exchange Rates
*
* Get current exchange rates. Default base currency is USD but it can be defined as any supported currency.
* Returned rates will define the exchange rate for one unit of the base currency.
*/
getExchangeRates(params?: { currency?: string }): Promise<{
data: {
currency: string;
rates: { [key: string]: string };
};
}> {
return this.get(`/v2/exchange-rates`, params);
}

/**
*
* DATA - Prices Endpoints
*
*/

/**
* Get Buy Price
*
* Get the total price to buy one bitcoin or ether.
* This endpoint doesn't require authentication.
*/
getBuyPrice(params: { currencyPair: string }): Promise<{
data: {
amount: string;
currency: string;
};
}> {
return this.get(`/v2/prices/${params.currencyPair}/buy`);
}

/**
* Get Sell Price
*
* Get the total price to sell one bitcoin or ether.
* This endpoint doesn't require authentication.
*/
getSellPrice(params: { currencyPair: string }): Promise<{
data: {
amount: string;
currency: string;
};
}> {
return this.get(`/v2/prices/${params.currencyPair}/sell`);
}

/**
* Get Spot Price
*
* Get the current market price for bitcoin. This is usually somewhere in between the buy and sell price.
* This endpoint doesn't require authentication.
*/
getSpotPrice(params: { currencyPair: string; date?: string }): Promise<{
data: {
amount: string;
currency: string;
};
}> {
const { currencyPair, ...query } = params;
return this.get(`/v2/prices/${currencyPair}/spot`, query);
}

/**
*
* DATA - Time Endpoints
*
*/

/**
* Get Current Time
*
* Get the API server time.
* This endpoint doesn't require authentication.
*/
getCurrentTime(): Promise<{
data: {
iso: string;
epoch: number;
};
}> {
return this.get('/v2/time');
}
}
24 changes: 24 additions & 0 deletions src/types/request/coinbase-app-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,27 @@ export interface CBAppWithdrawFundsRequest {
payment_method: string;
commit?: boolean;
}

/**
*
* DATA - Currencies Endpoints
*
*/

/**
*
* DATA- Exchange rates Endpoints
*
*/

/**
*
* DATA - Prices Endpoints
*
*/

/**
*
* DATA - Time Endpoints
*
*/
41 changes: 41 additions & 0 deletions src/types/response/coinbase-app-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,44 @@ export interface CBAppDepositWithdrawal {
fee: DepositWithdrawalAmountCurrency;
payout_at: string;
}

/**
*
* DATA - Currencies Endpoints
*
*/

export interface CBAppFiatCurrency {
id: string;
name: string;
min_size: string;
}

export interface CBAppCryptocurrency {
code: string;
name: string;
color: string;
sort_index: number;
exponent: number;
type: string;
address_regex: string;
asset_id: string;
}

/**
*
* DATA- Exchange rates Endpoints
*
*/

/**
*
* DATA - Prices Endpoints
*
*/

/**
*
* DATA - Time Endpoints
*
*/