Skip to content

Commit

Permalink
1.14.140
Browse files Browse the repository at this point in the history
[ci skip]
  • Loading branch information
Travis CI committed Jun 5, 2018
1 parent e6281c7 commit 12fb141
Show file tree
Hide file tree
Showing 11 changed files with 335 additions and 147 deletions.
127 changes: 90 additions & 37 deletions build/ccxt.browser.js

Large diffs are not rendered by default.

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

const version = '1.14.139'
const version = '1.14.140'

Exchange.ccxtVersion = version

Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "ccxt",
"version": "1.14.139",
"version": "1.14.140",
"description": "A JavaScript / Python / PHP cryptocurrency trading library with support for 100+ exchanges",
"main": "./ccxt.js",
"unpkg": "build/ccxt.browser.js",
Expand Down
2 changes: 1 addition & 1 deletion php/Exchange.php
Expand Up @@ -30,7 +30,7 @@

namespace ccxt;

$version = '1.14.139';
$version = '1.14.140';

// rounding mode
const TRUNCATE = 0;
Expand Down
123 changes: 88 additions & 35 deletions php/livecoin.php
Expand Up @@ -23,6 +23,7 @@ public function describe () {
'fetchCurrencies' => true,
'fetchTradingFees' => true,
'fetchOrders' => true,
'fetchOrder' => true,
'fetchOpenOrders' => true,
'fetchClosedOrders' => true,
'withdraw' => true,
Expand Down Expand Up @@ -379,63 +380,115 @@ public function fetch_trades ($symbol, $since = null, $limit = null, $params = a
return $this->parse_trades($response, $market, $since, $limit);
}

public function fetch_order ($id, $symbol = null, $params = array ()) {
$this->load_markets();
$request = array (
'orderId' => $id,
);
$response = $this->privateGetExchangeOrder (array_merge ($request, $params));
return $this->parse_order($response);
}

public function parse_order_status ($status) {
$statuses = array (
'OPEN' => 'open',
'PARTIALLY_FILLED' => 'open',
'EXECUTED' => 'closed',
'PARTIALLY_FILLED_AND_CANCELLED' => 'canceled',
);
if (is_array ($statuses) && array_key_exists ($status, $statuses))
return $statuses[$status];
return $status;
}

public function parse_order ($order, $market = null) {
$timestamp = $this->safe_integer($order, 'lastModificationTime');
if (!$timestamp)
$timestamp = $this->parse8601 ($order['lastModificationTime']);
$timestamp = null;
$datetime = null;
if (is_array ($order) && array_key_exists ('lastModificationTime', $order)) {
$timestamp = $this->safe_string($order, 'lastModificationTime');
if ($timestamp !== null) {
if (mb_strpos ($timestamp, 'T') !== false) {
$timestamp = $this->parse8601 ($timestamp);
} else {
$timestamp = $this->safe_integer($order, 'lastModificationTime');
}
}
}
if ($timestamp) {
$datetime = $this->iso8601 ($timestamp);
}
// TODO currently not supported by livecoin
// $trades = $this->parse_trades($order['trades'], $market, since, limit);
$trades = null;
if (is_array ($order) && array_key_exists ('trades', $order))
// TODO currently not supported by livecoin
// $trades = $this->parse_trades($order['trades'], $market, since, limit);
$trades = null;
$status = null;
if ($order['orderStatus'] === 'OPEN' || $order['orderStatus'] === 'PARTIALLY_FILLED') {
$status = 'open';
} else if ($order['orderStatus'] === 'EXECUTED' || $order['orderStatus'] === 'PARTIALLY_FILLED_AND_CANCELLED') {
$status = 'closed';
} else {
$status = 'canceled';
$status = $this->safe_string($order, 'status');
$status = $this->safe_string($order, 'orderStatus', $status);
$status = $this->parse_order_status($status);
$symbol = null;
if ($market === null) {
$marketId = $this->safe_string($order, 'currencyPair');
$marketId = $this->safe_string($order, 'symbol', $marketId);
if (is_array ($this->markets_by_id) && array_key_exists ($marketId, $this->markets_by_id))
$market = $this->markets_by_id[$marketId];
}
$symbol = $order['currencyPair'];
$parts = explode ('/', $symbol);
$quote = $parts[1];
// list ($base, $quote) = explode ('/', $symbol);
$type = null;
$side = null;
if (mb_strpos ($order['type'], 'MARKET') !== false) {
$type = 'market';
} else {
$type = 'limit';
}
if (mb_strpos ($order['type'], 'SELL') !== false) {
$side = 'sell';
} else {
$side = 'buy';
if (is_array ($order) && array_key_exists ('type', $order)) {
$orderType = strtolower (explode ('_', $order['type']));
$type = $orderType[0];
$side = $orderType[1];
}
$price = $this->safe_float($order, 'price', 0.0);
$cost = $this->safe_float($order, 'commissionByTrade', 0.0);
$remaining = $this->safe_float($order, 'remainingQuantity', 0.0);
$price = $this->safe_float($order, 'price');
// of the next two lines the latter overrides the former, if present in the $order structure
$remaining = $this->safe_float($order, 'remainingQuantity');
$remaining = $this->safe_float($order, 'remaining_quantity', $remaining);
$amount = $this->safe_float($order, 'quantity', $remaining);
$filled = $amount - $remaining;
$filled = null;
if ($remaining !== null) {
$filled = $amount - $remaining;
}
$cost = null;
if ($status === 'open') {
if ($filled !== null && $amount !== null && $price !== null) {
$cost = $amount * $price;
}
} else if ($status === 'closed' || $status === 'canceled') {
if ($filled !== null && $price !== null) {
$cost = $filled * $price;
}
}
if ($cost !== null) {
return null;
}
$feeRate = $this->safe_float($order, 'commission_rate');
$feeCost = null;
if ($cost !== null) {
$feeCost = $cost * $feeRate;
}
$feeCurrency = null;
if ($market !== null) {
$symbol = $market['symbol'];
$feeCurrency = $market['quote'];
}
return array (
'info' => $order,
'id' => $order['id'],
'timestamp' => $timestamp,
'datetime' => $this->iso8601 ($timestamp),
'datetime' => $datetime,
'lastTradeTimestamp' => null,
'status' => $status,
'symbol' => $symbol,
'type' => $type,
'side' => $side,
'price' => $price,
'cost' => $cost,
'amount' => $amount,
'cost' => $cost,
'filled' => $filled,
'remaining' => $remaining,
'trades' => $trades,
'fee' => array (
'cost' => $cost,
'currency' => $quote,
'cost' => $feeCost,
'currency' => $feeCurrency,
'rate' => $feeRate,
),
);
}
Expand Down
2 changes: 1 addition & 1 deletion python/ccxt/__init__.py
Expand Up @@ -22,7 +22,7 @@

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

__version__ = '1.14.139'
__version__ = '1.14.140'

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

Expand Down
2 changes: 1 addition & 1 deletion python/ccxt/async/__init__.py
Expand Up @@ -4,7 +4,7 @@

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

__version__ = '1.14.139'
__version__ = '1.14.140'

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

Expand Down
2 changes: 1 addition & 1 deletion python/ccxt/async/base/exchange.py
Expand Up @@ -2,7 +2,7 @@

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

__version__ = '1.14.139'
__version__ = '1.14.140'

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

Expand Down
109 changes: 75 additions & 34 deletions python/ccxt/async/livecoin.py
Expand Up @@ -40,6 +40,7 @@ def describe(self):
'fetchCurrencies': True,
'fetchTradingFees': True,
'fetchOrders': True,
'fetchOrder': True,
'fetchOpenOrders': True,
'fetchClosedOrders': True,
'withdraw': True,
Expand Down Expand Up @@ -378,60 +379,100 @@ async def fetch_trades(self, symbol, since=None, limit=None, params={}):
}, params))
return self.parse_trades(response, market, since, limit)

async def fetch_order(self, id, symbol=None, params={}):
await self.load_markets()
request = {
'orderId': id,
}
response = await self.privateGetExchangeOrder(self.extend(request, params))
return self.parse_order(response)

def parse_order_status(self, status):
statuses = {
'OPEN': 'open',
'PARTIALLY_FILLED': 'open',
'EXECUTED': 'closed',
'PARTIALLY_FILLED_AND_CANCELLED': 'canceled',
}
if status in statuses:
return statuses[status]
return status

def parse_order(self, order, market=None):
timestamp = self.safe_integer(order, 'lastModificationTime')
if not timestamp:
timestamp = self.parse8601(order['lastModificationTime'])
timestamp = None
datetime = None
if 'lastModificationTime' in order:
timestamp = self.safe_string(order, 'lastModificationTime')
if timestamp is not None:
if timestamp.find('T') >= 0:
timestamp = self.parse8601(timestamp)
else:
timestamp = self.safe_integer(order, 'lastModificationTime')
if timestamp:
datetime = self.iso8601(timestamp)
# TODO currently not supported by livecoin
# trades = self.parse_trades(order['trades'], market, since, limit)
trades = None
if 'trades' in order:
# TODO currently not supported by livecoin
# trades = self.parse_trades(order['trades'], market, since, limit)
trades = None
status = None
if order['orderStatus'] == 'OPEN' or order['orderStatus'] == 'PARTIALLY_FILLED':
status = 'open'
elif order['orderStatus'] == 'EXECUTED' or order['orderStatus'] == 'PARTIALLY_FILLED_AND_CANCELLED':
status = 'closed'
else:
status = 'canceled'
symbol = order['currencyPair']
parts = symbol.split('/')
quote = parts[1]
# base, quote = symbol.split('/')
status = self.safe_string(order, 'status')
status = self.safe_string(order, 'orderStatus', status)
status = self.parse_order_status(status)
symbol = None
if market is None:
marketId = self.safe_string(order, 'currencyPair')
marketId = self.safe_string(order, 'symbol', marketId)
if marketId in self.markets_by_id:
market = self.markets_by_id[marketId]
type = None
side = None
if order['type'].find('MARKET') >= 0:
type = 'market'
else:
type = 'limit'
if order['type'].find('SELL') >= 0:
side = 'sell'
else:
side = 'buy'
price = self.safe_float(order, 'price', 0.0)
cost = self.safe_float(order, 'commissionByTrade', 0.0)
remaining = self.safe_float(order, 'remainingQuantity', 0.0)
if 'type' in order:
orderType = order['type'].lower().split('_')
type = orderType[0]
side = orderType[1]
price = self.safe_float(order, 'price')
# of the next two lines the latter overrides the former, if present in the order structure
remaining = self.safe_float(order, 'remainingQuantity')
remaining = self.safe_float(order, 'remaining_quantity', remaining)
amount = self.safe_float(order, 'quantity', remaining)
filled = amount - remaining
filled = None
if remaining is not None:
filled = amount - remaining
cost = None
if status == 'open':
if filled is not None and amount is not None and price is not None:
cost = amount * price
elif status == 'closed' or status == 'canceled':
if filled is not None and price is not None:
cost = filled * price
if cost is not None:
return None
feeRate = self.safe_float(order, 'commission_rate')
feeCost = None
if cost is not None:
feeCost = cost * feeRate
feeCurrency = None
if market is not None:
symbol = market['symbol']
feeCurrency = market['quote']
return {
'info': order,
'id': order['id'],
'timestamp': timestamp,
'datetime': self.iso8601(timestamp),
'datetime': datetime,
'lastTradeTimestamp': None,
'status': status,
'symbol': symbol,
'type': type,
'side': side,
'price': price,
'cost': cost,
'amount': amount,
'cost': cost,
'filled': filled,
'remaining': remaining,
'trades': trades,
'fee': {
'cost': cost,
'currency': quote,
'cost': feeCost,
'currency': feeCurrency,
'rate': feeRate,
},
}

Expand Down
2 changes: 1 addition & 1 deletion python/ccxt/base/exchange.py
Expand Up @@ -4,7 +4,7 @@

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

__version__ = '1.14.139'
__version__ = '1.14.140'

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

Expand Down

0 comments on commit 12fb141

Please sign in to comment.