From 5f5ff190a3dfc279869b5182da37102b1789d40d Mon Sep 17 00:00:00 2001 From: Sam Germain Date: Mon, 30 May 2022 09:31:33 -0600 Subject: [PATCH 1/2] methodGuard class added to bass exchange --- js/base/Exchange.js | 110 ++++++++++++++--------------------- php/Exchange.php | 109 ++++++++++++++-------------------- python/ccxt/base/exchange.py | 95 +++++++++++++----------------- 3 files changed, 132 insertions(+), 182 deletions(-) diff --git a/js/base/Exchange.js b/js/base/Exchange.js index 57744ca175efe..0e869e20677e5 100644 --- a/js/base/Exchange.js +++ b/js/base/Exchange.js @@ -2222,9 +2222,7 @@ module.exports = class Exchange { async fetchBorrowRate (code, params = {}) { await this.loadMarkets (); - if (!this.has['fetchBorrowRates']) { - throw new NotSupported (this.id + ' fetchBorrowRate() is not supported yet') - } + this.methodGuard ('fetchBorrowRates', 'fetchBorrowRate'); const borrowRates = await this.fetchBorrowRates (params); const rate = this.safeValue (borrowRates, code); if (rate === undefined) { @@ -2278,16 +2276,13 @@ module.exports = class Exchange { } async fetchMarketLeverageTiers (symbol, params = {}) { - if (this.has['fetchLeverageTiers']) { - const market = await this.market (symbol); - if (!market['contract']) { - throw new BadSymbol (this.id + ' fetchMarketLeverageTiers() supports contract markets only'); - } - const tiers = await this.fetchLeverageTiers ([ symbol ]); - return this.safeValue (tiers, symbol); - } else { - throw new NotSupported (this.id + ' fetchMarketLeverageTiers() is not supported yet'); + this.methodGuard ('fetchLeverageTiers', 'fetchMarketLeverageTiers'); + const market = await this.market (symbol); + if (!market['contract']) { + throw new BadSymbol (this.id + ' fetchMarketLeverageTiers() supports contract markets only'); } + const tiers = await this.fetchLeverageTiers ([ symbol ]); + return this.safeValue (tiers, symbol); } parseOpenInterests (response, market = undefined, since = undefined, limit = undefined) { @@ -2332,25 +2327,19 @@ module.exports = class Exchange { } async createPostOnlyOrder (symbol, type, side, amount, price, params = {}) { - if (!this.has['createPostOnlyOrder']) { - throw new NotSupported (this.id + 'createPostOnlyOrder() is not supported yet'); - } + this.methodGuard ('createPostOnlyOrder'); const query = this.extend (params, { 'postOnly': true }); return await this.createOrder (symbol, type, side, amount, price, query); } async createReduceOnlyOrder (symbol, type, side, amount, price, params = {}) { - if (!this.has['createReduceOnlyOrder']) { - throw new NotSupported (this.id + 'createReduceOnlyOrder() is not supported yet'); - } + this.methodGuard ('createReduceOnlyOrder'); const query = this.extend (params, { 'reduceOnly': true }); return await this.createOrder (symbol, type, side, amount, price, query); } async createStopOrder (symbol, type, side, amount, price = undefined, stopPrice = undefined, params = {}) { - if (!this.has['createStopOrder']) { - throw new NotSupported (this.id + ' createStopOrder() is not supported yet'); - } + this.methodGuard ('createStopOrder'); if (stopPrice === undefined) { throw new ArgumentsRequired(this.id + ' create_stop_order() requires a stopPrice argument'); } @@ -2359,17 +2348,13 @@ module.exports = class Exchange { } async createStopLimitOrder(symbol, side, amount, price, stopPrice, params = {}) { - if (!this.has['createStopLimitOrder']) { - throw new NotSupported(this.id + ' createStopLimitOrder() is not supported yet'); - } + this.methodGuard ('createStopLimitOrder'); const query = this.extend(params, {'stopPrice': stopPrice}); return this.createOrder(symbol, 'limit', side, amount, price, query); } - + async createStopMarketOrder(symbol, side, amount, stopPrice, params = {}) { - if (!this.has['createStopMarketOrder']) { - throw new NotSupported(this.id + ' createStopMarketOrder() is not supported yet'); - } + this.methodGuard ('createStopMarketOrder'); const query = this.extend(params, {'stopPrice': stopPrice}); return this.createOrder(symbol, 'market', side, amount, undefined, query); } @@ -2412,20 +2397,24 @@ module.exports = class Exchange { } async fetchFundingRate (symbol, params = {}) { - if (this.has['fetchFundingRates']) { - const market = await this.market (symbol); - if (!market['contract']) { - throw new BadSymbol (this.id + ' fetchFundingRate() supports contract markets only'); - } - const rates = await this.fetchFundingRates ([ symbol ], params); - const rate = this.safeValue (rates, symbol); - if (rate === undefined) { - throw new NullResponse (this.id + ' fetchFundingRate () returned no data for ' + symbol); - } else { - return rate; - } + this.methodGuard ('fetchFundingRates', 'fetchFundingRate'); + const market = await this.market (symbol); + if (!market['contract']) { + throw new BadSymbol (this.id + ' fetchFundingRate() supports contract markets only'); + } + const rates = await this.fetchFundingRates ([ symbol ], params); + const rate = this.safeValue (rates, symbol); + if (rate === undefined) { + throw new NullResponse (this.id + ' fetchFundingRate () returned no data for ' + symbol); } else { - throw new NotSupported (this.id + ' fetchFundingRate () is not supported yet'); + return rate; + } + } + + methodGuard (hasMethod, unsupportedMethod = undefined) { + if (!this.has[hasMethod]) { + unsupportedMethod = unsupportedMethod ? unsupportedMethod : hasMethod; + throw new NotSupported (this.id + ' ' + unsupportedMethod + ' () is not supported yet'); } } @@ -2441,14 +2430,11 @@ module.exports = class Exchange { * @param {dict} params extra parameters specific to the exchange api endpoint * @returns {[[int|float]]} A list of candles ordered as timestamp, open, high, low, close, undefined */ - if (this.has['fetchMarkOHLCV']) { - const request = { - 'price': 'mark', - }; - return await this.fetchOHLCV (symbol, timeframe, since, limit, this.extend (request, params)); - } else { - throw new NotSupported (this.id + ' fetchMarkOHLCV () is not supported yet'); - } + this.methodGuard ('fetchMarkOHLCV'); + const request = { + 'price': 'mark', + }; + return await this.fetchOHLCV (symbol, timeframe, since, limit, this.extend (request, params)); } async fetchIndexOHLCV (symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) { @@ -2463,14 +2449,11 @@ module.exports = class Exchange { * @param {dict} params extra parameters specific to the exchange api endpoint * @returns {[[int|float]]} A list of candles ordered as timestamp, open, high, low, close, undefined */ - if (this.has['fetchIndexOHLCV']) { - const request = { - 'price': 'index', - }; - return await this.fetchOHLCV (symbol, timeframe, since, limit, this.extend (request, params)); - } else { - throw new NotSupported (this.id + ' fetchIndexOHLCV () is not supported yet'); - } + this.methodGuard ('fetchIndexOHLCV'); + const request = { + 'price': 'index', + }; + return await this.fetchOHLCV (symbol, timeframe, since, limit, this.extend (request, params)); } async fetchPremiumIndexOHLCV (symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) { @@ -2485,13 +2468,10 @@ module.exports = class Exchange { * @param {dict} params extra parameters specific to the exchange api endpoint * @returns {[[int|float]]} A list of candles ordered as timestamp, open, high, low, close, undefined */ - if (this.has['fetchPremiumIndexOHLCV']) { - const request = { - 'price': 'premiumIndex', - }; - return await this.fetchOHLCV (symbol, timeframe, since, limit, this.extend (request, params)); - } else { - throw new NotSupported (this.id + ' fetchPremiumIndexOHLCV () is not supported yet'); - } + this.methodGuard ('fetchPremiumIndexOHLCV'); + const request = { + 'price': 'premiumIndex', + }; + return await this.fetchOHLCV (symbol, timeframe, since, limit, this.extend (request, params)); } } diff --git a/php/Exchange.php b/php/Exchange.php index eb473129652cc..1831ec3d0c401 100644 --- a/php/Exchange.php +++ b/php/Exchange.php @@ -411,6 +411,7 @@ class Exchange { 'parseBorrowInterests' => 'parse_borrow_interests', 'parseFundingRateHistories' => 'parse_funding_rate_histories', 'fetchFundingRate' => 'fetch_funding_rate', + 'methodGuard' => 'method_guard', 'fetchMarkOHLCV' => 'fetch_mark_ohlcv', 'fetchIndexOHLCV' => 'fetch_index_ohlcv', 'fetchPremiumIndexOHLCV' => 'fetch_premium_index_ohlcv', @@ -3834,10 +3835,8 @@ public function get_supported_mapping($key, $mapping = array()) { } public function fetch_borrow_rate($code, $params = array()) { + $this->method_guard('fetchBorrowRates', 'fetch_borrow_rate'); $this->load_markets(); - if (!$this->has['fetchBorrowRates']) { - throw new NotSupported($this->id . ' fetchBorrowRate() is not supported yet'); - } $borrow_rates = $this->fetch_borrow_rates($params); $rate = $this->safe_value($borrow_rates, $code); if ($rate == null) { @@ -3890,16 +3889,13 @@ public function parse_leverage_tiers($response, $symbols, $market_id_key){ } public function fetch_market_leverage_tiers($symbol, $params = array()) { - if ($this->has['fetchLeverageTiers']) { - $market = $this->market($symbol); - if (!$market['contract']) { - throw new BadRequest($this->id . ' fetch_market_leverage_tiers() supports contract markets only'); - } - $tiers = $this->fetch_leverage_tiers(array($symbol)); - return $this->safe_value($tiers, $symbol); - } else { - throw new NotSupported($this->id . ' fetch_market_leverage_tiers() is not supported yet'); + $this->method_guard('fetchLeverageTiers', 'fetch_market_leverage_tiers'); + $market = $this->market($symbol); + if (!$market['contract']) { + throw new BadRequest($this->id . ' fetch_market_leverage_tiers() supports contract markets only'); } + $tiers = $this->fetch_leverage_tiers(array($symbol)); + return $this->safe_value($tiers, $symbol); } public function sleep($milliseconds) { @@ -3935,27 +3931,21 @@ public function is_post_only($isMarketOrder, $exchangeSpecificParam, $params = a } public function create_post_only_order($symbol, $type, $side, $amount, $price, $params = array()) { - if (!$this->has['createPostOnlyOrder']) { - throw new NotSupported($this->id . ' create_post_only_order() is not supported yet'); - } + $this->method_guard('createPostOnlyOrder', 'create_post_only_order'); $array = array('postOnly' => true); $query = $this->extend($params, $array); return $this->create_order($symbol, $type, $side, $amount, $price, $query); } public function create_reduce_only_order($symbol, $type, $side, $amount, $price, $params = array()) { - if (!$this->has['createReduceOnlyOrder']) { - throw new NotSupported($this->id . ' create_reduce_only_order() is not supported yet'); - } + $this->method_guard('createReduceOnlyOrder', 'create_reduce_only_order'); $array = array('reduceOnly' => true); $query = $this->extend($params, $array); return $this->create_order($symbol, $type, $side, $amount, $price, $params); } - + public function create_stop_order($symbol, $type, $side, $amount, $price = null, $stopPrice = null, $params = array()) { - if (!$this->has['createStopOrder']) { - throw new NotSupported($this->id . ' create_stop_order() is not supported yet'); - } + $this->method_guard('createStopOrder', 'create_stop_order'); if ($stopPrice === null) { throw new ArgumentsRequired($this->id . ' create_stop_order() requires a stopPrice argument'); } @@ -3965,18 +3955,14 @@ public function create_stop_order($symbol, $type, $side, $amount, $price = null, } public function create_stop_limit_order($symbol, $side, $amount, $price, $stopPrice, $params = array()) { - if (!$this->has['createStopLimitOrder']) { - throw new NotSupported($this->id . ' create_stop_limit_order() is not supported yet'); - } + $this->method_guard('createStopLimitOrder', 'create_stop_limit_order'); $array = array('stopPrice' => $stopPrice); $query = $this->extend($params, $array); return $this->create_order($symbol, 'limit', $side, $amount, $price, $query); } public function create_stop_market_order($symbol, $side, $amount, $stopPrice, $params = array()) { - if (!$this->has['createStopMarketOrder']) { - throw new NotSupported($this->id . ' create_stop_market_order() is not supported yet'); - } + $this->method_guard('createStopMarketOrder', 'create_stop_market_order'); $array = array('stopPrice' => $stopPrice); $query = $this->extend($params, $array); return $this->create_order($symbol, 'market', $side, $amount, null, $query); @@ -4036,20 +4022,17 @@ public function parse_open_interests($response, $market = null, $since = null, $ } public function fetch_funding_rate($symbol, $params = array ()) { - if ($this->has['fetchFundingRates']) { - $market = $this->market($symbol); - if (!$market['contract']) { - throw new BadSymbol($this->id . ' fetch_funding_rate () supports contract markets only'); - } - $rates = $this->fetch_funding_rates (array( $symbol ), $params); - $rate = $this->safe_value($rates, $symbol); - if ($rate === null) { - throw new NullResponse($this->id . ' fetch_funding_rate () returned no data for ' . $symbol); - } else { - return $rate; - } + $this->method_guard('fetchFundingRates', 'fetch_funding_rate'); + $market = $this->market($symbol); + if (!$market['contract']) { + throw new BadSymbol($this->id . ' fetch_funding_rate () supports contract markets only'); + } + $rates = $this->fetch_funding_rates (array( $symbol ), $params); + $rate = $this->safe_value($rates, $symbol); + if ($rate === null) { + throw new NullResponse($this->id . ' fetch_funding_rate () returned no data for ' . $symbol); } else { - throw new NotSupported($this->id . ' fetch_funding_rate () is not supported yet'); + return $rate; } } @@ -4063,14 +4046,11 @@ public function fetch_mark_ohlcv($symbol, $timeframe = '1m', $since = null, $lim * @param {dict} $params extra parameters specific to the exchange api endpoint * @return {[[int|float]]} a list of candles ordered as timestamp, open, high, low, close, null */ - if ($this->has['fetchMarkOHLCV']) { - $request = array( - 'price' => 'mark', - ); - return $this->fetch_ohlcv($symbol, $timeframe, $since, $limit, array_merge($request, $params)); - } else { - throw new NotSupported($this->id . ' fetchMarkOHLCV () is not supported yet'); - } + $this->method_guard('fetchMarkOHLCV', 'fetch_mark_ohlcv'); + $request = array( + 'price' => 'mark', + ); + return $this->fetch_ohlcv($symbol, $timeframe, $since, $limit, array_merge($request, $params)); } public function fetch_index_ohlcv($symbol, $timeframe = '1m', $since = null, $limit = null, $params = array ()) { @@ -4083,14 +4063,11 @@ public function fetch_index_ohlcv($symbol, $timeframe = '1m', $since = null, $li * @param {dict} $params extra parameters specific to the exchange api endpoint * @return {[[int|float]]} a list of candles ordered as timestamp, open, high, low, close, null */ - if ($this->has['fetchIndexOHLCV']) { - $request = array( - 'price' => 'index', - ); - return $this->fetch_ohlcv($symbol, $timeframe, $since, $limit, array_merge($request, $params)); - } else { - throw new NotSupported($this->id . ' fetchIndexOHLCV () is not supported yet'); - } + $this->method_guard('fetchIndexOHLCV', 'fetch_index_ohlcv'); + $request = array( + 'price' => 'index', + ); + return $this->fetch_ohlcv($symbol, $timeframe, $since, $limit, array_merge($request, $params)); } public function fetch_premium_index_ohlcv($symbol, $timeframe = '1m', $since = null, $limit = null, $params = array ()) { @@ -4103,13 +4080,17 @@ public function fetch_premium_index_ohlcv($symbol, $timeframe = '1m', $since = n * @param {dict} $params extra parameters specific to the exchange api endpoint * @return {[[int|float]]} a list of candles ordered as timestamp, open, high, low, close, null */ - if ($this->has['fetchPremiumIndexOHLCV']) { - $request = array( - 'price' => 'premiumIndex', - ); - return $this->fetch_ohlcv($symbol, $timeframe, $since, $limit, array_merge($request, $params)); - } else { - throw new NotSupported($this->id . ' fetchPremiumIndexOHLCV () is not supported yet'); + $this->method_guard('fetchPremiumIndexOHLCV', 'fetch_premium_index_ohlcv'); + $request = array( + 'price' => 'premiumIndex', + ); + return $this->fetch_ohlcv($symbol, $timeframe, $since, $limit, array_merge($request, $params)); + } + + public function method_guard($hasMethod, $unsupportedMethod = null) { + if (!$this->has[$hasMethod]) { + $unsupportedMethod = $unsupportedMethod ? $unsupportedMethod : $hasMethod; + throw new NotSupported($this->id . ' ' . $unsupportedMethod . ' () is not supported yet'); } } } diff --git a/python/ccxt/base/exchange.py b/python/ccxt/base/exchange.py index ad20d5eabe31b..55f850e4f3002 100644 --- a/python/ccxt/base/exchange.py +++ b/python/ccxt/base/exchange.py @@ -2899,8 +2899,7 @@ def get_supported_mapping(self, key, mapping={}): def fetch_borrow_rate(self, code, params={}): self.load_markets() - if not self.has['fetchBorrowRates']: - raise NotSupported(self.id + 'fetchBorrowRate() is not supported yet') + self.method_guard('fetchBorrowRates', 'fetch_borrow_rate') borrow_rates = self.fetch_borrow_rates(params) rate = self.safe_value(borrow_rates, code) if rate is None: @@ -2942,14 +2941,12 @@ def parse_leverage_tiers(self, response, symbols, market_id_key): return tiers def fetch_market_leverage_tiers(self, symbol, params={}): - if self.has['fetchLeverageTiers']: - market = self.market(symbol) - if (not market['contract']): - raise BadRequest(self.id + ' fetch_market_leverage_tiers() supports contract markets only') - tiers = self.fetch_leverage_tiers([symbol]) - return self.safe_value(tiers, symbol) - else: - raise NotSupported(self.id + 'fetch_market_leverage_tiers() is not supported yet') + self.method_guard('fetchLeverageTiers', 'fetch_market_leverage_tiers') + market = self.market(symbol) + if (not market['contract']): + raise BadRequest(self.id + ' fetch_market_leverage_tiers() supports contract markets only') + tiers = self.fetch_leverage_tiers([symbol]) + return self.safe_value(tiers, symbol) def is_post_only(self, isMarketOrder, exchangeSpecificParam, params={}): """ @@ -2977,34 +2974,29 @@ def is_post_only(self, isMarketOrder, exchangeSpecificParam, params={}): return False def create_post_only_order(self, symbol, type, side, amount, price, params={}): - if not self.has['createPostOnlyOrder']: - raise NotSupported(self.id + ' create_post_only_order() is not supported yet') + self.method_guard('createPostOnlyOrder', 'create_post_only_order') query = self.extend(params, {'postOnly': True}) return self.create_order(symbol, type, side, amount, price, query) def create_reduce_only_order(self, symbol, type, side, amount, price, params={}): - if not self.has['createReduceOnlyOrder']: - raise NotSupported(self.id + ' create_reduce_only_order() is not supported yet') + self.method_guard('createReduceOnlyOrder', 'create_reduce_only_order') query = self.extend(params, {'reduceOnly': True}) return self.create_order(symbol, type, side, amount, price, query) def create_stop_order(self, symbol, type, side, amount, price=None, stopPrice=None, params={}): - if not self.has['createStopOrder']: - raise NotSupported(self.id + 'create_stop_order() is not supported yet') + self.method_guard('createStopOrder', 'create_stop_order') if stopPrice is None: raise ArgumentsRequired(self.id + ' create_stop_order() requires a stopPrice argument') query = self.extend(params, {'stopPrice': stopPrice}) return self.create_order(symbol, type, side, amount, price, query) def create_stop_limit_order(self, symbol, side, amount, price, stopPrice, params={}): - if not self.has['createStopLimitOrder']: - raise NotSupported(self.id + ' create_stop_limit_order() is not supported yet') + self.method_guard('createStopLimitOrder', 'create_stop_limit_order') query = self.extend(params, {'stopPrice': stopPrice}) return self.create_order(symbol, 'limit', side, amount, price, query) def create_stop_market_order(self, symbol, side, amount, stopPrice, params={}): - if not self.has['createStopMarketOrder']: - raise NotSupported(self.id + ' create_stop_market_order() is not supported yet') + self.method_guard('createStopMarketOrder', 'create_stop_market_order') query = self.extend(params, {'stopPrice': stopPrice}) return self.create_order(symbol, 'market', side, amount, None, query) @@ -3044,22 +3036,20 @@ def parse_open_interests(self, response, market=None, since=None, limit=None): interest = self.parseOpenInterest(entry, market) interests.append(interest) sorted = self.sortBy(interests, 'timestamp') - symbol = this.safeString(market, 'symbol') + symbol = self.safeString(market, 'symbol') return self.filterBySymbolSinceLimit(sorted, symbol, since, limit) def fetch_funding_rate(self, symbol, params={}): - if self.has['fetchFundingRates']: - market = self.market(symbol) - if not market['contract']: - raise BadSymbol(self.id + ' fetch_funding_rate() supports contract markets only') - rates = self.fetchFundingRates([symbol], params) - rate = self.safe_value(rates, symbol) - if rate is None: - raise NullResponse(self.id + ' fetch_funding_rate() returned no data for ' + symbol) - else: - return rate + self.method_guard('fetchFundingRates', 'fetch_funding_rate') + market = self.market(symbol) + if not market['contract']: + raise BadSymbol(self.id + ' fetch_funding_rate() supports contract markets only') + rates = self.fetchFundingRates([symbol], params) + rate = self.safe_value(rates, symbol) + if rate is None: + raise NullResponse(self.id + ' fetch_funding_rate() returned no data for ' + symbol) else: - raise NotSupported(self.id + ' fetch_funding_rate() is not supported yet') + return rate def fetch_mark_ohlcv(self, symbol, timeframe='1m', since=None, limit=None, params={}): """ @@ -3071,13 +3061,11 @@ def fetch_mark_ohlcv(self, symbol, timeframe='1m', since=None, limit=None, param :param dict params: extra parameters specific to the exchange api endpoint :returns [[int|float]] A: list of candles ordered as timestamp, open, high, low, close, None """ - if self.has['fetchMarkOHLCV']: - request = { - 'price': 'mark', - } - return self.fetch_ohlcv(symbol, timeframe, since, limit, self.extend(request, params)) - else: - raise NotSupported(self.id + ' fetchMarkOHLCV() is not supported yet') + self.method_guard('fetchMarkOHLCV', 'fetch_mark_ohlcv') + request = { + 'price': 'mark', + } + return self.fetch_ohlcv(symbol, timeframe, since, limit, self.extend(request, params)) def fetch_index_ohlcv(self, symbol, timeframe='1m', since=None, limit=None, params={}): """ @@ -3089,13 +3077,11 @@ def fetch_index_ohlcv(self, symbol, timeframe='1m', since=None, limit=None, para :param dict params: extra parameters specific to the exchange api endpoint :returns [[int|float]] A: list of candles ordered as timestamp, open, high, low, close, None """ - if self.has['fetchIndexOHLCV']: - request = { - 'price': 'index', - } - return self.fetch_ohlcv(symbol, timeframe, since, limit, self.extend(request, params)) - else: - raise NotSupported(self.id + ' fetchIndexOHLCV() is not supported yet') + self.method_guard('fetchIndexOHLCV', 'fetch_index_ohlcv') + request = { + 'price': 'index', + } + return self.fetch_ohlcv(symbol, timeframe, since, limit, self.extend(request, params)) def fetch_premium_index_ohlcv(self, symbol, timeframe='1m', since=None, limit=None, params={}): """ @@ -3107,10 +3093,13 @@ def fetch_premium_index_ohlcv(self, symbol, timeframe='1m', since=None, limit=No :param dict params: extra parameters specific to the exchange api endpoint :returns [[int|float]] A: list of candles ordered as timestamp, open, high, low, close, None """ - if self.has['fetchPremiumIndexOHLCV']: - request = { - 'price': 'premiumIndex', - } - return self.fetch_ohlcv(symbol, timeframe, since, limit, self.extend(request, params)) - else: - raise NotSupported(self.id + ' fetchPremiumIndexOHLCV() is not supported yet') + self.method_guard('fetchPremiumIndexOHLCV', 'fetch_premium_index_ohlcv') + request = { + 'price': 'premiumIndex', + } + return self.fetch_ohlcv(symbol, timeframe, since, limit, self.extend(request, params)) + + def method_guard(self, hasMethod, unsupportedMethod=None): + if not self.has[hasMethod]: + unsupportedMethod = unsupportedMethod if unsupportedMethod else hasMethod + raise NotSupported(self.id + ' ' + unsupportedMethod + '() is not supported yet') From fe5facb667b13cbc57e3812ae6294ca421137c0c Mon Sep 17 00:00:00 2001 From: Sam Germain Date: Mon, 30 May 2022 23:07:48 -0600 Subject: [PATCH 2/2] minor changes --- js/base/Exchange.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/js/base/Exchange.js b/js/base/Exchange.js index 0e869e20677e5..adeb999d3e9d2 100644 --- a/js/base/Exchange.js +++ b/js/base/Exchange.js @@ -2341,7 +2341,7 @@ module.exports = class Exchange { async createStopOrder (symbol, type, side, amount, price = undefined, stopPrice = undefined, params = {}) { this.methodGuard ('createStopOrder'); if (stopPrice === undefined) { - throw new ArgumentsRequired(this.id + ' create_stop_order() requires a stopPrice argument'); + throw new ArgumentsRequired(this.id + ' createStopOrder() requires a stopPrice argument'); } const query = this.extend (params, { 'stopPrice': stopPrice }); return await this.createOrder (symbol, type, side, amount, price, query); @@ -2349,12 +2349,18 @@ module.exports = class Exchange { async createStopLimitOrder(symbol, side, amount, price, stopPrice, params = {}) { this.methodGuard ('createStopLimitOrder'); + if (stopPrice === undefined) { + throw new ArgumentsRequired(this.id + ' createStopLimitOrder() requires a stopPrice argument'); + } const query = this.extend(params, {'stopPrice': stopPrice}); return this.createOrder(symbol, 'limit', side, amount, price, query); } - + async createStopMarketOrder(symbol, side, amount, stopPrice, params = {}) { this.methodGuard ('createStopMarketOrder'); + if (stopPrice === undefined) { + throw new ArgumentsRequired(this.id + ' createStopMarketOrder() requires a stopPrice argument'); + } const query = this.extend(params, {'stopPrice': stopPrice}); return this.createOrder(symbol, 'market', side, amount, undefined, query); }