Skip to content

Commit

Permalink
Merge pull request ccxt#18158 from Dan-krm/gateFetchTickerOption
Browse files Browse the repository at this point in the history
Gate: fetchTicker, fetchTickers, add option support

[ci skip]
  • Loading branch information
Travis CI committed Jun 8, 2023
1 parent b21cef4 commit 2c40cc8
Show file tree
Hide file tree
Showing 9 changed files with 459 additions and 65 deletions.
67 changes: 59 additions & 8 deletions dist/ccxt.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -111926,6 +111926,10 @@ class gate extends _abstract_gate_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"]
* @method
* @name gate#fetchTicker
* @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
* @see https://www.gate.io/docs/developers/apiv4/en/#get-details-of-a-specifc-order
* @see https://www.gate.io/docs/developers/apiv4/en/#list-futures-tickers
* @see https://www.gate.io/docs/developers/apiv4/en/#list-futures-tickers-2
* @see https://www.gate.io/docs/developers/apiv4/en/#list-tickers-of-options-contracts
* @param {string} symbol unified symbol of the market to fetch the ticker for
* @param {object} params extra parameters specific to the gate api endpoint
* @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
Expand All @@ -111938,9 +111942,27 @@ class gate extends _abstract_gate_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"]
'margin': 'publicSpotGetTickers',
'swap': 'publicFuturesGetSettleTickers',
'future': 'publicDeliveryGetSettleTickers',
'option': 'publicOptionsGetTickers',
});
if (market['option']) {
const marketId = market['id'];
const optionParts = marketId.split('-');
request['underlying'] = this.safeString(optionParts, 0);
}
const response = await this[method](this.extend(request, query));
const ticker = this.safeValue(response, 0);
let ticker = undefined;
if (market['option']) {
for (let i = 0; i < response.length; i++) {
const entry = response[i];
if (entry['name'] === market['id']) {
ticker = entry;
break;
}
}
}
else {
ticker = this.safeValue(response, 0);
}
return this.parseTicker(ticker, market);
}
parseTicker(ticker, market = undefined) {
Expand Down Expand Up @@ -111991,16 +112013,37 @@ class gate extends _abstract_gate_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"]
// A: '0.0353' // best ask size
// }
//
const marketId = this.safeString2(ticker, 'currency_pair', 'contract');
const marketType = ('contract' in ticker) ? 'contract' : 'spot';
// option
//
// {
// "vega": "0.00002",
// "leverage": "12.277188268663",
// "ask_iv": "0",
// "delta": "-0.99999",
// "last_price": "0",
// "theta": "-0.00661",
// "bid1_price": "1096",
// "mark_iv": "0.7799",
// "name": "BTC_USDT-20230608-28500-P",
// "bid_iv": "0",
// "ask1_price": "2935",
// "mark_price": "2147.3",
// "position_size": 0,
// "bid1_size": 12,
// "ask1_size": -14,
// "gamma": "0"
// }
//
const marketId = this.safeStringN(ticker, ['currency_pair', 'contract', 'name']);
const marketType = ('mark_price' in ticker) ? 'contract' : 'spot';
const symbol = this.safeSymbol(marketId, market, '_', marketType);
const last = this.safeString(ticker, 'last');
const ask = this.safeString2(ticker, 'lowest_ask', 'a');
const bid = this.safeString2(ticker, 'highest_bid', 'b');
const last = this.safeString2(ticker, 'last', 'last_price');
const ask = this.safeStringN(ticker, ['lowest_ask', 'a', 'ask1_price']);
const bid = this.safeStringN(ticker, ['highest_bid', 'b', 'bid1_price']);
const high = this.safeString(ticker, 'high_24h');
const low = this.safeString(ticker, 'low_24h');
const bidVolume = this.safeString(ticker, 'B');
const askVolume = this.safeString(ticker, 'A');
const bidVolume = this.safeString2(ticker, 'B', 'bid1_size');
const askVolume = this.safeString2(ticker, 'A', 'ask1_size');
const timestamp = this.safeInteger(ticker, 't');
let baseVolume = this.safeString2(ticker, 'base_volume', 'volume_24h_base');
if (baseVolume === 'nan') {
Expand Down Expand Up @@ -112042,6 +112085,7 @@ class gate extends _abstract_gate_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"]
* @see https://www.gate.io/docs/developers/apiv4/en/#get-details-of-a-specifc-order
* @see https://www.gate.io/docs/developers/apiv4/en/#list-futures-tickers
* @see https://www.gate.io/docs/developers/apiv4/en/#list-futures-tickers-2
* @see https://www.gate.io/docs/developers/apiv4/en/#list-tickers-of-options-contracts
* @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 gate api endpoint
* @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/#/?id=ticker-structure}
Expand All @@ -112060,7 +112104,14 @@ class gate extends _abstract_gate_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"]
'margin': 'publicSpotGetTickers',
'swap': 'publicFuturesGetSettleTickers',
'future': 'publicDeliveryGetSettleTickers',
'option': 'publicOptionsGetTickers',
});
if (type === 'option') {
this.checkRequiredArgument('fetchTickers', symbols, 'symbols');
const marketId = market['id'];
const optionParts = marketId.split('-');
request['underlying'] = this.safeString(optionParts, 0);
}
const response = await this[method](this.extend(request, requestParams));
return this.parseTickers(response, symbols);
}
Expand Down
2 changes: 1 addition & 1 deletion dist/ccxt.browser.min.js

Large diffs are not rendered by default.

67 changes: 59 additions & 8 deletions dist/ccxt.bundle.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -120220,6 +120220,10 @@ class gate$1 extends Exchange$E {
* @method
* @name gate#fetchTicker
* @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
* @see https://www.gate.io/docs/developers/apiv4/en/#get-details-of-a-specifc-order
* @see https://www.gate.io/docs/developers/apiv4/en/#list-futures-tickers
* @see https://www.gate.io/docs/developers/apiv4/en/#list-futures-tickers-2
* @see https://www.gate.io/docs/developers/apiv4/en/#list-tickers-of-options-contracts
* @param {string} symbol unified symbol of the market to fetch the ticker for
* @param {object} params extra parameters specific to the gate api endpoint
* @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
Expand All @@ -120232,9 +120236,27 @@ class gate$1 extends Exchange$E {
'margin': 'publicSpotGetTickers',
'swap': 'publicFuturesGetSettleTickers',
'future': 'publicDeliveryGetSettleTickers',
'option': 'publicOptionsGetTickers',
});
if (market['option']) {
const marketId = market['id'];
const optionParts = marketId.split('-');
request['underlying'] = this.safeString(optionParts, 0);
}
const response = await this[method](this.extend(request, query));
const ticker = this.safeValue(response, 0);
let ticker = undefined;
if (market['option']) {
for (let i = 0; i < response.length; i++) {
const entry = response[i];
if (entry['name'] === market['id']) {
ticker = entry;
break;
}
}
}
else {
ticker = this.safeValue(response, 0);
}
return this.parseTicker(ticker, market);
}
parseTicker(ticker, market = undefined) {
Expand Down Expand Up @@ -120285,16 +120307,37 @@ class gate$1 extends Exchange$E {
// A: '0.0353' // best ask size
// }
//
const marketId = this.safeString2(ticker, 'currency_pair', 'contract');
const marketType = ('contract' in ticker) ? 'contract' : 'spot';
// option
//
// {
// "vega": "0.00002",
// "leverage": "12.277188268663",
// "ask_iv": "0",
// "delta": "-0.99999",
// "last_price": "0",
// "theta": "-0.00661",
// "bid1_price": "1096",
// "mark_iv": "0.7799",
// "name": "BTC_USDT-20230608-28500-P",
// "bid_iv": "0",
// "ask1_price": "2935",
// "mark_price": "2147.3",
// "position_size": 0,
// "bid1_size": 12,
// "ask1_size": -14,
// "gamma": "0"
// }
//
const marketId = this.safeStringN(ticker, ['currency_pair', 'contract', 'name']);
const marketType = ('mark_price' in ticker) ? 'contract' : 'spot';
const symbol = this.safeSymbol(marketId, market, '_', marketType);
const last = this.safeString(ticker, 'last');
const ask = this.safeString2(ticker, 'lowest_ask', 'a');
const bid = this.safeString2(ticker, 'highest_bid', 'b');
const last = this.safeString2(ticker, 'last', 'last_price');
const ask = this.safeStringN(ticker, ['lowest_ask', 'a', 'ask1_price']);
const bid = this.safeStringN(ticker, ['highest_bid', 'b', 'bid1_price']);
const high = this.safeString(ticker, 'high_24h');
const low = this.safeString(ticker, 'low_24h');
const bidVolume = this.safeString(ticker, 'B');
const askVolume = this.safeString(ticker, 'A');
const bidVolume = this.safeString2(ticker, 'B', 'bid1_size');
const askVolume = this.safeString2(ticker, 'A', 'ask1_size');
const timestamp = this.safeInteger(ticker, 't');
let baseVolume = this.safeString2(ticker, 'base_volume', 'volume_24h_base');
if (baseVolume === 'nan') {
Expand Down Expand Up @@ -120336,6 +120379,7 @@ class gate$1 extends Exchange$E {
* @see https://www.gate.io/docs/developers/apiv4/en/#get-details-of-a-specifc-order
* @see https://www.gate.io/docs/developers/apiv4/en/#list-futures-tickers
* @see https://www.gate.io/docs/developers/apiv4/en/#list-futures-tickers-2
* @see https://www.gate.io/docs/developers/apiv4/en/#list-tickers-of-options-contracts
* @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 gate api endpoint
* @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/#/?id=ticker-structure}
Expand All @@ -120354,7 +120398,14 @@ class gate$1 extends Exchange$E {
'margin': 'publicSpotGetTickers',
'swap': 'publicFuturesGetSettleTickers',
'future': 'publicDeliveryGetSettleTickers',
'option': 'publicOptionsGetTickers',
});
if (type === 'option') {
this.checkRequiredArgument('fetchTickers', symbols, 'symbols');
const marketId = market['id'];
const optionParts = marketId.split('-');
request['underlying'] = this.safeString(optionParts, 0);
}
const response = await this[method](this.extend(request, requestParams));
return this.parseTickers(response, symbols);
}
Expand Down
67 changes: 59 additions & 8 deletions dist/cjs/src/gate.js
Original file line number Diff line number Diff line change
Expand Up @@ -2106,6 +2106,10 @@ class gate extends gate$1 {
* @method
* @name gate#fetchTicker
* @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
* @see https://www.gate.io/docs/developers/apiv4/en/#get-details-of-a-specifc-order
* @see https://www.gate.io/docs/developers/apiv4/en/#list-futures-tickers
* @see https://www.gate.io/docs/developers/apiv4/en/#list-futures-tickers-2
* @see https://www.gate.io/docs/developers/apiv4/en/#list-tickers-of-options-contracts
* @param {string} symbol unified symbol of the market to fetch the ticker for
* @param {object} params extra parameters specific to the gate api endpoint
* @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
Expand All @@ -2118,9 +2122,27 @@ class gate extends gate$1 {
'margin': 'publicSpotGetTickers',
'swap': 'publicFuturesGetSettleTickers',
'future': 'publicDeliveryGetSettleTickers',
'option': 'publicOptionsGetTickers',
});
if (market['option']) {
const marketId = market['id'];
const optionParts = marketId.split('-');
request['underlying'] = this.safeString(optionParts, 0);
}
const response = await this[method](this.extend(request, query));
const ticker = this.safeValue(response, 0);
let ticker = undefined;
if (market['option']) {
for (let i = 0; i < response.length; i++) {
const entry = response[i];
if (entry['name'] === market['id']) {
ticker = entry;
break;
}
}
}
else {
ticker = this.safeValue(response, 0);
}
return this.parseTicker(ticker, market);
}
parseTicker(ticker, market = undefined) {
Expand Down Expand Up @@ -2171,16 +2193,37 @@ class gate extends gate$1 {
// A: '0.0353' // best ask size
// }
//
const marketId = this.safeString2(ticker, 'currency_pair', 'contract');
const marketType = ('contract' in ticker) ? 'contract' : 'spot';
// option
//
// {
// "vega": "0.00002",
// "leverage": "12.277188268663",
// "ask_iv": "0",
// "delta": "-0.99999",
// "last_price": "0",
// "theta": "-0.00661",
// "bid1_price": "1096",
// "mark_iv": "0.7799",
// "name": "BTC_USDT-20230608-28500-P",
// "bid_iv": "0",
// "ask1_price": "2935",
// "mark_price": "2147.3",
// "position_size": 0,
// "bid1_size": 12,
// "ask1_size": -14,
// "gamma": "0"
// }
//
const marketId = this.safeStringN(ticker, ['currency_pair', 'contract', 'name']);
const marketType = ('mark_price' in ticker) ? 'contract' : 'spot';
const symbol = this.safeSymbol(marketId, market, '_', marketType);
const last = this.safeString(ticker, 'last');
const ask = this.safeString2(ticker, 'lowest_ask', 'a');
const bid = this.safeString2(ticker, 'highest_bid', 'b');
const last = this.safeString2(ticker, 'last', 'last_price');
const ask = this.safeStringN(ticker, ['lowest_ask', 'a', 'ask1_price']);
const bid = this.safeStringN(ticker, ['highest_bid', 'b', 'bid1_price']);
const high = this.safeString(ticker, 'high_24h');
const low = this.safeString(ticker, 'low_24h');
const bidVolume = this.safeString(ticker, 'B');
const askVolume = this.safeString(ticker, 'A');
const bidVolume = this.safeString2(ticker, 'B', 'bid1_size');
const askVolume = this.safeString2(ticker, 'A', 'ask1_size');
const timestamp = this.safeInteger(ticker, 't');
let baseVolume = this.safeString2(ticker, 'base_volume', 'volume_24h_base');
if (baseVolume === 'nan') {
Expand Down Expand Up @@ -2222,6 +2265,7 @@ class gate extends gate$1 {
* @see https://www.gate.io/docs/developers/apiv4/en/#get-details-of-a-specifc-order
* @see https://www.gate.io/docs/developers/apiv4/en/#list-futures-tickers
* @see https://www.gate.io/docs/developers/apiv4/en/#list-futures-tickers-2
* @see https://www.gate.io/docs/developers/apiv4/en/#list-tickers-of-options-contracts
* @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 gate api endpoint
* @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/#/?id=ticker-structure}
Expand All @@ -2240,7 +2284,14 @@ class gate extends gate$1 {
'margin': 'publicSpotGetTickers',
'swap': 'publicFuturesGetSettleTickers',
'future': 'publicDeliveryGetSettleTickers',
'option': 'publicOptionsGetTickers',
});
if (type === 'option') {
this.checkRequiredArgument('fetchTickers', symbols, 'symbols');
const marketId = market['id'];
const optionParts = marketId.split('-');
request['underlying'] = this.safeString(optionParts, 0);
}
const response = await this[method](this.extend(request, requestParams));
return this.parseTickers(response, symbols);
}
Expand Down
Loading

0 comments on commit 2c40cc8

Please # to comment.