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.

Coinbasepro fetch_ohlcv since giving 'Invalid start'

See original GitHub issue

Most other exchanges work fine with these functions and ‘since’ calls. Coinbasepro is the only one that says ‘invalid start’. Thanks to anyone who can help 😃

The problem is in the updateHistory() function last_update = self.bars.iloc[-1, 0] <— returns the last timestamp saved from the OHLCV data new_data = pd.DataFrame(exchange.fetch_ohlcv(ticker, timeframe, since=last_update))

  • OS: Windows 10
  • Programming Language version: Python 3.9.10 64bit
  • CCXT version:
from genericpath import isfile, isdir
from configparser import ConfigParser
import ccxt.async_support as ccas
import asyncio
import ccxt
import pandas as pd
import os


class Exchange:

    config = ConfigParser()
    config.read('C:\\Users\\pattt\\Desktop\\exchanges.config')


    def __init__(self):
        self.api = {}
        self.bars = None
        self.exchanges = ['coinbasepro']
        self.loadAllExchanges(self.exchanges)


    def updateHistory(self, tickers, timeframe):
        """ 
            Load exchange CSV file from 'OHLCV/' or create one and pull data.
        """
        for exchange in self.api.values():
            for ticker in tickers:
                PATH = 'OHLCV/'
                FILE = "{0}-{1}{2}".format(exchange.id, timeframe, '.csv')
                if not isfile(PATH + FILE):
                    df = pd.DataFrame(exchange.fetch_ohlcv(ticker, timeframe), columns=['Time', 'Open', 'High', 'Low', 'Close', 'Vol'])
                    if not (isdir(PATH)):
                        os.makedirs(PATH)
                        df.to_csv(PATH + FILE, index=False)
                        self.bars = df
                    else: 
                        df.to_csv(PATH + FILE, index=False)
                        self.bars = df
                else:
                    self.bars = pd.read_csv(PATH + FILE)
                    last_update = self.bars.iloc[-1, 0]
                    new_data = pd.DataFrame(exchange.fetch_ohlcv(ticker, timeframe, since=last_update))
                    new_data.drop(new_data.head(1).index, inplace=True)
                    new_data.to_csv(PATH + FILE, mode='a', header=False, index=False)
                    self.bars = pd.read_csv(PATH + FILE)


    def loadAllExchanges(self, exchanges):
        for exchange_id in exchanges:
            exchange_class = getattr(ccxt, exchange_id)
            if(exchange_id.upper() in self.config):
                try:
                    self.api[exchange_id] = exchange_class({
                        'apiKey': self.config[self.exchange_id.upper()]['apiKey'],
                        'secret': self.config[self.exchange_id.upper()]['secret'],
                    })
                    # do what you want with this exchange
                    # pprint(dir(exchange))
                except ccxt.NetworkError as e:
                    print(e)
                except ccxt.ExchangeError as e:
                    print(e)
                except Exception as e:
                    print(e)
            else: 
                self.api[exchange_id] = exchange_class({
                    'enableRateLimit': True,
                })
                self.api[exchange_id].load_markets()



e = Exchange()
e.updateHistory(['BTC/USDT'], '1m')
print(e.bars)
(venv) C:\Users\pattt\Desktop\Python\Trading Bot\WaveTrend Bot v1.1>"c:/Users/pattt/Desktop/Python/Trading Bot/WaveTrend Bot v1.1/venv/Scripts/python.exe" "c:/Users/pattt/Desktop/Python/Trading Bot/WaveTrend Bot v1.1/Exchange.py"
Traceback (most recent call last):
  File "c:\Users\pattt\Desktop\Python\Trading Bot\WaveTrend Bot v1.1\venv\lib\site-packages\ccxt\base\exchange.py", line 656, in fetch
    response.raise_for_status()
  File "c:\Users\pattt\Desktop\Python\Trading Bot\WaveTrend Bot v1.1\venv\lib\site-packages\requests\models.py", line 960, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://api.pro.coinbase.com/products/BTC-USDT/candles?granularity=60&start=None&end=1970-01-01T04%3A59%3A00.000Z

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\Users\pattt\Desktop\Python\Trading Bot\WaveTrend Bot v1.1\Exchange.py", line 75, in <module>
    e.updateHistory(['BTC/USDT'], '1m')
  File "c:\Users\pattt\Desktop\Python\Trading Bot\WaveTrend Bot v1.1\Exchange.py", line 43, in updateHistory
    new_data = pd.DataFrame(exchange.fetch_ohlcv(ticker, timeframe, since=last_update))
  File "c:\Users\pattt\Desktop\Python\Trading Bot\WaveTrend Bot v1.1\venv\lib\site-packages\ccxt\coinbasepro.py", line 746, in fetch_ohlcv
    response = self.publicGetProductsIdCandles(self.extend(request, params))
  File "c:\Users\pattt\Desktop\Python\Trading Bot\WaveTrend Bot v1.1\venv\lib\site-packages\ccxt\base\exchange.py", line 498, in inner
    return entry(_self, **inner_kwargs)
  File "c:\Users\pattt\Desktop\Python\Trading Bot\WaveTrend Bot v1.1\venv\lib\site-packages\ccxt\coinbasepro.py", line 1335, in request
    response = self.fetch2(path, api, method, params, headers, body, config, context)
  File "c:\Users\pattt\Desktop\Python\Trading Bot\WaveTrend Bot v1.1\venv\lib\site-packages\ccxt\base\exchange.py", line 545, in fetch2
    return self.fetch(request['url'], request['method'], request['headers'], request['body'])
  File "c:\Users\pattt\Desktop\Python\Trading Bot\WaveTrend Bot v1.1\venv\lib\site-packages\ccxt\base\exchange.py", line 672, in fetch
    self.handle_errors(http_status_code, http_status_text, url, method, headers, http_response, json_response, request_headers, request_body)
  File "c:\Users\pattt\Desktop\Python\Trading Bot\WaveTrend Bot v1.1\venv\lib\site-packages\ccxt\coinbasepro.py", line 1331, in handle_errors
    raise ExchangeError(feedback)  # unknown message
ccxt.base.errors.ExchangeError: coinbasepro Invalid start

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
carlosmieicommented, Jan 23, 2022

@pattty847 You’re welcome 🙂 Actually no, those exchanges are not converting it either. Probably since the last_value directly maps a value coming from the exchange response, the other exchanges are already returning an int and Coinbase is returning a string.

0reactions
pattty847commented, Jan 23, 2022

@pattty847 I believe I found the problem. Probably this last_value variable is a string but the since parameter needs to be an integer.

Can you please try to convert it to an integer before calling the fetchOHLCV?

Example: exchange.fetch_ohlcv(ticker, timeframe, since='1642959420000') -> won’t work exchange.fetch_ohlcv(ticker, timeframe, since=1642959420000) -> works

Feel free to reach back again if the problem persists Thanks

Brilliant! That was exactly the problem! Thank you very much, any chance why the other exchanges convert it? It’s probably in its’ exchange file, right?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Coinbasepro fetch_ohlcv since giving 'Invalid start' - ccxt/ccxt ...
Most other exchanges work fine with these functions and 'since' calls. Coinbasepro is the only one that says 'invalid start'. Thanks to anyone...
Read more >
Coinbase Pro fetchOHLCV not returning 1d data. · Issue #5569
Hello, I am attempting to get data for 1 day for BTC/USD but when I execute the following code, the oldest data point...
Read more >
Exchanges — ccxt 2.4.71 documentation
To connect to an exchange and start trading you need to instantiate an exchange class from ccxt library. To get the full list...
Read more >
How to fetch all the coinbase pro transactions correctly in php
I am using the following library to fetch all the coinbase pro orders , but it only gives me 100 orders from the...
Read more >
“Oops, something went wrong” when trying to log into ... - Reddit
I switched my funds from Coinbase pro to regular Coinbase and it's working fine. Since I won't be buying or selling for a...
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