Skip to content

Commit

Permalink
Reimplement 66b45ae in the official way
Browse files Browse the repository at this point in the history
  • Loading branch information
ngugc committed Sep 15, 2018
1 parent 66b45ae commit a375dd3
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 59 deletions.
20 changes: 18 additions & 2 deletions js/base/Exchange.js
Original file line number Diff line number Diff line change
Expand Up @@ -1080,7 +1080,15 @@ module.exports = class Exchange {
}

parseTrades (trades, market = undefined, since = undefined, limit = undefined) {
let result = Object.values (trades || []).map (trade => this.parseTrade (trade, market))
let result = Object.values (trades || []).map (
function(trade){
tradeMarket = market
if (tradeMarket === undefined) {
tradeMarket = this.findMarket(this.safeString(trade, 'market'));
}
return this.parseTrade (trade, tradeMarket)
}
)
result = sortBy (result, 'timestamp')
let symbol = (market !== undefined) ? market['symbol'] : undefined
return this.filterBySymbolSinceLimit (result, symbol, since, limit)
Expand All @@ -1094,7 +1102,15 @@ module.exports = class Exchange {
}

parseOrders (orders, market = undefined, since = undefined, limit = undefined) {
let result = Object.values (orders).map (order => this.parseOrder (order, market))
let result = Object.values (orders || []).map (
function(order){
orderMarket = market
if (orderMarket === undefined) {
orderMarket = this.findMarket(this.safeString(order, 'market'));
}
return this.parseTrade (order, orderMarket)
}
)
result = sortBy (result, 'timestamp')
let symbol = (market !== undefined) ? market['symbol'] : undefined
return this.filterBySymbolSinceLimit (result, symbol, since, limit)
Expand Down
30 changes: 15 additions & 15 deletions js/coinex.js
Original file line number Diff line number Diff line change
Expand Up @@ -452,14 +452,13 @@ module.exports = class coinex extends Exchange {
}

async fetchOrdersByStatus (status, symbol = undefined, since = undefined, limit = undefined, params = {}) {
if (symbol === undefined) {
throw new ExchangeError (this.id + ' fetchOrders requires a symbol argument');
let request = {};
let market = undefined;
if (symbol !== undefined) {
await this.loadMarkets ();
market = this.market (symbol);
request['market'] = market['id'];
}
await this.loadMarkets ();
let market = this.market (symbol);
let request = {
'market': market['id'],
};
if (limit !== undefined)
request['limit'] = limit;
let method = 'privateGetOrder' + this.capitalize (status);
Expand All @@ -476,16 +475,17 @@ module.exports = class coinex extends Exchange {
}

async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) {
if (symbol === undefined) {
throw new ExchangeError (this.id + ' fetchMyTrades requires a symbol argument');
}
await this.loadMarkets ();
let market = this.market (symbol);
let response = await this.privateGetOrderUserDeals (this.extend ({
'market': market['id'],
let request = {
'page': 1,
'limit': 100,
}, params));
};
let market = undefined;
if (symbol !== undefined) {
await this.loadMarkets ();
market = this.market (symbol);
request['market'] = market['id'];
}
let response = await this.privateGetOrderUserDeals (this.extend (request, params));
return this.parseTrades (response['data']['data'], market, since, limit);
}

Expand Down
30 changes: 15 additions & 15 deletions php/coinex.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,14 +453,13 @@ public function fetch_order ($id, $symbol = null, $params = array ()) {
}

public function fetch_orders_by_status ($status, $symbol = null, $since = null, $limit = null, $params = array ()) {
if ($symbol === null) {
throw new ExchangeError ($this->id . ' fetchOrders requires a $symbol argument');
$request = array ();
$market = null;
if ($symbol !== null) {
$this->load_markets();
$market = $this->market ($symbol);
$request['market'] = $market['id'];
}
$this->load_markets();
$market = $this->market ($symbol);
$request = array (
'market' => $market['id'],
);
if ($limit !== null)
$request['limit'] = $limit;
$method = 'privateGetOrder' . $this->capitalize ($status);
Expand All @@ -477,16 +476,17 @@ public function fetch_closed_orders ($symbol = null, $since = null, $limit = nul
}

public function fetch_my_trades ($symbol = null, $since = null, $limit = null, $params = array ()) {
if ($symbol === null) {
throw new ExchangeError ($this->id . ' fetchMyTrades requires a $symbol argument');
}
$this->load_markets();
$market = $this->market ($symbol);
$response = $this->privateGetOrderUserDeals (array_merge (array (
'market' => $market['id'],
$request = array (
'page' => 1,
'limit' => 100,
), $params));
);
$market = null;
if ($symbol !== null) {
$this->load_markets();
$market = $this->market ($symbol);
$request['market'] = $market['id'];
}
$response = $this->privateGetOrderUserDeals (array_merge ($request, $params));
return $this->parse_trades($response['data']['data'], $market, $since, $limit);
}

Expand Down
28 changes: 14 additions & 14 deletions python/ccxt/async_support/coinex.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,13 +431,12 @@ async def fetch_order(self, id, symbol=None, params={}):
return self.parse_order(response['data'], market)

async def fetch_orders_by_status(self, status, symbol=None, since=None, limit=None, params={}):
if symbol is None:
raise ExchangeError(self.id + ' fetchOrders requires a symbol argument')
await self.load_markets()
market = self.market(symbol)
request = {
'market': market['id'],
}
request = {}
market = None
if symbol is not None:
await self.load_markets()
market = self.market(symbol)
request['market'] = market['id']
if limit is not None:
request['limit'] = limit
method = 'privateGetOrder' + self.capitalize(status)
Expand All @@ -451,15 +450,16 @@ async def fetch_closed_orders(self, symbol=None, since=None, limit=None, params=
return await self.fetch_orders_by_status('finished', symbol, since, limit, params)

async def fetch_my_trades(self, symbol=None, since=None, limit=None, params={}):
if symbol is None:
raise ExchangeError(self.id + ' fetchMyTrades requires a symbol argument')
await self.load_markets()
market = self.market(symbol)
response = await self.privateGetOrderUserDeals(self.extend({
'market': market['id'],
request = {
'page': 1,
'limit': 100,
}, params))
}
market = None
if symbol is not None:
await self.load_markets()
market = self.market(symbol)
request['market'] = market['id']
response = await self.privateGetOrderUserDeals(self.extend(request, params))
return self.parse_trades(response['data']['data'], market, since, limit)

async def withdraw(self, code, amount, address, tag=None, params={}):
Expand Down
22 changes: 18 additions & 4 deletions python/ccxt/base/exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -1292,8 +1292,15 @@ def parse_timeframe(self, timeframe):

def parse_trades(self, trades, market=None, since=None, limit=None):
array = self.to_array(trades)
array = [self.parse_trade(trade, market) for trade in array]
array = self.sort_by(array, 'timestamp')
# array = [self.parse_trade(trade, market) for trade in array]
parsedTrades = []
for trade in array:
if market is None:
self.load_markets()
market = self.find_market(trade['market'])
parsedTrades.append(self.parse_trade(trade, market))
# array = self.sort_by(array, 'timestamp')
array = self.sort_by(parsedTrades, 'timestamp')
symbol = market['symbol'] if market else None
return self.filter_by_symbol_since_limit(array, symbol, since, limit)

Expand All @@ -1306,8 +1313,15 @@ def parse_transactions(self, transactions, currency=None, since=None, limit=None

def parse_orders(self, orders, market=None, since=None, limit=None):
array = self.to_array(orders)
array = [self.parse_order(order, market) for order in array]
array = self.sort_by(array, 'timestamp')
# array = [self.parse_order(order, market) for order in array]
parsedOrders = []
for order in array:
if market is None:
self.load_markets()
market = self.find_market(order['market'])
parsedOrders.append(self.parse_order(order, market))
# array = self.sort_by(array, 'timestamp')
array = self.sort_by(parsedOrders, 'timestamp')
symbol = market['symbol'] if market else None
return self.filter_by_symbol_since_limit(array, symbol, since, limit)

Expand Down
12 changes: 3 additions & 9 deletions python/ccxt/coinex.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,6 @@ def parse_trade(self, trade, market=None):
orderId = self.safe_string(trade, 'order_id')
price = self.safe_float(trade, 'price')
amount = self.safe_float(trade, 'amount')
if market is None:
self.load_markets()
market = self.find_market(trade['market'])
symbol = market['symbol']
cost = self.safe_float(trade, 'deal_money')
if not cost:
Expand Down Expand Up @@ -360,9 +357,6 @@ def parse_order(self, order, market=None):
cost = self.safe_float(order, 'deal_money')
amount = self.safe_float(order, 'amount')
filled = self.safe_float(order, 'deal_amount')
if market is None:
self.load_markets()
market = self.find_market(order['market'])
symbol = market['symbol']
remaining = float(self.amount_to_precision(symbol, amount - filled))
status = self.parse_order_status(self.safe_string(order, 'status'))
Expand Down Expand Up @@ -437,8 +431,8 @@ def fetch_order(self, id, symbol=None, params={}):
return self.parse_order(response['data'], market)

def fetch_orders_by_status(self, status, symbol=None, since=None, limit=None, params={}):
market = None
request = {}
market = None
if symbol is not None:
self.load_markets()
market = self.market(symbol)
Expand All @@ -456,12 +450,12 @@ def fetch_closed_orders(self, symbol=None, since=None, limit=None, params={}):
return self.fetch_orders_by_status('finished', symbol, since, limit, params)

def fetch_my_trades(self, symbol=None, since=None, limit=None, params={}):
market = None
request = {
'page': 1,
'limit': 100,
}
if symbol:
market = None
if symbol is not None:
self.load_markets()
market = self.market(symbol)
request['market'] = market['id']
Expand Down

0 comments on commit a375dd3

Please sign in to comment.