question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Trades in fetch_trades should have unified order ASC or DESC

See original GitHub issue

Some exchanges (for example poloniex) returns trades history in the descending order and some others in ascending.

  • Programming Language: Python
  • CCXT version: 1.10.389
  • Exchange: binance, poloniex
  • Method: fetch_trades
# example 1: ordered by time desc
ccxt.poloniex ({'verbose': True}).fetch_trades(
                            market['symbol'], # symbol returned by fetch_markets()
                            since=timestamp
                        )

# https://poloniex.com/public?command=returnTradeHistory&currencyPair=BTC_NXT&start=1410158341&end=1410499372

# example 2: ordered by time asc
ccxt.binance ({'verbose': True}).fetch_trades(
                            market['symbol'], # symbol returned by fetch_markets()
                            since=timestamp
                        )
# https://api.binance.com/api/v1/aggTrades?symbol=ETHBTC

I think there should be one unified order (ASC as for me).

This issue can be solved by checking first and last trade’s timestamps and applying reversed iterator if needed.

Posting it because it took me some time to go there and as for me, this behavior is unexpected.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:25 (14 by maintainers)

github_iconTop GitHub Comments

1reaction
hippylovercommented, Jan 15, 2018

okok.

1reaction
ksanderercommented, Dec 29, 2017
  1. Question: Some exchanges have limitation on max since time. For example, when trying to iterate over exchanges list poloniex will return an undocumented error (can’t return more than 1 month trade history). I think there should be an error or auto adjusting since parameter to maximal available.

  2. fetch_trades reversed order (we already discussed earlier). Python reversed return an iterator that hasn’t __getitem__ (so you can’t retrieve order by id) and its type differs from normal behavior (list) so I think it’s a bad idea to return implicitly reversed orders iterator.

Now my code looks like this:

class Reversed:
    def __init__(self, seq):
        self.seq = seq
    def __len__(self):
        return len(self.seq)
    def __getitem__(self, i):
        return self.seq[-(i + 1)]

trades = ccxt.poloniex ().fetch_trades(market['symbol'], since=timestamp)

if trades[0]['timestamp'] > trades[-1]['timestamp']:
    trades = Reversed(trades)

# For some exchanges `type(trades) == list` and for others `type(trades) == Reverses`

Maybe we should explicitly return is_reversed to force reaction from developer? Like this:

trades, is_reversed = ccxt.poloniex ().fetch_trades(market['symbol'], since=timestamp)

if is_reversed:
    # do something with it
    # for example 
    # trades = Reversed(trades)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Exchanges — ccxt 2.4.71 documentation
To connect to an exchange and start trading you need to instantiate an exchange ... Python exchange = ccxt.binance ({ 'rateLimit': 10000, #...
Read more >
CCXT - 简书
Overview. The ccxt library is a collection of available crypto exchanges or exchange classes. Each class implements the public and private ...
Read more >
Coinbase 3 Network Confirmations Poloniex Orderbook
All extra params are exchange-specific non-unified. Thus market orders can be emulated with limit orders where missing. If you only need one how...
Read more >
Reset Qr Code Bitstamp Binance Exchange Says Invalid ...
To connect to an exchange and start trading you need to instantiate an exchange ... by timestamp in ascending order, oldest trade first,...
Read more >
Spring Cloud
If you need to use newer version of AWS SDK than one configured by Spring Cloud ... In order to interact with the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found