Skip to content

Commit

Permalink
Merge pull request #59 from JJ-Cro/Update181124
Browse files Browse the repository at this point in the history
v1.0.5 feat(): added 4 new INTX Index endpoints
  • Loading branch information
tiagosiebler authored Nov 18, 2024
2 parents a047886 + ca7141c commit 4e07ef6
Show file tree
Hide file tree
Showing 9 changed files with 201 additions and 47 deletions.
92 changes: 48 additions & 44 deletions docs/endpointFunctionList.md

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions examples/apidoc/CBInternationalClient/getIndexCandles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const { CBInternationalClient } = require('coinbase-api');

// This example shows how to call this coinbase API endpoint with either node.js, javascript (js) or typescript (ts) with the npm module "coinbase-api" for coinbase exchange
// This coinbase API SDK is available on npm via "npm install coinbase-api"
// ENDPOINT: /api/v1/index/{index}/candles
// METHOD: GET
// PUBLIC: YES

const client = new CBInternationalClient({
apiKey: 'insert_api_key_here',
apiSecret: 'insert_api_secret_here',
});

client.getIndexCandles(params)
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});
20 changes: 20 additions & 0 deletions examples/apidoc/CBInternationalClient/getIndexComposition.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const { CBInternationalClient } = require('coinbase-api');

// This example shows how to call this coinbase API endpoint with either node.js, javascript (js) or typescript (ts) with the npm module "coinbase-api" for coinbase exchange
// This coinbase API SDK is available on npm via "npm install coinbase-api"
// ENDPOINT: /api/v1/index/{index}/composition
// METHOD: GET
// PUBLIC: YES

const client = new CBInternationalClient({
apiKey: 'insert_api_key_here',
apiSecret: 'insert_api_secret_here',
});

client.getIndexComposition(params)
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const { CBInternationalClient } = require('coinbase-api');

// This example shows how to call this coinbase API endpoint with either node.js, javascript (js) or typescript (ts) with the npm module "coinbase-api" for coinbase exchange
// This coinbase API SDK is available on npm via "npm install coinbase-api"
// ENDPOINT: /api/v1/index/{index}/composition-history
// METHOD: GET
// PUBLIC: YES

const client = new CBInternationalClient({
apiKey: 'insert_api_key_here',
apiSecret: 'insert_api_secret_here',
});

client.getIndexCompositionHistory(params)
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});
20 changes: 20 additions & 0 deletions examples/apidoc/CBInternationalClient/getIndexPrice.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const { CBInternationalClient } = require('coinbase-api');

// This example shows how to call this coinbase API endpoint with either node.js, javascript (js) or typescript (ts) with the npm module "coinbase-api" for coinbase exchange
// This coinbase API SDK is available on npm via "npm install coinbase-api"
// ENDPOINT: /api/v1/index/{index}/price
// METHOD: GET
// PUBLIC: YES

const client = new CBInternationalClient({
apiKey: 'insert_api_key_here',
apiSecret: 'insert_api_secret_here',
});

client.getIndexPrice(params)
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "coinbase-api",
"version": "1.0.4",
"version": "1.0.5",
"description": "Node.js SDK for Coinbase's REST APIs and WebSockets, with TypeScript & strong end to end tests.",
"scripts": {
"clean": "rm -rf dist",
Expand Down
50 changes: 50 additions & 0 deletions src/CBInternationalClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
GetINTXAggregatedCandlesData,
GetINTXDailyTradingVolumes,
GetINTXFillsByPortfoliosRequest,
GetINTXIndexCandlesRequest,
GetINTXIndexCompositionHistory,
GetINTXMatchingTransfersRequest,
GetINTXOpenOrdersRequest,
GetINTXPortfolioFillsRequest,
Expand Down Expand Up @@ -73,6 +75,54 @@ export class CBInternationalClient extends BaseRestClient {
return this.get(`/api/v1/assets/${params.asset}/networks`);
}

/**
*
* Index Endpoints
*
*/

/**
* Get index composition
*
* Retrieves the latest index composition (metadata) with an ordered set of constituents.
*/
getIndexComposition(params: { index: string }): Promise<any> {
return this.get(`/api/v1/index/${params.index}/composition`);
}

/**
* Get index composition history
*
* Retrieves a history of index composition records in a descending time order.
* The results are an array of index composition data recorded at different "timestamps".
*/
getIndexCompositionHistory(
params: GetINTXIndexCompositionHistory,
): Promise<any> {
const { index, ...query } = params;
return this.get(`/api/v1/index/${index}/composition-history`, query);
}

/**
* Get index price
*
* Retrieves the latest index price.
*/
getIndexPrice(params: { index: string }): Promise<any> {
return this.get(`/api/v1/index/${params.index}/price`);
}

/**
* Get index candles
*
* Retrieves the historical daily index prices in time descending order.
* The daily values are represented as aggregated entries for the day in typical OHLC format.
*/
getIndexCandles(params: GetINTXIndexCandlesRequest): Promise<any> {
const { index, ...query } = params;
return this.get(`/api/v1/index/${index}/candles`, query);
}

/**
*
* Instruments Endpoints
Expand Down
20 changes: 20 additions & 0 deletions src/types/request/coinbase-international.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,26 @@
*
*/

/**
*
* Index Endpoints
*
*/

export interface GetINTXIndexCompositionHistory {
index: string;
time_from?: string;
result_limit?: number;
result_offset?: number;
}

export interface GetINTXIndexCandlesRequest {
index: string;
granularity: string;
start: string;
end?: string;
}

/**
*
* Instruments Endpoints
Expand Down

0 comments on commit 4e07ef6

Please sign in to comment.