Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

    Binance data doesn't plot correctly

    General Code/Help
    2
    2
    58
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • X
      xeramph last edited by

      Trying to plot this data and it ends up not looking like the expected graph. I loaded it up in a csv viewer and my generated graph looks nothing like it. I'm assuming it's because I'm not plotting all of the data from the csv file, but I don't know how I would go about doing it without errors, please help.

      My graph
      Expected graph

      Code sample:

      btc = pd.read_csv(
          "D:\Projects\Algo\Data\BTCUSDT-1m-2022-04-27.csv",
          names = ['datetime', 'open', 'high', 'low', 'close', 'volume'],
          parse_dates = ['datetime'],
          date_parser = lambda d: pd.to_datetime(d).strftime('%Y-%m-%d %H:%M:%S'),
      )
      
      
      data = bt.feeds.PandasData(
          dataname = btc,
      
          compression = 1,
          timeframe = bt.TimeFrame.Minutes,
          
          datetime = 0,
          open = 1,
          high = 2,
          low = 3,
          close = 4,
          volume = 5,
          openinterest = -1,
      )
      cerebro.adddata(data)
      
      cerebro.run()
      cerebro.plot()
      

      Data sample:

      1651017600000,38112.64000000,38136.59000000,38080.85000000,38104.14000000,114.26374000,1651017659999,4354852.56207570,1283,50.22287000,1914106.74409190,0
      

      Data explanation (from api docs):

      [
        [
          1499040000000,      // Open time
          "0.01634790",       // Open
          "0.80000000",       // High
          "0.01575800",       // Low
          "0.01577100",       // Close
          "148976.11427815",  // Volume
          1499644799999,      // Close time
          "2434.19055334",    // Quote asset volume
          308,                // Number of trades
          "1756.87402397",    // Taker buy base asset volume
          "28.46694368",      // Taker buy quote asset volume
          "17928899.62484339" // Ignore.
        ]
      ]
      
      1 Reply Last reply Reply Quote 0
      • hronnie
        hronnie last edited by

        @xeramph said in Binance data doesn't plot correctly:

        date_parser = lambda d: pd.to_datetime(d).strftime('%Y-%m-%d %H:%M:%S')

        Did you find any solution by any chance? I have the very same problem.

        1 Reply Last reply Reply Quote 0
        • 1 / 1
        • First post
          Last post
        Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors