Skip to content

Commit

Permalink
1.10.690
Browse files Browse the repository at this point in the history
[ci skip]
  • Loading branch information
Travis CI committed Jan 13, 2018
1 parent 7391ee7 commit b8170c9
Show file tree
Hide file tree
Showing 14 changed files with 247 additions and 157 deletions.
128 changes: 76 additions & 52 deletions build/ccxt.browser.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ccxt.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const errors = require ('./js/base/errors')
//-----------------------------------------------------------------------------
// this is updated by vss.js when building

const version = '1.10.689'
const version = '1.10.690'

Exchange.ccxtVersion = version

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ccxt",
"version": "1.10.689",
"version": "1.10.690",
"description": "A JavaScript / Python / PHP cryptocurrency trading library with support for 90+ exchanges",
"main": "./ccxt.js",
"unpkg": "build/ccxt.browser.js",
Expand Down
2 changes: 1 addition & 1 deletion php/Exchange.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

namespace ccxt;

$version = '1.10.689';
$version = '1.10.690';

abstract class Exchange {

Expand Down
101 changes: 57 additions & 44 deletions php/bitfinex.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,20 @@ public function fetch_markets () {
'price' => $market['price_precision'],
'amount' => $market['price_precision'],
);
$limits = array (
'amount' => array (
'min' => floatval ($market['minimum_order_size']),
'max' => floatval ($market['maximum_order_size']),
),
'price' => array (
'min' => pow (10, -$precision['price']),
'max' => pow (10, $precision['price']),
),
);
$limits['cost'] = array (
'min' => $limits['amount']['min'] * $limits['price']['min'],
'max' => null,
);
$result[] = array_merge ($this->fees['trading'], array (
'id' => $id,
'symbol' => $symbol,
Expand All @@ -244,22 +258,10 @@ public function fetch_markets () {
'baseId' => $baseId,
'quoteId' => $quoteId,
'active' => true,
'info' => $market,
'precision' => $precision,
'limits' => array (
'amount' => array (
'min' => floatval ($market['minimum_order_size']),
'max' => floatval ($market['maximum_order_size']),
),
'price' => array (
'min' => pow (10, -$precision['price']),
'max' => pow (10, $precision['price']),
),
'cost' => array (
'min' => null,
'max' => null,
),
),
'limits' => $limits,
'lot' => pow (10, -$precision['amount']),
'info' => $market,
));
}
return $result;
Expand All @@ -272,7 +274,7 @@ public function fetch_balance ($params = array ()) {
$result = array ( 'info' => $balances );
for ($i = 0; $i < count ($balances); $i++) {
$balance = $balances[$i];
if ($balance['type'] == $balanceType) {
if ($balance['type'] === $balanceType) {
$currency = $balance['currency'];
$uppercase = strtoupper ($currency);
$uppercase = $this->common_currency_code($uppercase);
Expand Down Expand Up @@ -410,7 +412,7 @@ public function fetch_my_trades ($symbol = null, $since = null, $limit = null, $
public function create_order ($symbol, $type, $side, $amount, $price = null, $params = array ()) {
$this->load_markets();
$orderType = $type;
if (($type == 'limit') || ($type == 'market'))
if (($type === 'limit') || ($type === 'market'))
$orderType = 'exchange ' . $type;
// $amount = $this->amount_to_precision($symbol, $amount);
$order = array (
Expand All @@ -422,7 +424,7 @@ public function create_order ($symbol, $type, $side, $amount, $price = null, $pa
'buy_price_oco' => 0,
'sell_price_oco' => 0,
);
if ($type == 'market') {
if ($type === 'market') {
$order['price'] = (string) $this->nonce ();
} else {
// $price = $this->price_to_precision($symbol, $price);
Expand Down Expand Up @@ -543,31 +545,31 @@ public function fetch_ohlcv ($symbol, $timeframe = '1m', $since = null, $limit =
}

public function get_currency_name ($currency) {
if ($currency == 'BTC') {
if ($currency === 'BTC') {
return 'bitcoin';
} else if ($currency == 'LTC') {
} else if ($currency === 'LTC') {
return 'litecoin';
} else if ($currency == 'ETH') {
} else if ($currency === 'ETH') {
return 'ethereum';
} else if ($currency == 'ETC') {
} else if ($currency === 'ETC') {
return 'ethereumc';
} else if ($currency == 'OMNI') {
} else if ($currency === 'OMNI') {
return 'mastercoin'; // ???
} else if ($currency == 'ZEC') {
} else if ($currency === 'ZEC') {
return 'zcash';
} else if ($currency == 'XMR') {
} else if ($currency === 'XMR') {
return 'monero';
} else if ($currency == 'USD') {
} else if ($currency === 'USD') {
return 'wire';
} else if ($currency == 'DASH') {
} else if ($currency === 'DASH') {
return 'dash';
} else if ($currency == 'XRP') {
} else if ($currency === 'XRP') {
return 'ripple';
} else if ($currency == 'EOS') {
} else if ($currency === 'EOS') {
return 'eos';
} else if ($currency == 'BCH') {
} else if ($currency === 'BCH') {
return 'bcash';
} else if ($currency == 'USDT') {
} else if ($currency === 'USDT') {
return 'tetheruso';
}
throw new NotSupported ($this->id . ' ' . $currency . ' not supported for withdrawal');
Expand Down Expand Up @@ -623,21 +625,21 @@ public function nonce () {

public function sign ($path, $api = 'public', $method = 'GET', $params = array (), $headers = null, $body = null) {
$request = '/' . $this->implode_params($path, $params);
if ($api == 'v2') {
if ($api === 'v2') {
$request = '/' . $api . $request;
} else {
$request = '/' . $this->version . $request;
}
$query = $this->omit ($params, $this->extract_params($path));
$url = $this->urls['api'] . $request;
if (($api == 'public') || (mb_strpos ($path, '/hist') !== false)) {
if (($api === 'public') || (mb_strpos ($path, '/hist') !== false)) {
if ($query) {
$suffix = '?' . $this->urlencode ($query);
$url .= $suffix;
$request .= $suffix;
}
}
if ($api == 'private') {
if ($api === 'private') {
$this->check_required_credentials();
$nonce = $this->nonce ();
$query = array_merge (array (
Expand All @@ -659,18 +661,29 @@ public function sign ($path, $api = 'public', $method = 'GET', $params = array (
}

public function handle_errors ($code, $reason, $url, $method, $headers, $body) {
if ($code == 400) {
if ($body[0] == "{") {
if ($code >= 400) {
if ($body[0] === "{") {
$response = json_decode ($body, $as_associative_array = true);
$message = $response['message'];
if (mb_strpos ($message, 'Key price should be a decimal number') !== false) {
throw new InvalidOrder ($this->id . ' ' . $message);
} else if (mb_strpos ($message, 'Invalid order => not enough exchange balance') !== false) {
throw new InsufficientFunds ($this->id . ' ' . $message);
} else if (mb_strpos ($message, 'Invalid order') !== false) {
throw new InvalidOrder ($this->id . ' ' . $message);
} else if (mb_strpos ($message, 'Order could not be cancelled.') !== false) {
throw new OrderNotFound ($this->id . ' ' . $message);
$error = $this->id . ' ' . $message;
if ($code === 400) {
if (mb_strpos ($message, 'Key price should be a decimal number') !== false) {
throw new InvalidOrder ($error);
} else if (mb_strpos ($message, 'Invalid order => not enough exchange balance') !== false) {
throw new InsufficientFunds ($error);
} else if (mb_strpos ($message, 'Order could not be cancelled.') !== false) {
throw new OrderNotFound ($error);
} else if (mb_strpos ($message, 'Invalid order') !== false) {
throw new InvalidOrder ($error);
} else if (mb_strpos ($message, 'Order price must be positive.') !== false) {
throw new InvalidOrder ($error);
} else if (mb_strpos ($message, 'Key amount should be a decimal number') !== false) {
throw new InvalidOrder ($error);
}
} else if ($code === 404) {
if (mb_strpos ($message, 'No such order found.') !== false) {
throw new OrderNotFound ($error);
}
}
}
throw new ExchangeError ($this->id . ' ' . $body);
Expand Down
15 changes: 13 additions & 2 deletions php/kucoin.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,22 @@ public function parse_order ($order, $market = null) {
$symbol = $order['coinType'] . '/' . $order['coinTypePair'];
}
$timestamp = $order['createdAt'];
$price = $order['price'];
$price = $this->safe_value($order, 'price');
if ($price === null)
$price = $this->safe_value($order, 'dealPrice');
$filled = $order['dealAmount'];
$remaining = $order['pendingAmount'];
$amount = $this->sum ($filled, $remaining);
$side = strtolower ($order['direction']);
$fee = null;
if (is_array ($order) && array_key_exists ('fee', $order)) {
$fee = array (
'cost' => $this->safe_float($order, 'fee'),
'rate' => $this->safe_float($order, 'feeRate'),
);
if ($market)
$fee['currency'] = $market['base'];
}
$result = array (
'info' => $order,
'id' => $this->safe_string($order, 'oid'),
Expand All @@ -312,7 +323,7 @@ public function parse_order ($order, $market = null) {
'filled' => $filled,
'remaining' => $remaining,
'status' => null,
'fee' => $this->safe_float($order, 'fee'),
'fee' => $fee,
);
return $result;
}
Expand Down
2 changes: 1 addition & 1 deletion python/ccxt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

# ----------------------------------------------------------------------------

__version__ = '1.10.689'
__version__ = '1.10.690'

# ----------------------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion python/ccxt/async/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# -----------------------------------------------------------------------------

__version__ = '1.10.689'
__version__ = '1.10.690'

# -----------------------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion python/ccxt/async/base/exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# -----------------------------------------------------------------------------

__version__ = '1.10.689'
__version__ = '1.10.690'

# -----------------------------------------------------------------------------

Expand Down
59 changes: 35 additions & 24 deletions python/ccxt/async/bitfinex.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,20 @@ async def fetch_markets(self):
'price': market['price_precision'],
'amount': market['price_precision'],
}
limits = {
'amount': {
'min': float(market['minimum_order_size']),
'max': float(market['maximum_order_size']),
},
'price': {
'min': math.pow(10, -precision['price']),
'max': math.pow(10, precision['price']),
},
}
limits['cost'] = {
'min': limits['amount']['min'] * limits['price']['min'],
'max': None,
}
result.append(self.extend(self.fees['trading'], {
'id': id,
'symbol': symbol,
Expand All @@ -252,22 +266,10 @@ async def fetch_markets(self):
'baseId': baseId,
'quoteId': quoteId,
'active': True,
'info': market,
'precision': precision,
'limits': {
'amount': {
'min': float(market['minimum_order_size']),
'max': float(market['maximum_order_size']),
},
'price': {
'min': math.pow(10, -precision['price']),
'max': math.pow(10, precision['price']),
},
'cost': {
'min': None,
'max': None,
},
},
'limits': limits,
'lot': math.pow(10, -precision['amount']),
'info': market,
}))
return result

Expand Down Expand Up @@ -624,18 +626,27 @@ def sign(self, path, api='public', method='GET', params={}, headers=None, body=N
return {'url': url, 'method': method, 'body': body, 'headers': headers}

def handle_errors(self, code, reason, url, method, headers, body):
if code == 400:
if code >= 400:
if body[0] == "{":
response = json.loads(body)
message = response['message']
if message.find('Key price should be a decimal number') >= 0:
raise InvalidOrder(self.id + ' ' + message)
elif message.find('Invalid order: not enough exchange balance') >= 0:
raise InsufficientFunds(self.id + ' ' + message)
elif message.find('Invalid order') >= 0:
raise InvalidOrder(self.id + ' ' + message)
elif message.find('Order could not be cancelled.') >= 0:
raise OrderNotFound(self.id + ' ' + message)
error = self.id + ' ' + message
if code == 400:
if message.find('Key price should be a decimal number') >= 0:
raise InvalidOrder(error)
elif message.find('Invalid order: not enough exchange balance') >= 0:
raise InsufficientFunds(error)
elif message.find('Order could not be cancelled.') >= 0:
raise OrderNotFound(error)
elif message.find('Invalid order') >= 0:
raise InvalidOrder(error)
elif message.find('Order price must be positive.') >= 0:
raise InvalidOrder(error)
elif message.find('Key amount should be a decimal number') >= 0:
raise InvalidOrder(error)
elif code == 404:
if message.find('No such order found.') >= 0:
raise OrderNotFound(error)
raise ExchangeError(self.id + ' ' + body)

async def request(self, path, api='public', method='GET', params={}, headers=None, body=None):
Expand Down
14 changes: 12 additions & 2 deletions python/ccxt/async/kucoin.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,21 @@ def parse_order(self, order, market=None):
else:
symbol = order['coinType'] + '/' + order['coinTypePair']
timestamp = order['createdAt']
price = order['price']
price = self.safe_value(order, 'price')
if price is None:
price = self.safe_value(order, 'dealPrice')
filled = order['dealAmount']
remaining = order['pendingAmount']
amount = self.sum(filled, remaining)
side = order['direction'].lower()
fee = None
if 'fee' in order:
fee = {
'cost': self.safe_float(order, 'fee'),
'rate': self.safe_float(order, 'feeRate'),
}
if market:
fee['currency'] = market['base']
result = {
'info': order,
'id': self.safe_string(order, 'oid'),
Expand All @@ -312,7 +322,7 @@ def parse_order(self, order, market=None):
'filled': filled,
'remaining': remaining,
'status': None,
'fee': self.safe_float(order, 'fee'),
'fee': fee,
}
return result

Expand Down
2 changes: 1 addition & 1 deletion python/ccxt/base/exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# -----------------------------------------------------------------------------

__version__ = '1.10.689'
__version__ = '1.10.690'

# -----------------------------------------------------------------------------

Expand Down
Loading

0 comments on commit b8170c9

Please sign in to comment.