Skip to content

Commit

Permalink
limitPriceToPrecision + limitAmountToPrecision
Browse files Browse the repository at this point in the history
  • Loading branch information
kroitor committed Oct 8, 2017
1 parent 64fb1a5 commit f0c3e8a
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
12 changes: 11 additions & 1 deletion ccxt.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,6 @@ const Exchange = function (config) {
this.base64ToString = base64ToString
this.binaryToString = binaryToString
this.utf16ToBase64 = utf16ToBase64

this.encodeURIComponent = encodeURIComponent
this.urlencode = urlencode
this.omit = omit
Expand Down Expand Up @@ -779,6 +778,14 @@ const Exchange = function (config) {
return currency
}

this.limitPriceToPrecision = function (symbol, price) {
return price.toFixed (this.markets[symbol].precision.price)
}

this.limitAmountToPrecision = function (symbol, amount) {
return amount.toFixed (this.markets[symbol].precision.amount)
}

this.market = function (symbol) {
return (((typeof symbol === 'string') &&
(typeof this.markets != 'undefined') &&
Expand Down Expand Up @@ -1049,6 +1056,8 @@ const Exchange = function (config) {
this.calculate_fee = this.calculateFee
this.calculate_fee_rate = this.calculateFeeRate
this.common_currency_code = this.commonCurrencyCode
this.limit_price_to_precision = this.limitPriceToPrecision
this.limit_amount_to_precision = this.limitAmountToPrecision

this.init ()
}
Expand Down Expand Up @@ -3102,6 +3111,7 @@ var bitfinex = {
'hasCORS': false,
'hasFetchOrder': true,
'hasFetchTickers': false,
'hasDeposit': true,
'hasWithdraw': true,
'urls': {
'logo': 'https://user-images.githubusercontent.com/1294454/27766244-e328a50c-5ed2-11e7-947b-041416579bb3.jpg',
Expand Down
16 changes: 16 additions & 0 deletions ccxt.php
Original file line number Diff line number Diff line change
Expand Up @@ -1204,6 +1204,22 @@ public function common_currency_code ($currency) {
return $currency;
}

public function limit_price_to_precision ($symbol, $price) {
return sprintf ('%.' . $this->markets[$symbol]['precision']['price'] . 'f', $price);
}

public function limitPriceToPrecision ($symbol, $price) {
return $this->limit_price_to_precision ($symbol, $price);
}

public function limit_amount_to_precision ($symbol, $amount) {
return sprintf ('%.' . $this->markets[$symbol]['precision']['amount'] . 'f', $amount);
}

public function limitAmountToPrecision ($symbol, $amount) {
return $this->limit_amount_to_precision ($symbol, $amount);
}

public function commonCurrencyCode ($currency) {
return $this->common_currency_code ($currency);
}
Expand Down
12 changes: 12 additions & 0 deletions ccxt/exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,18 @@ def common_currency_code(self, currency):
return 'DASH'
return currency

def limit_price_to_precision(self, symbol, price):
return ('{:.' + str(self.markets[symbol]['precision']['price']) + 'f}').format(price)

def limitPriceToPrecision(self, symbol, price):
return self.limit_price_to_precision(symbol, price)

def limit_amount_to_precision(self, symbol, amount):
return ('{:.' + str(self.markets[symbol]['precision']['amount']) + 'f}').format(amount)

def limitAmountToPrecision(self, symbol, amount):
return self.limit_amount_to_precision(symbol, amount)

def commonCurrencyCode(self, currency):
return self.common_currency_code(currency)

Expand Down
6 changes: 6 additions & 0 deletions transpile.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ while (exchanges = regex.exec (contents)) {

method = method.replace ('fetchBalance', 'fetch_balance')
// .replace ('fetchCategories', 'fetch_categories')
.replace ('limitPriceToPrecision', 'limit_price_to_precision')
.replace ('limitAmountToPrecision', 'limit_amount_to_precision')
.replace ('commonCurrencyCode', 'common_currency_code')
.replace ('loadMarkets', 'load_markets')
.replace ('fetchMarkets', 'fetch_markets')
Expand Down Expand Up @@ -208,6 +210,8 @@ while (exchanges = regex.exec (contents)) {
[ /\.fetchOrder\s/g, '.fetch_order'],
[ /\.fetchTickers\s/g, '.fetch_tickers'],
[ /\.fetchTicker\s/g, '.fetch_ticker'],
[ /\.limitPriceToPrecision\s/g, '.limit_price_to_precision'],
[ /\.limitAmountToPrecision\s/g, '.limit_amount_to_precision'],
[ /\.commonCurrencyCode\s/g, '.common_currency_code'],
[ /\.loadMarkets\s/g, '.load_markets'],
[ /\.calculateFeeRate\s/g, '.calculate_fee_rate'],
Expand Down Expand Up @@ -326,6 +330,8 @@ while (exchanges = regex.exec (contents)) {
[ /\.parseOrders/g, '.parse_orders'],
[ /\.parseOrderStatus/g, '.parse_order_status'],
[ /\.parseOrder/g, '.parse_order'],
[ /\.limitPriceToPrecision/g, '.limit_price_to_precision'],
[ /\.limitAmountToPrecision/g, '.limit_amount_to_precision'],
[ /\.commonCurrencyCode/g, '.common_currency_code'],
[ /\.loadMarkets/g, '.load_markets'],
[ /\.calculateFeeRate/g, '.calculate_fee_rate'],
Expand Down

0 comments on commit f0c3e8a

Please sign in to comment.