Skip to content

Commit

Permalink
fix(coinbase) - add usePrivate option (#22579)
Browse files Browse the repository at this point in the history
* fix(coinbase) - priv api for public data 1

* added all other endpints

* rename option

---------

Co-authored-by: carlosmiei <43336371+carlosmiei@users.noreply.github.com>

[ci skip]
  • Loading branch information
Travis CI committed May 27, 2024
1 parent e2a19c3 commit e1d43e4
Show file tree
Hide file tree
Showing 11 changed files with 868 additions and 379 deletions.
130 changes: 124 additions & 6 deletions cs/ccxt/exchanges/coinbase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ public override object describe()
{ "CGLD", "CELO" },
} },
{ "options", new Dictionary<string, object>() {
{ "usePrivate", false },
{ "brokerId", "ccxt" },
{ "stablePairs", new List<object>() {"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", new Dictionary<string, object>() {
Expand Down Expand Up @@ -1119,6 +1120,7 @@ public async override Task<object> fetchMarkets(object parameters = null)
* @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
*/
parameters ??= new Dictionary<string, object>();
Expand Down Expand Up @@ -1211,7 +1213,63 @@ public async virtual Task<object> fetchMarketsV2(object parameters = null)
public async virtual Task<object> fetchMarketsV3(object parameters = null)
{
parameters ??= new Dictionary<string, object>();
object spotUnresolvedPromises = new List<object> {this.v3PublicGetBrokerageMarketProducts(parameters)};
object usePrivate = false;
var usePrivateparametersVariable = this.handleOptionAndParams(parameters, "fetchMarkets", "usePrivate", false);
usePrivate = ((IList<object>)usePrivateparametersVariable)[0];
parameters = ((IList<object>)usePrivateparametersVariable)[1];
object spotUnresolvedPromises = new List<object>() {};
if (isTrue(usePrivate))
{
((IList<object>)spotUnresolvedPromises).Add(this.v3PrivateGetBrokerageProducts(parameters));
} else
{
((IList<object>)spotUnresolvedPromises).Add(this.v3PublicGetBrokerageMarketProducts(parameters));
}
//
// {
// 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 (isTrue(this.checkRequiredCredentials(false)))
{
((IList<object>)spotUnresolvedPromises).Add(this.v3PrivateGetBrokerageTransactionSummary(parameters));
Expand Down Expand Up @@ -1766,6 +1824,7 @@ public async override Task<object> fetchTickers(object symbols = null, object pa
* @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}
*/
parameters ??= new Dictionary<string, object>();
Expand Down Expand Up @@ -1831,7 +1890,18 @@ public async virtual Task<object> fetchTickersV3(object symbols = null, object p
{
((IDictionary<string,object>)request)["product_type"] = ((bool) isTrue((isEqual(marketType, "swap")))) ? "FUTURE" : "SPOT";
}
object response = await this.v3PublicGetBrokerageMarketProducts(this.extend(request, parameters));
object response = null;
object usePrivate = false;
var usePrivateparametersVariable = this.handleOptionAndParams(parameters, "fetchTickers", "usePrivate", false);
usePrivate = ((IList<object>)usePrivateparametersVariable)[0];
parameters = ((IList<object>)usePrivateparametersVariable)[1];
if (isTrue(usePrivate))
{
response = await this.v3PrivateGetBrokerageProducts(this.extend(request, parameters));
} else
{
response = await this.v3PublicGetBrokerageMarketProducts(this.extend(request, parameters));
}
//
// {
// "products": [
Expand Down Expand Up @@ -1894,6 +1964,7 @@ public async override Task<object> fetchTicker(object symbol, object parameters
* @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}
*/
parameters ??= new Dictionary<string, object>();
Expand Down Expand Up @@ -1945,7 +2016,18 @@ public async virtual Task<object> fetchTickerV3(object symbol, object parameters
{ "product_id", getValue(market, "id") },
{ "limit", 1 },
};
object response = await this.v3PublicGetBrokerageMarketProductsProductIdTicker(this.extend(request, parameters));
object usePrivate = false;
var usePrivateparametersVariable = this.handleOptionAndParams(parameters, "fetchTicker", "usePrivate", false);
usePrivate = ((IList<object>)usePrivateparametersVariable)[0];
parameters = ((IList<object>)usePrivateparametersVariable)[1];
object response = null;
if (isTrue(usePrivate))
{
response = await this.v3PrivateGetBrokerageProductsProductIdTicker(this.extend(request, parameters));
} else
{
response = await this.v3PublicGetBrokerageMarketProductsProductIdTicker(this.extend(request, parameters));
}
//
// {
// "trades": [
Expand Down Expand Up @@ -3671,6 +3753,7 @@ public async override Task<object> fetchOHLCV(object symbol, object timeframe =
* @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
*/
timeframe ??= "1m";
Expand Down Expand Up @@ -3713,7 +3796,18 @@ public async override Task<object> fetchOHLCV(object symbol, object timeframe =
// 300 candles max
((IDictionary<string,object>)request)["end"] = Precise.stringAdd(sinceString, ((object)requestedDuration).ToString());
}
object response = await this.v3PublicGetBrokerageMarketProductsProductIdCandles(this.extend(request, parameters));
object response = null;
object usePrivate = false;
var usePrivateparametersVariable = this.handleOptionAndParams(parameters, "fetchOHLCV", "usePrivate", false);
usePrivate = ((IList<object>)usePrivateparametersVariable)[0];
parameters = ((IList<object>)usePrivateparametersVariable)[1];
if (isTrue(usePrivate))
{
response = await this.v3PrivateGetBrokerageProductsProductIdCandles(this.extend(request, parameters));
} else
{
response = await this.v3PublicGetBrokerageMarketProductsProductIdCandles(this.extend(request, parameters));
}
//
// {
// "candles": [
Expand Down Expand Up @@ -3760,6 +3854,7 @@ public async override Task<object> fetchTrades(object symbol, object since = nul
* @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}
*/
parameters ??= new Dictionary<string, object>();
Expand Down Expand Up @@ -3787,7 +3882,18 @@ public async override Task<object> fetchTrades(object symbol, object since = nul
{
throw new ArgumentsRequired ((string)add(this.id, " fetchTrades() requires a `until` parameter when you use `since` argument")) ;
}
object response = await this.v3PublicGetBrokerageMarketProductsProductIdTicker(this.extend(request, parameters));
object response = null;
object usePrivate = false;
var usePrivateparametersVariable = this.handleOptionAndParams(parameters, "fetchTrades", "usePrivate", false);
usePrivate = ((IList<object>)usePrivateparametersVariable)[0];
parameters = ((IList<object>)usePrivateparametersVariable)[1];
if (isTrue(usePrivate))
{
response = await this.v3PrivateGetBrokerageProductsProductIdTicker(this.extend(request, parameters));
} else
{
response = await this.v3PublicGetBrokerageMarketProductsProductIdTicker(this.extend(request, parameters));
}
//
// {
// "trades": [
Expand Down Expand Up @@ -3902,6 +4008,7 @@ public async override Task<object> fetchOrderBook(object symbol, object limit =
* @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
*/
parameters ??= new Dictionary<string, object>();
Expand All @@ -3914,7 +4021,18 @@ public async override Task<object> fetchOrderBook(object symbol, object limit =
{
((IDictionary<string,object>)request)["limit"] = limit;
}
object response = await this.v3PublicGetBrokerageMarketProductBook(this.extend(request, parameters));
object response = null;
object usePrivate = false;
var usePrivateparametersVariable = this.handleOptionAndParams(parameters, "fetchOrderBook", "usePrivate", false);
usePrivate = ((IList<object>)usePrivateparametersVariable)[0];
parameters = ((IList<object>)usePrivateparametersVariable)[1];
if (isTrue(usePrivate))
{
response = await this.v3PrivateGetBrokerageProductBook(this.extend(request, parameters));
} else
{
response = await this.v3PublicGetBrokerageMarketProductBook(this.extend(request, parameters));
}
//
// {
// "pricebook": {
Expand Down
36 changes: 36 additions & 0 deletions cs/ccxt/wrappers/coinbase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,12 @@ public async Task<List<Transaction>> FetchDeposits(string code = null, Int64? si
/// object : extra parameters specific to the exchange API endpoint
/// </description>
/// </item>
/// <item>
/// <term>params.usePrivate</term>
/// <description>
/// boolean : use private endpoint for fetching markets
/// </description>
/// </item>
/// </list>
/// </remarks>
/// <returns> <term>object[]</term> an array of objects representing market data.</returns>
Expand Down Expand Up @@ -302,6 +308,12 @@ public async Task<List<MarketInterface>> FetchMarkets(Dictionary<string, object>
/// object : extra parameters specific to the exchange API endpoint
/// </description>
/// </item>
/// <item>
/// <term>params.usePrivate</term>
/// <description>
/// boolean : use private endpoint for fetching tickers
/// </description>
/// </item>
/// </list>
/// </remarks>
/// <returns> <term>object</term> a dictionary of [ticker structures]{@link https://docs.ccxt.com/#/?id=ticker-structure}.</returns>
Expand Down Expand Up @@ -335,6 +347,12 @@ public async Task<Tickers> FetchTickers(List<String> symbols = null, Dictionary<
/// object : extra parameters specific to the exchange API endpoint
/// </description>
/// </item>
/// <item>
/// <term>params.usePrivate</term>
/// <description>
/// boolean : whether to use the private endpoint for fetching the ticker
/// </description>
/// </item>
/// </list>
/// </remarks>
/// <returns> <term>object</term> a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}.</returns>
Expand Down Expand Up @@ -872,6 +890,12 @@ public async Task<List<Order>> FetchCanceledOrders(string symbol = null, Int64?
/// boolean : 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)
/// </description>
/// </item>
/// <item>
/// <term>params.usePrivate</term>
/// <description>
/// boolean : default false, when true will use the private endpoint to fetch the candles
/// </description>
/// </item>
/// </list>
/// </remarks>
/// <returns> <term>int[][]</term> A list of candles ordered as timestamp, open, high, low, close, volume.</returns>
Expand Down Expand Up @@ -906,6 +930,12 @@ public async Task<List<OHLCV>> FetchOHLCV(string symbol, string timeframe = "1m"
/// object : extra parameters specific to the exchange API endpoint
/// </description>
/// </item>
/// <item>
/// <term>params.usePrivate</term>
/// <description>
/// boolean : default false, when true will use the private endpoint to fetch the trades
/// </description>
/// </item>
/// </list>
/// </remarks>
/// <returns> <term>Trade[]</term> a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}.</returns>
Expand Down Expand Up @@ -980,6 +1010,12 @@ public async Task<List<Trade>> FetchMyTrades(string symbol = null, Int64? since2
/// object : extra parameters specific to the exchange API endpoint
/// </description>
/// </item>
/// <item>
/// <term>params.usePrivate</term>
/// <description>
/// boolean : default false, when true will use the private endpoint to fetch the order book
/// </description>
/// </item>
/// </list>
/// </remarks>
/// <returns> <term>object</term> A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols.</returns>
Expand Down
Loading

0 comments on commit e1d43e4

Please sign in to comment.