Skip to content

Commit

Permalink
feat(): Added CBApp data endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
JJ-Cro committed Sep 13, 2024
1 parent 29717e3 commit fc0b7f6
Show file tree
Hide file tree
Showing 3 changed files with 188 additions and 0 deletions.
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
*
*/

0 comments on commit fc0b7f6

Please sign in to comment.