Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding "total price" worth to ladder whale orders #68

Closed
mifunetoshiro opened this issue Feb 24, 2018 · 8 comments
Closed

Adding "total price" worth to ladder whale orders #68

mifunetoshiro opened this issue Feb 24, 2018 · 8 comments

Comments

@mifunetoshiro
Copy link
Contributor

Now with #66 merged, hovering over a bubble shows the total price of the order/s. I tried to add the same to the ladder whale orders, and if I play with a simple test dataframe it works, but when I try with app.py, I get an error on:

    vol_grp_bid = vol_grp_bid[
        ((vol_grp_bid[TBL_VOLUME] >= minVolume) & (vol_grp_bid['count'] >= 2.0) & (vol_grp_bid['count'] < 70.0))]

for some reason. Could someone with more experience implement this?

@theimo1221
Copy link
Contributor

theimo1221 commented Feb 24, 2018

Wich Error and are you sure it´s on that line and not cause error in line before?
@mifunetoshiro I made a pull request into your patch repo, try it in there my changes will do many things in other ways

@mifunetoshiro
Copy link
Contributor Author

mifunetoshiro commented Feb 25, 2018

@theimo1221 This error, see the code I tried: mifunetoshiro@7647a92

Exception in thread Thread-57:
Traceback (most recent call last):
File "C:\Python\lib\site-packages\pandas\core\indexes\base.py", line 2525, in get_loc
return self._engine.get_loc(key)
File "pandas_libs\index.pyx", line 117, in pandas._libs.index.IndexEngine.get_loc
File "pandas_libs\index.pyx", line 139, in pandas._libs.index.IndexEngine.get_loc
File "pandas_libs\hashtable_class_helper.pxi", line 1265, in pandas._libs.hashtable.PyObjectHashTable.get_item
File "pandas_libs\hashtable_class_helper.pxi", line 1273, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: 'volume'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Python\lib\threading.py", line 916, in _bootstrap_inner
self.run()
File "C:\Python\lib\threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\mifune\Desktop\app.py", line 596, in recalcThread
count = count+1 if (not calc_data(pair)) else 0
File "C:\Users\mifune\Desktop\app.py", line 223, in calc_data
((vol_grp_bid[TBL_VOLUME] >= minVolume) & (vol_grp_bid['count'] >= 2.0) & (vol_grp_bid['count'] < 70.0))]
File "C:\Python\lib\site-packages\pandas\core\frame.py", line 2139, in getitem
return self._getitem_column(key)
File "C:\Python\lib\site-packages\pandas\core\frame.py", line 2151, in _getitem_column
result = result[key]
File "C:\Python\lib\site-packages\pandas\core\frame.py", line 2139, in getitem
return self._getitem_column(key)
File "C:\Python\lib\site-packages\pandas\core\frame.py", line 2146, in _getitem_column
return self._get_item_cache(key)
File "C:\Python\lib\site-packages\pandas\core\generic.py", line 1842, in _get_item_cache
values = self._data.get(item)
File "C:\Python\lib\site-packages\pandas\core\internals.py", line 3843, in get
loc = self.items.get_loc(item)
File "C:\Python\lib\site-packages\pandas\core\indexes\base.py", line 2527, in get_loc
return self._engine.get_loc(self._maybe_cast_indexer(key))
File "pandas_libs\index.pyx", line 117, in pandas._libs.index.IndexEngine.get_loc
File "pandas_libs\index.pyx", line 139, in pandas._libs.index.IndexEngine.get_loc
File "pandas_libs\hashtable_class_helper.pxi", line 1265, in pandas._libs.hashtable.PyObjectHashTable.get_item
File "pandas_libs\hashtable_class_helper.pxi", line 1273, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: 'volume'

@mifunetoshiro
Copy link
Contributor Author

Ah, I see: rename(columns={'amin': 'min_Price', 'amax': 'max_Price', 'sum': 'volume', 'sum': 'total_price'})

This renames both sum columns to 'total_price' instead of 'volume' and 'total_price'. So how do you rename two sums to two different names?

@theimo1221
Copy link
Contributor

vol_grp_ask = ask_tbl.groupby([TBL_VOLUME]).agg({TBL_PRICE: [np.min, np.max, 'count'], TBL_VOLUME:{TBL_VOLUME:np.sum}, 'total_price': {'total_price':np.sum}).rename(columns={'amin': 'min_Price', 'amax': 'max_Price'})

Is what you need I guess

@mifunetoshiro
Copy link
Contributor Author

mifunetoshiro commented Feb 25, 2018

Ok, I figured it out. Instead of using the rename function, I manually renamed the columns with vol_grp_bid.columns. This is also unneeded after: vol_grp_bid.columns.droplevel(0)

Will add pull request soon.

Edit: your way produces this warning:

FutureWarning: using a dict with renaming is deprecated and will be removed in a future version

@theimo1221
Copy link
Contributor

theimo1221 commented Feb 25, 2018

@mifunetoshiro Dropplevel (0) removes the groubby name marked in following example:
image

Not the colum name themselves

@mifunetoshiro
Copy link
Contributor Author

mifunetoshiro commented Feb 25, 2018

Yes, but in the way that I did it:

    vol_grp_bid = bid_tbl.groupby([TBL_VOLUME]).agg({TBL_PRICE: [np.min, np.max, 'count'], TBL_VOLUME: np.sum, 'total_price': np.sum})
    vol_grp_bid.columns = ['min_Price', 'max_Price', 'count', 'volume', 'total_price']
    vol_grp_ask = ask_tbl.groupby([TBL_VOLUME]).agg({TBL_PRICE: [np.min, np.max, 'count'], TBL_VOLUME: np.sum, 'total_price': np.sum})
    vol_grp_ask.columns = ['min_Price', 'max_Price', 'count', 'volume', 'total_price']

It's not needed, because there aren't 2 levels, and you get an error:

AttributeError: 'Index' object has no attribute 'droplevel'

@theimo1221
Copy link
Contributor

ah okay, gotcha.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants