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

gemini - fetchMarketsFromApi #15862

Merged
merged 3 commits into from Dec 20, 2022
Merged
Changes from 2 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
107 changes: 96 additions & 11 deletions js/gemini.js
Expand Up @@ -233,6 +233,10 @@ module.exports = class gemini extends Exchange {
},
'options': {
'fetchMarketsMethod': 'fetch_markets_from_web',
'fetchMarketsFromAPI': {
'fetchDetailsForAllSymbols': false,
'fetchDetailsForMarketIds': [],
},
'fetchTickerMethod': 'fetchTickerV1', // fetchTickerV1, fetchTickerV2, fetchTickerV1AndV2
'networkIds': {
'bitcoin': 'BTC',
Expand Down Expand Up @@ -371,6 +375,17 @@ module.exports = class gemini extends Exchange {
return result;
}

parseMarketActive (status) {
const statuses = {
'open': true,
'closed': false,
'cancel_only': true,
'post_only': true,
'limit_only': true,
};
return this.safeValue (statuses, status, true);
}

async fetchMarketsFromAPI (params = {}) {
const response = await this.publicGetV1Symbols (params);
//
Expand All @@ -380,16 +395,86 @@ module.exports = class gemini extends Exchange {
// ...
// ]
//
const result = [];
const result = {};
for (let i = 0; i < response.length; i++) {
const marketId = response[i];
const market = marketId;
const idLength = marketId.length - 0;
const baseId = marketId.slice (0, idLength - 3);
const baseId = marketId.slice (0, idLength - 3); // Not true for all markets
const quoteId = marketId.slice (idLength - 3, idLength);
const base = this.safeCurrencyCode (baseId);
const quote = this.safeCurrencyCode (quoteId);
result.push ({
result[marketId] = {
'id': marketId,
'symbol': base + '/' + quote,
'swap': false,
'future': false,
'option': false,
'active': undefined,
'contract': false,
'linear': undefined,
'inverse': undefined,
'strike': undefined,
'optionType': undefined,
'precision': {
'price': undefined,
'amount': undefined,
},
'limits': {
'leverage': {
'min': undefined,
'max': undefined,
},
'amount': {
'min': undefined,
'max': undefined,
},
'price': {
'max': undefined,
},
},
'info': marketId,
};
}
const options = this.safeValue (this.options, 'fetchMarketsFromAPI', {});
const fetchDetailsForAllSymbols = this.safeValue (options, 'fetchDetailsForAllSymbols', false);
const fetchDetailsForMarketIds = this.safeValue (options, 'fetchDetailsForMarketIds', []);
let promises = [];
let marketIds = [];
if (fetchDetailsForAllSymbols) {
marketIds = response;
} else {
marketIds = fetchDetailsForMarketIds;
}
for (let i = 0; i < marketIds.length; i++) {
const marketId = marketIds[i];
const method = 'publicGetV1SymbolsDetailsSymbol';
const request = {
'symbol': marketId,
};
promises.push (this[method] (this.extend (request, params)));
//
// {
// "symbol": "BTCUSD",
// "base_currency": "BTC",
// "quote_currency": "USD",
// "tick_size": 1E-8,
// "quote_increment": 0.01,
// "min_order_size": "0.00001",
// "status": "open",
// "wrap_enabled": false
// }
//
}
promises = await Promise.all (promises);
for (let i = 0; i < promises.length; i++) {
pcriadoperez marked this conversation as resolved.
Show resolved Hide resolved
const response = promises[i];
const marketId = this.safeStringLower (response, 'symbol');
const baseId = this.safeString (response, 'base_currency');
const base = this.safeCurrencyCode (baseId);
const quoteId = this.safeString (response, 'quote_currency');
const quote = this.safeCurrencyCode (quoteId);
const status = this.safeString (response, 'status');
result[marketId] = ({
'id': marketId,
'symbol': base + '/' + quote,
'base': base,
Expand All @@ -404,7 +489,7 @@ module.exports = class gemini extends Exchange {
'swap': false,
'future': false,
'option': false,
'active': undefined,
'active': this.parseMarketActive (status),
'contract': false,
'linear': undefined,
'inverse': undefined,
Expand All @@ -414,16 +499,16 @@ module.exports = class gemini extends Exchange {
'strike': undefined,
'optionType': undefined,
'precision': {
'price': undefined,
'amount': undefined,
'price': this.safeNumber (response, 'quote_increment'),
'amount': this.safeNumber (response, 'tick_size'),
},
'limits': {
'leverage': {
'min': undefined,
'max': undefined,
},
'amount': {
'min': undefined,
'min': this.safeNumber (response, 'min_order_size'),
'max': undefined,
},
'price': {
Expand All @@ -435,10 +520,10 @@ module.exports = class gemini extends Exchange {
'max': undefined,
},
},
'info': market,
'info': response,
});
}
return result;
return this.toArray (result);
}

async fetchOrderBook (symbol, limit = undefined, params = {}) {
Expand Down Expand Up @@ -1317,7 +1402,7 @@ module.exports = class gemini extends Exchange {
}

nonce () {
return this.milliseconds ();
return this.seconds ();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pcriadoperez btw why are we doing this?

check this for context: #16066 and let me know if you have additional info pls

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@carlosmiei I think that it should be this.seconds I can't get gemini to work, and the solution is to change to this.seconds

}

async fetchTransactions (code = undefined, since = undefined, limit = undefined, params = {}) {
Expand Down