highfestiva/finplot

volume profile example gets an error on horiz_time_volume function

knoghax opened this issue · 8 comments

I've been trying to run the examples in the repo, and for the volume profile one, I get an error on line 69 while executing the horiz_time_volume function. The output in my terminal is shown below:

Traceback (most recent call last):
  File "d:\Dropbox\Binance bot\python-binance-bot\finplot volume profile.py", line 69, in <module>
    fplt.horiz_time_volume(time_volume_profile, draw_va=0.7, draw_poc=1.0)
  File "C:\Users\knoghax\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\finplot\__init__.py", line 1537, in horiz_time_volume
    _set_datasrc(ax, datasrc)
  File "C:\Users\knoghax\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\finplot\__init__.py", line 2206, in _set_datasrc
    datasrc.df.index = [d[i] for i in datasrc.df[datasrc.df.columns[0]]]
  File "C:\Users\knoghax\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\finplot\__init__.py", line 2206, in <listcomp>
    datasrc.df.index = [d[i] for i in datasrc.df[datasrc.df.columns[0]]]
KeyError: 1592784000000000000

I have no idea what could be the issue here and opted to let you know. Would appreciate it if you could let me know what could be going on here. Thank you!

You have an old version of finplot installed. Please upgrade first, and if it still doesn't work, please post a screenshot of what is shown when you uncomment line 69 in the volume profile example.

Btw, nice to see you working on a Binance bot! This is the way.

Thanks for the quick reply!

I uninstalled the version I had (I installed it with pip install finplot) and then installed directly from the repo.

I ran the code again and it still didn't work.

This is what happens when I uncomment line 69 in the example:

Capture11

I've been working on Binance bots for 2 years :) This is the way.

You've still not commented out line 69 on the example, as can be seen in your log which clearly states volume profile.py", line 69 in <module>.

I guess I misunderstood what you meant in the previous comment. You wrote "uncomment line 69" but I guess you meant to post a screenshot of what is shown when I comment line 69 in the volume profile example.

In that case the resulting graph is shown below:

Capture11

I'm guessing the data you're using might be missing some timestamps. Could you post a minimal example so I can reproduce it myself?

The results I have are from using exactly the code of volume-profile.py that you have in your repository.

I'm not sure if this is what you're looking for, but these are the results I get when I print time_volume_profile and when I print df:

time_volume_profile

[[Timestamp('2020-06-22 00:00:00'), [(8945.44, 112828.117), (8980.211, 30542.971), (9014.983, 30416.381), (9049.754, 59804.638), (9084.525, 97447.19099999998), (9119.297, 198542.83299999996), (9154.068, 118055.52500000002), (9188.839, 80489.76300000002), (9223.611, 86670.615), (9258.382, 125592.37099999998), (9293.153, 94760.60200000001), (9327.925, 39387.325), (9362.696, 38519.091), (9397.467, 95702.46), (9432.239, 16941.612), (9467.01, 27720.045), (9501.781, 41685.752), (9536.553, 31911.863), (9571.324, 57606.107), (9606.095, 81176.976), (9640.867, 118358.563), (9675.638, 25277.745000000003), (9710.409, 29845.079)]], [Timestamp('2020-06-29 00:00:00'), [(8945.44, 14537.655), (8980.211, 7930.26), (9014.983, 118864.89900000002), (9049.754, 179427.20299999992), (9084.525, 207275.13500000004), (9119.297, 220027.39300000004), (9154.068, 93654.06699999998), (9188.839, 97890.63100000001), (9223.611, 92843.50000000001), (9258.382, 16777.66)]], [Timestamp('2020-07-06 00:00:00'), [(9049.754, 7814.402), (9084.525, 17267.177), (9119.297, 17511.713), (9154.068, 78449.06600000002), (9188.839, 228463.34699999995), (9223.611, 165483.13399999996), (9258.382, 215219.76599999992), (9293.153, 98330.085), (9327.925, 24848.64), (9362.696, 47575.725000000006), (9397.467, 99413.63600000001), (9432.239, 29368.246)]], [Timestamp('2020-07-13 00:00:00'), [(9049.754, 22627.001000000004), (9084.525, 61262.041000000005), (9119.297, 146919.03199999998), (9154.068, 166601.60299999997), (9188.839, 103965.33100000002), (9223.611, 138732.16799999995), (9258.382, 45233.549), (9293.153, 52407.12899999999)]], [Timestamp('2020-07-20 00:00:00'), [(9119.297, 1292.142), (9154.068, 68999.65599999997), (9188.839, 25655.816), (9293.153, 84156.668), (9327.925, 75237.239), (9362.696, 58725.24899999999), (9397.467, 25116.157), (9467.01, 79926.872), (9501.781, 105407.75099999997), (9536.553, 64897.97600000001), (9571.324, 115198.94600000003), (9606.095, 41830.124), (9640.867, 36164.529), (9675.638, 42466.166), (9710.409, 18117.766), (9745.181, 20048.613), (9779.952, 13610.98), (9849.495, 24627.577999999998), (9884.266, 19065.221), (9919.037, 36474.00399999999), (9953.809, 25536.129), (9988.58, 
13263.051), (10023.351, 78762.897)]], [Timestamp('2020-07-27 00:00:00'), [(9953.809, 3396.652), (9988.58, 11887.535), (10058.123, 36598.362), (10092.894, 9621.754), (10162.437, 32456.226), (10197.208, 6680.086), (10231.979, 112290.85600000001), (10266.751, 39612.486), (10301.522, 54558.590000000004), (10336.293, 18405.673), (10371.065, 35352.426999999996), (10614.464, 63155.219), (10684.007, 28766.751), (10753.549, 52371.437999999995), (10788.321, 6061.663), (10823.092, 145036.474), (10857.863, 12295.774000000001), (10892.635, 45150.042), (10927.406, 130071.71000000002), (10962.177, 156449.27000000002), (10996.949, 193691.214), (11031.72, 184749.154), (11066.491, 111481.64699999998), (11101.263, 164762.43999999997), (11136.034, 175500.45799999996), (11170.805, 95696.92600000002), (11205.577, 214937.13299999997), (11240.348, 171845.96900000004), (11275.119, 96238.793), (11309.891, 119257.24899999998), (11344.662, 23152.794), (11379.433, 33359.894), (11448.976, 12949.22), (11518.519, 19733.614), (11553.29, 33214.573), (11588.061, 21555.563000000002), (11622.833, 58995.04000000001), (11657.604, 72822.835), (11692.375, 19462.388), (11727.147, 16304.008000000002), (11761.918, 45041.397), (11796.689, 42028.06), (11831.461, 16241.766), (11901.003, 18228.597999999998), (11935.775, 14216.822), (11970.546, 41595.009000000005)]], [Timestamp('2020-08-03 00:00:00'), [(11031.72, 11820.447), (11101.263, 22775.334), (11136.034, 65258.776000000005), (11170.805, 44493.988000000005), (11205.577, 101003.98700000001), (11240.348, 72574.40200000002), (11275.119, 44383.39599999999), (11309.891, 33580.978), (11344.662, 41848.424), (11379.433, 54520.433000000005), (11414.205, 58297.85400000001), (11448.976, 15930.439), (11483.747, 28309.159000000003), (11518.519, 28716.603000000003), (11553.29, 62357.182000000015), (11588.061, 144023.018), (11622.833, 96270.463), (11657.604, 128444.14300000001), (11692.375, 78585.849), (11727.147, 117785.85200000001), (11761.918, 83142.10800000002), (11796.689, 49813.594000000005), (11831.461, 83701.42599999999), (11866.232, 25137.169)]], [Timestamp('2020-08-10 00:00:00'), [(11205.577, 38066.909), (11240.348, 19225.989), (11275.119, 43224.13), (11309.891, 21546.406000000003), (11344.662, 52153.349), (11379.433, 79835.753), (11414.205, 24828.54), (11448.976, 54031.771), (11483.747, 124202.945), (11518.519, 43423.20300000001), (11553.29, 84682.26700000002), (11588.061, 78806.928), (11622.833, 34248.490000000005), (11657.604, 45023.929000000004), (11692.375, 60311.969), (11727.147, 114849.97100000002), (11761.918, 110126.13300000002), (11796.689, 102007.66499999998), (11831.461, 94633.40899999997), 
(11866.232, 193943.86499999996), (11901.003, 95907.707), (11935.775, 27212.247000000003), (11970.546, 58415.05999999999), (12005.317, 17233.206), (12040.089, 18368.694)]], [Timestamp('2020-08-17 00:00:00'), [(11796.689, 13611.112), (11831.461, 30584.669999999995), (11866.232, 33490.331000000006), (11901.003, 36233.851), (11935.775, 13171.94), (11970.546, 126946.84199999999), (12005.317, 21371.305), (12040.089, 10902.401), (12074.86, 25536.836), (12144.403, 48967.539000000004), (12179.174, 13049.27), (12213.945, 23643.841999999997), (12248.717, 42626.50200000001), (12283.488, 24214.066), (12318.259, 48744.200999999994), (12353.031, 70805.068), (12387.802, 38885.224)]]]

df

                    time      open      high       low     close    volume  ...      c         d               e  f          hlc3         hlc3v
0    2020-06-22 00:00:00   9293.39   9335.00   9273.00   9326.26  5279.928  ...  13509  3190.031  29681156.85887  0   9311.420000  4.916363e+07
1    2020-06-22 00:30:00   9326.14   9332.70   9311.51   9320.35  1565.054  ...   6069   850.786   7930980.17011  0   9321.520000  1.458868e+07
2    2020-06-22 01:00:00   9320.35   9337.00   9317.40   9333.92  1805.899  ...   5776  1010.843   9432276.28982  0   9329.440000  1.684803e+07
3    2020-06-22 01:30:00   9333.93   9388.00   9330.43   9382.58  7701.893  ...  20574  4895.225  45826766.59459  0   9367.003333  7.214366e+07
4    2020-06-22 02:00:00   9382.57   9394.43   9365.42   9373.48  5705.957  ...  14506  3034.380  28462426.27621  0   9377.776667  5.350919e+07
...                  ...       ...       ...       ...       ...       ...  ...    ...       ...             ... ..           ...           ...
2779 2020-08-18 21:30:00  12066.91  12093.94  12045.50  12075.48  2129.550  ...  10692   986.828  11909333.99333  0  12071.640000  2.570716e+07
2780 2020-08-18 22:00:00  12075.48  12083.98  12040.43  12078.65  2085.981  ...   9251   803.235   9687752.32018  0  12067.686667  2.517297e+07
2781 2020-08-18 22:30:00  12078.65  12097.48  12043.05  12061.34  2269.613  ...  10627  1059.666  12790275.45061  0  12067.290000  2.738808e+07
2782 2020-08-18 23:00:00  12061.34  12062.99  11990.86  11992.87  3883.610  ...  14708  1552.595  18680446.25025  0  12015.573333  4.666380e+07
2783 2020-08-18 23:30:00  11992.98  12029.00  11957.38  11960.79  3525.837  ...  13942  1621.428  19436462.99356  0  11982.390000  4.224795e+07

It's close to impossible to reproduce your error from that data. Please send me something I can work with. You don't have to give me your data or code, just a minimal example is best.