Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/ccxt/ccxt into btcmarkets…
Browse files Browse the repository at this point in the history
…-orders

# Conflicts:
#	js/btcmarkets.js
  • Loading branch information
cogat committed Dec 30, 2017
2 parents ab031a0 + 89a8ba6 commit 5cb02f5
Show file tree
Hide file tree
Showing 13 changed files with 563 additions and 63 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.521'
const version = '1.10.523'

Exchange.ccxtVersion = version

Expand Down
53 changes: 25 additions & 28 deletions js/btcmarkets.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,9 @@ module.exports = class btcmarkets extends Exchange {

parseMyTrades (trades, market = undefined, since = undefined, limit = undefined) {
let result = [];
for (let i=0; i < trades.length; i++) {
result.push (this.parseMyTrade (trades[i], market));
for (let i = 0; i < trades.length; i++) {
let trade = this.parseMyTrade (trades[i], market);
result.push (trade);
}
return result;
}
Expand All @@ -242,7 +243,7 @@ module.exports = class btcmarkets extends Exchange {
let type = (order['ordertype'] == 'Limit') ? 'limit' : 'market';
let timestamp = order['creationTime'];
if (!market) {
market = this.market(order['instrument'] + "/" + order['currency']);
market = this.market (order['instrument'] + '/' + order['currency']);
}
let status = 'open';
if (order['status'] == 'Failed' || order['status'] == 'Cancelled' || order['status'] == 'Partially Cancelled' || order['status'] == 'Error') {
Expand Down Expand Up @@ -278,15 +279,18 @@ module.exports = class btcmarkets extends Exchange {

async fetchOrder (id, symbol = undefined, params = {}) {
await this.loadMarkets ();
let response = await this.privatePostOrderDetail (this.extend ({ 'orderIds': [id] }, params));
if (response['orders'].length == 0) {
let ids = [ id ];
let response = await this.privatePostOrderDetail (this.extend ({
'orderIds': ids,
}, params));
let numOrders = response['orders'].length;
if (numOrders < 1)
throw new OrderNotFound (this.id + ' No matching order found: ' + id);
}
return this.parseOrder (response['orders'][0]);
}

async prepHistoryRequest (market, since = undefined, limit = undefined) {
let request = this.ordered({
async prepareHistoryRequest (market, since = undefined, limit = undefined) {
let request = this.ordered ({
'currency': market['quote'],
'instrument': market['base'],
});
Expand All @@ -304,42 +308,35 @@ module.exports = class btcmarkets extends Exchange {
}

async fetchOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) {
await this.loadMarkets();
let market = undefined;
if (!symbol) {
if (!symbol)
throw new NotSupported (this.id + ': fetchOrders requires a `symbol` parameter.');
}
market = this.market(symbol);
let request = this.prepHistoryRequest(market, since, limit);
await this.loadMarkets ();
let market = this.market (symbol);
let request = this.prepareHistoryRequest (market, since, limit);
let response = await this.privatePostOrderHistory (this.extend (request, params));
return this.parseOrders (response['orders'], market);
}

async fetchOpenOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) {
await this.loadMarkets();
let market = undefined;
if (!symbol) {
throw new NotSupported (this.id + ': fetchOrders requires a `symbol` parameter.');
}
market = this.market(symbol);
let request = this.prepHistoryRequest(market, since, limit);
if (!symbol)
throw new NotSupported (this.id + ': fetchOpenOrders requires a `symbol` parameter.');
await this.loadMarkets ();
let market = this.market(symbol);
let request = this.prepareHistoryRequest (market, since, limit);
let response = await this.privatePostOrderOpen (this.extend (request, params));
return this.parseOrders (response['orders'], market);
}

async fetchClosedOrders (symbol = undefined, since = undefined, limit = undefined, params = {}) {
let orders = await this.fetchOrders (symbol, params);
let orders = await this.fetchOrders (symbol, since, limit, params);
return this.filterBy (orders, 'status', 'closed');
return [];
}

async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) {
await this.loadMarkets();
let market = undefined;
if (!symbol) {
if (!symbol)
throw new NotSupported (this.id + ': fetchMyTrades requires a `symbol` parameter.');
}
market = this.market(symbol);
await this.loadMarkets();
let market = this.market(symbol);
let request = this.prepHistoryRequest(market, since, limit);
let response = await this.privatePostOrderTradeHistory (this.extend (request, params));
return this.parseMyTrades (response['trades'], market);
Expand Down
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ccxt",
"version": "1.10.521",
"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 Expand Up @@ -108,6 +108,7 @@
"merchandise",
"merchant",
"minimal",
"ohlcv",
"order",
"orderbook",
"order book",
Expand All @@ -118,6 +119,8 @@
"public",
"ripple",
"strategy",
"ticker",
"tickers",
"toolkit",
"trade",
"trader",
Expand Down Expand Up @@ -221,6 +224,8 @@
"itBit",
"jubi.com",
"Kraken",
"Kucoin",
"Kuna",
"LakeBTC",
"lakebtc.com",
"LiveCoin",
Expand Down Expand Up @@ -265,6 +270,7 @@
"YoBit",
"yobit.net",
"YUNBI",
"Zaif"
"Zaif",
"ZB"
]
}
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.521';
$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.521'
__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.521'
__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.521'
__version__ = '1.10.523'

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

Expand Down
Loading

0 comments on commit 5cb02f5

Please sign in to comment.