Skip to content

Commit

Permalink
1.10.523
Browse files Browse the repository at this point in the history
[ci skip]
  • Loading branch information
Travis CI committed Dec 30, 2017
1 parent 734d42e commit 89a8ba6
Show file tree
Hide file tree
Showing 11 changed files with 501 additions and 13 deletions.
133 changes: 130 additions & 3 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.522'
const version = '1.10.523'

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.522",
"version": "1.10.523",
"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.522';
$version = '1.10.523';

abstract class Exchange {

Expand Down
129 changes: 128 additions & 1 deletion php/btcmarkets.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ public function describe () {
'countries' => 'AU', // Australia
'rateLimit' => 1000, // market data cached for 1 second (trades cached for 2 seconds)
'hasCORS' => false,
'hasFetchOrder' => true,
'hasFetchOrders' => true,
'hasFetchClosedOrders' => true,
'hasFetchOpenOrders' => true,
'has' => array (
'fetchOrder' => true,
'fetchOrders' => true,
'fetchClosedOrders' => 'emulated',
'fetchOpenOrders' => true,
),
'urls' => array (
'logo' => 'https://user-images.githubusercontent.com/1294454/29142911-0e1acfc2-7d5c-11e7-98c4-07d9532b29d7.jpg',
'api' => 'https://api.btcmarkets.net',
Expand Down Expand Up @@ -185,14 +195,131 @@ public function cancel_order ($id, $symbol = null, $params = array ()) {
return $this->cancel_orders (array ( $id ));
}

public function parse_order_trade ($trade, $market) {
$multiplier = 100000000;
$timestamp = $trade['creationTime'];
$side = ($trade['side'] == 'Bid') ? 'buy' : 'sell';
return array (
'info' => $trade,
'id' => (string) $trade['id'],
'timestamp' => $timestamp,
'datetime' => $this->iso8601 ($timestamp),
'symbol' => $market['symbol'],
'type' => null,
'side' => $side,
'price' => $trade['price'] / $multiplier,
'fee' => $trade['fee'] / $multiplier,
'amount' => $trade['volume'] / $multiplier,
);
}

public function parse_order ($order, $market = null) {
$multiplier = 100000000;
$side = ($order['orderSide'] == 'Bid') ? 'buy' : 'sell';
$type = ($order['ordertype'] == 'Limit') ? 'limit' : 'market';
$timestamp = $order['creationTime'];
if (!$market) {
$market = $this->market ($order['instrument'] . '/' . $order['currency']);
}
$status = 'open';
if ($order['status'] == 'Failed' || $order['status'] == 'Cancelled' || $order['status'] == 'Partially Cancelled' || $order['status'] == 'Error') {
$status = 'canceled';
} else if ($order['status'] == "Fully Matched" || $order['status'] == "Partially Matched") {
$status = 'closed';
}
$price = $this->safe_float($order, 'price') / $multiplier;
$amount = $this->safe_float($order, 'volume') / $multiplier;
$remaining = $this->safe_float($order, 'openVolume', 0.0) / $multiplier;
$filled = $amount - $remaining;
$cost = $price * $amount;
$trades = array ();
for ($i = 0; $i < count ($order['trades']); $i++) {
$trade = $this->parse_order_trade ($order['trades'][$i], $market);
$trades[] = $trade;
}
$result = array (
'info' => $order,
'id' => (string) $order['id'],
'timestamp' => $timestamp,
'datetime' => $this->iso8601 ($timestamp),
'symbol' => $market['symbol'],
'type' => $type,
'side' => $side,
'price' => $price,
'cost' => $cost,
'amount' => $amount,
'filled' => $filled,
'remaining' => $remaining,
'status' => $status,
'trades' => $trades,
);
return $result;
}

public function fetch_order ($id, $symbol = null, $params = array ()) {
$this->load_markets();
$ids = array ( $id );
$response = $this->privatePostOrderDetail (array_merge (array (
'orderIds' => $ids,
), $params));
$numOrders = is_array ($response['orders']) ? count ($response['orders']) : 0;
if ($numOrders < 1)
throw new OrderNotFound ($this->id . ' No matching order found => ' . $id);
return $this->parse_order($response['orders'][0]);
}

public function prepare_orders_request ($market, $since = null, $limit = null, $params = array ()) {
$request = $this->ordered (array (
'currency' => $market['quote'],
'instrument' => $market['base'],
));
if ($limit) {
$request['limit'] = $limit;
} else {
$request['limit'] = 100;
}
if ($since) {
$request['since'] = $since;
} else {
$request['since'] = 0;
}
return $request;
}

public function fetch_orders ($symbol = null, $since = null, $limit = null, $params = array ()) {
if (!$symbol)
throw new NotSupported ($this->id . ' => fetchOrders requires a `$symbol` parameter.');
$this->load_markets();
$market = null;
$market = $this->market ($symbol);
$request = $this->prepare_orders_request ($market, $since, $limit, $params);
$response = $this->privatePostOrderHistory (array_merge ($request, $params));
return $this->parse_orders($response['orders'], $market);
}

public function fetch_open_orders ($symbol = null, $since = null, $limit = null, $params = array ()) {
if (!$symbol)
throw new NotSupported ($this->id . ' => fetchOpenOrders requires a `$symbol` parameter.');
$this->load_markets();
$market = null;
$market = $this->market ($symbol);
$request = $this->prepare_orders_request ($market, $since, $limit, $params);
$response = $this->privatePostOrderOpen (array_merge ($request, $params));
return $this->parse_orders($response['orders'], $market);
}

public function fetch_closed_orders ($symbol = null, $since = null, $limit = null, $params = array ()) {
$orders = $this->fetch_orders($symbol, $params);
return $this->filter_by($orders, 'status', 'closed');
}

public function nonce () {
return $this->milliseconds ();
}

public function sign ($path, $api = 'public', $method = 'GET', $params = array (), $headers = null, $body = null) {
$uri = '/' . $this->implode_params($path, $params);
$url = $this->urls['api'] . $uri;
// $query = $this->omit ($params, $this->extract_params($path));
if ($api == 'public') {
if ($params)
$url .= '?' . $this->urlencode ($params);
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.522'
__version__ = '1.10.523'

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

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.522'
__version__ = '1.10.523'

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

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.522'
__version__ = '1.10.523'

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

Expand Down
119 changes: 118 additions & 1 deletion python/ccxt/async/btcmarkets.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import base64
import hashlib
from ccxt.base.errors import ExchangeError
from ccxt.base.errors import NotSupported
from ccxt.base.errors import OrderNotFound


class btcmarkets (Exchange):
Expand All @@ -15,6 +17,16 @@ def describe(self):
'countries': 'AU', # Australia
'rateLimit': 1000, # market data cached for 1 second(trades cached for 2 seconds)
'hasCORS': False,
'hasFetchOrder': True,
'hasFetchOrders': True,
'hasFetchClosedOrders': True,
'hasFetchOpenOrders': True,
'has': {
'fetchOrder': True,
'fetchOrders': True,
'fetchClosedOrders': 'emulated',
'fetchOpenOrders': True,
},
'urls': {
'logo': 'https://user-images.githubusercontent.com/1294454/29142911-0e1acfc2-7d5c-11e7-98c4-07d9532b29d7.jpg',
'api': 'https://api.btcmarkets.net',
Expand Down Expand Up @@ -178,13 +190,118 @@ async def cancel_order(self, id, symbol=None, params={}):
await self.load_markets()
return await self.cancel_orders([id])

def parse_order_trade(self, trade, market):
multiplier = 100000000
timestamp = trade['creationTime']
side = 'buy' if (trade['side'] == 'Bid') else 'sell'
return {
'info': trade,
'id': str(trade['id']),
'timestamp': timestamp,
'datetime': self.iso8601(timestamp),
'symbol': market['symbol'],
'type': None,
'side': side,
'price': trade['price'] / multiplier,
'fee': trade['fee'] / multiplier,
'amount': trade['volume'] / multiplier,
}

def parse_order(self, order, market=None):
multiplier = 100000000
side = 'buy' if (order['orderSide'] == 'Bid') else 'sell'
type = 'limit' if (order['ordertype'] == 'Limit') else 'market'
timestamp = order['creationTime']
if not market:
market = self.market(order['instrument'] + '/' + order['currency'])
status = 'open'
if order['status'] == 'Failed' or order['status'] == 'Cancelled' or order['status'] == 'Partially Cancelled' or order['status'] == 'Error':
status = 'canceled'
elif order['status'] == "Fully Matched" or order['status'] == "Partially Matched":
status = 'closed'
price = self.safe_float(order, 'price') / multiplier
amount = self.safe_float(order, 'volume') / multiplier
remaining = self.safe_float(order, 'openVolume', 0.0) / multiplier
filled = amount - remaining
cost = price * amount
trades = []
for i in range(0, len(order['trades'])):
trade = self.parse_order_trade(order['trades'][i], market)
trades.append(trade)
result = {
'info': order,
'id': str(order['id']),
'timestamp': timestamp,
'datetime': self.iso8601(timestamp),
'symbol': market['symbol'],
'type': type,
'side': side,
'price': price,
'cost': cost,
'amount': amount,
'filled': filled,
'remaining': remaining,
'status': status,
'trades': trades,
}
return result

async def fetch_order(self, id, symbol=None, params={}):
await self.load_markets()
ids = [id]
response = await self.privatePostOrderDetail(self.extend({
'orderIds': ids,
}, params))
numOrders = len(response['orders'])
if numOrders < 1:
raise OrderNotFound(self.id + ' No matching order found: ' + id)
return self.parse_order(response['orders'][0])

async def prepare_orders_request(self, market, since=None, limit=None, params={}):
request = self.ordered({
'currency': market['quote'],
'instrument': market['base'],
})
if limit:
request['limit'] = limit
else:
request['limit'] = 100
if since:
request['since'] = since
else:
request['since'] = 0
return request

async def fetch_orders(self, symbol=None, since=None, limit=None, params={}):
if not symbol:
raise NotSupported(self.id + ': fetchOrders requires a `symbol` parameter.')
await self.load_markets()
market = None
market = self.market(symbol)
request = self.prepare_orders_request(market, since, limit, params)
response = await self.privatePostOrderHistory(self.extend(request, params))
return self.parse_orders(response['orders'], market)

async def fetch_open_orders(self, symbol=None, since=None, limit=None, params={}):
if not symbol:
raise NotSupported(self.id + ': fetchOpenOrders requires a `symbol` parameter.')
await self.load_markets()
market = None
market = self.market(symbol)
request = self.prepare_orders_request(market, since, limit, params)
response = await self.privatePostOrderOpen(self.extend(request, params))
return self.parse_orders(response['orders'], market)

async def fetch_closed_orders(self, symbol=None, since=None, limit=None, params={}):
orders = await self.fetch_orders(symbol, params)
return self.filter_by(orders, 'status', 'closed')

def nonce(self):
return self.milliseconds()

def sign(self, path, api='public', method='GET', params={}, headers=None, body=None):
uri = '/' + self.implode_params(path, params)
url = self.urls['api'] + uri
# query = self.omit(params, self.extract_params(path))
if api == 'public':
if params:
url += '?' + self.urlencode(params)
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.522'
__version__ = '1.10.523'

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

Expand Down
Loading

0 comments on commit 89a8ba6

Please sign in to comment.