Skip to content

Commit

Permalink
_1btcxe ticker timestamp and parseDate added to js/py/php
Browse files Browse the repository at this point in the history
  • Loading branch information
kroitor committed Feb 27, 2018
1 parent 2529ea5 commit e49e928
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
7 changes: 4 additions & 3 deletions js/_1btcxe.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ module.exports = class _1btcxe extends Exchange {
'currency': this.marketId (symbol),
}, params));
let ticker = response['stats'];
let last = parseFloat (ticker['last_price']);
return {
'symbol': symbol,
'timestamp': undefined,
Expand All @@ -128,9 +129,9 @@ module.exports = class _1btcxe extends Exchange {
'ask': parseFloat (ticker['ask']),
'vwap': undefined,
'open': parseFloat (ticker['open']),
'close': undefined,
'first': undefined,
'last': parseFloat (ticker['last_price']),
'close': last,
'last': last,
'previousClose': undefined,
'change': parseFloat (ticker['daily_change']),
'percentage': undefined,
'average': undefined,
Expand Down
8 changes: 7 additions & 1 deletion js/base/Exchange.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,13 @@ module.exports = class Exchange {

this.iso8601 = timestamp => ((typeof timestamp === 'undefined') ? timestamp : new Date (timestamp).toISOString ())
this.parse8601 = x => Date.parse (((x.indexOf ('+') >= 0) || (x.slice (-1) === 'Z')) ? x : (x + 'Z'))
this.parseDate = x => ((x.indexOf ('GMT') >= 0) ? Date.parse (x) : this.parse8601 (x))
this.parseDate = (x) => {
if (typeof x === 'undefined')
return x
return ((x.indexOf ('GMT') >= 0) ?
Date.parse (x) :
this.parse8601 (x))
}
this.microseconds = () => now () * 1000 // TODO: utilize performance.now for that purpose
this.seconds = () => Math.floor (now () / 1000)

Expand Down
8 changes: 8 additions & 0 deletions php/Exchange.php
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,14 @@ public static function iso8601 ($timestamp) {
return str_replace ('+', sprintf (".%03d+", $msec), $result);
}

public static function parse_date ($timestamp) {
if (!isset ($timestamp))
return $timestamp;
if (strstr ($timestamp, 'GMT'))
return strtotime ($timestamp) * 1000;
return static::parse8601 ($timestamp);
}

public static function parse8601 ($timestamp) {
$time = strtotime ($timestamp) * 1000;
if (preg_match ('/\.(?<milliseconds>[0-9]{1,3})/', $timestamp, $match)) {
Expand Down
2 changes: 2 additions & 0 deletions python/ccxt/base/exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,8 @@ def ymdhms(timestamp, infix=' '):

@staticmethod
def parse_date(timestamp):
if timestamp is None:
return timestamp
if 'GMT' in timestamp:
string = ''.join([str(value) for value in parsedate(timestamp)[:6]]) + '.000Z'
dt = datetime.datetime.strptime(string, "%Y%m%d%H%M%S.%fZ")
Expand Down

0 comments on commit e49e928

Please sign in to comment.