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

fix(coinbase) - add usePrivate option #22579

Merged
merged 3 commits into from
May 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
153 changes: 100 additions & 53 deletions ts/src/coinbase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ export default class coinbase extends Exchange {
'CGLD': 'CELO',
},
'options': {
'usePrivate': false,
'brokerId': 'ccxt',
'stablePairs': [ 'BUSD-USD', 'CBETH-ETH', 'DAI-USD', 'GUSD-USD', 'GYEN-USD', 'PAX-USD', 'PAX-USDT', 'USDC-EUR', 'USDC-GBP', 'USDT-EUR', 'USDT-GBP', 'USDT-USD', 'USDT-USDC', 'WBTC-BTC' ],
'fetchCurrencies': {
Expand Down Expand Up @@ -1118,6 +1119,7 @@ export default class coinbase extends Exchange {
* @see https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-exchange-rates#get-exchange-rates
* @description retrieves data on all markets for coinbase
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.usePrivate] use private endpoint for fetching markets
* @returns {object[]} an array of objects representing market data
*/
const method = this.safeString (this.options, 'fetchMarkets', 'fetchMarketsV3');
Expand Down Expand Up @@ -1201,54 +1203,59 @@ export default class coinbase extends Exchange {
}

async fetchMarketsV3 (params = {}) {
const spotUnresolvedPromises = [
this.v3PublicGetBrokerageMarketProducts (params),
//
// {
// products: [
// {
// product_id: 'BTC-USD',
// price: '67060',
// price_percentage_change_24h: '3.30054960636883',
// volume_24h: '10967.87426597',
// volume_percentage_change_24h: '141.73048325503036',
// base_increment: '0.00000001',
// quote_increment: '0.01',
// quote_min_size: '1',
// quote_max_size: '150000000',
// base_min_size: '0.00000001',
// base_max_size: '3400',
// base_name: 'Bitcoin',
// quote_name: 'US Dollar',
// watched: false,
// is_disabled: false,
// new: false,
// status: 'online',
// cancel_only: false,
// limit_only: false,
// post_only: false,
// trading_disabled: false,
// auction_mode: false,
// product_type: 'SPOT',
// quote_currency_id: 'USD',
// base_currency_id: 'BTC',
// fcm_trading_session_details: null,
// mid_market_price: '',
// alias: '',
// alias_to: [ 'BTC-USDC' ],
// base_display_symbol: 'BTC',
// quote_display_symbol: 'USD',
// view_only: false,
// price_increment: '0.01',
// display_name: 'BTC-USD',
// product_venue: 'CBE'
// },
// ...
// ],
// num_products: '646'
// }
//
];
let usePrivate = false;
[ usePrivate, params ] = this.handleOptionAndParams (params, 'fetchMarkets', 'usePrivate', false);
const spotUnresolvedPromises = [];
if (usePrivate) {
spotUnresolvedPromises.push (this.v3PrivateGetBrokerageProducts (params));
} else {
spotUnresolvedPromises.push (this.v3PublicGetBrokerageMarketProducts (params));
}
//
// {
// products: [
// {
// product_id: 'BTC-USD',
// price: '67060',
// price_percentage_change_24h: '3.30054960636883',
// volume_24h: '10967.87426597',
// volume_percentage_change_24h: '141.73048325503036',
// base_increment: '0.00000001',
// quote_increment: '0.01',
// quote_min_size: '1',
// quote_max_size: '150000000',
// base_min_size: '0.00000001',
// base_max_size: '3400',
// base_name: 'Bitcoin',
// quote_name: 'US Dollar',
// watched: false,
// is_disabled: false,
// new: false,
// status: 'online',
// cancel_only: false,
// limit_only: false,
// post_only: false,
// trading_disabled: false,
// auction_mode: false,
// product_type: 'SPOT',
// quote_currency_id: 'USD',
// base_currency_id: 'BTC',
// fcm_trading_session_details: null,
// mid_market_price: '',
// alias: '',
// alias_to: [ 'BTC-USDC' ],
// base_display_symbol: 'BTC',
// quote_display_symbol: 'USD',
// view_only: false,
// price_increment: '0.01',
// display_name: 'BTC-USD',
// product_venue: 'CBE'
// },
// ...
// ],
// num_products: '646'
// }
//
if (this.checkRequiredCredentials (false)) {
spotUnresolvedPromises.push (this.v3PrivateGetBrokerageTransactionSummary (params));
}
Expand Down Expand Up @@ -1778,6 +1785,7 @@ export default class coinbase extends Exchange {
* @see https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-exchange-rates#get-exchange-rates
* @param {string[]|undefined} symbols unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.usePrivate] use private endpoint for fetching tickers
* @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/#/?id=ticker-structure}
*/
const method = this.safeString (this.options, 'fetchTickers', 'fetchTickersV3');
Expand Down Expand Up @@ -1834,7 +1842,14 @@ export default class coinbase extends Exchange {
if (marketType !== undefined && marketType !== 'default') {
request['product_type'] = (marketType === 'swap') ? 'FUTURE' : 'SPOT';
}
const response = await this.v3PublicGetBrokerageMarketProducts (this.extend (request, params));
let response = undefined;
let usePrivate = false;
[ usePrivate, params ] = this.handleOptionAndParams (params, 'fetchTickers', 'usePrivate', false);
if (usePrivate) {
response = await this.v3PrivateGetBrokerageProducts (this.extend (request, params));
} else {
response = await this.v3PublicGetBrokerageMarketProducts (this.extend (request, params));
}
//
// {
// "products": [
Expand Down Expand Up @@ -1895,6 +1910,7 @@ export default class coinbase extends Exchange {
* @see https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-prices#get-sell-price
* @param {string} symbol unified symbol of the market to fetch the ticker for
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.usePrivate] whether to use the private endpoint for fetching the ticker
* @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
*/
const method = this.safeString (this.options, 'fetchTicker', 'fetchTickerV3');
Expand Down Expand Up @@ -1940,7 +1956,14 @@ export default class coinbase extends Exchange {
'product_id': market['id'],
'limit': 1,
};
const response = await this.v3PublicGetBrokerageMarketProductsProductIdTicker (this.extend (request, params));
let usePrivate = false;
[ usePrivate, params ] = this.handleOptionAndParams (params, 'fetchTicker', 'usePrivate', false);
let response = undefined;
if (usePrivate) {
response = await this.v3PrivateGetBrokerageProductsProductIdTicker (this.extend (request, params));
} else {
response = await this.v3PublicGetBrokerageMarketProductsProductIdTicker (this.extend (request, params));
}
//
// {
// "trades": [
Expand Down Expand Up @@ -3510,6 +3533,7 @@ export default class coinbase extends Exchange {
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] the latest time in ms to fetch trades for
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @param {boolean} [params.usePrivate] default false, when true will use the private endpoint to fetch the candles
* @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
*/
await this.loadMarkets ();
Expand Down Expand Up @@ -3543,7 +3567,14 @@ export default class coinbase extends Exchange {
// 300 candles max
request['end'] = Precise.stringAdd (sinceString, requestedDuration.toString ());
}
const response = await this.v3PublicGetBrokerageMarketProductsProductIdCandles (this.extend (request, params));
let response = undefined;
let usePrivate = false;
[ usePrivate, params ] = this.handleOptionAndParams (params, 'fetchOHLCV', 'usePrivate', false);
if (usePrivate) {
response = await this.v3PrivateGetBrokerageProductsProductIdCandles (this.extend (request, params));
} else {
response = await this.v3PublicGetBrokerageMarketProductsProductIdCandles (this.extend (request, params));
}
//
// {
// "candles": [
Expand Down Expand Up @@ -3595,6 +3626,7 @@ export default class coinbase extends Exchange {
* @param {int} [since] not used by coinbase fetchTrades
* @param {int} [limit] the maximum number of trade structures to fetch
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.usePrivate] default false, when true will use the private endpoint to fetch the trades
* @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
*/
await this.loadMarkets ();
Expand All @@ -3615,7 +3647,14 @@ export default class coinbase extends Exchange {
} else if (since !== undefined) {
throw new ArgumentsRequired (this.id + ' fetchTrades() requires a `until` parameter when you use `since` argument');
}
const response = await this.v3PublicGetBrokerageMarketProductsProductIdTicker (this.extend (request, params));
let response = undefined;
let usePrivate = false;
[ usePrivate, params ] = this.handleOptionAndParams (params, 'fetchTrades', 'usePrivate', false);
if (usePrivate) {
response = await this.v3PrivateGetBrokerageProductsProductIdTicker (this.extend (request, params));
} else {
response = await this.v3PublicGetBrokerageMarketProductsProductIdTicker (this.extend (request, params));
}
//
// {
// "trades": [
Expand Down Expand Up @@ -3718,6 +3757,7 @@ export default class coinbase extends Exchange {
* @param {string} symbol unified symbol of the market to fetch the order book for
* @param {int} [limit] the maximum amount of order book entries to return
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.usePrivate] default false, when true will use the private endpoint to fetch the order book
* @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
*/
await this.loadMarkets ();
Expand All @@ -3728,7 +3768,14 @@ export default class coinbase extends Exchange {
if (limit !== undefined) {
request['limit'] = limit;
}
const response = await this.v3PublicGetBrokerageMarketProductBook (this.extend (request, params));
let response = undefined;
let usePrivate = false;
[ usePrivate, params ] = this.handleOptionAndParams (params, 'fetchOrderBook', 'usePrivate', false);
if (usePrivate) {
response = await this.v3PrivateGetBrokerageProductBook (this.extend (request, params));
} else {
response = await this.v3PublicGetBrokerageMarketProductBook (this.extend (request, params));
}
//
// {
// "pricebook": {
Expand Down