Skip to content

Commit

Permalink
#32 fix: 'cost' is only available on closed orders
Browse files Browse the repository at this point in the history
need to calculate amount from price*volume
  • Loading branch information
joergrs committed Oct 12, 2022
1 parent 2573533 commit a87dc44
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions krakendca/dca.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,9 @@ def filter_ignored_orders(pair_orders: dict, amount: float) -> dict:

def is_similiar_amount(order_info):
try:
order_amount = float(order_info.get("cost"))
except (ValueError, TypeError) as e:
price = float(order_info["descr"]["price"])
order_amount = float(order_info.get("vol")) * price
except (ValueError, TypeError, KeyError) as e:
print(
f'Cannot convert "cost"={repr(order_info.get("const"))} '
f"of order to float: {e}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ interactions:
uri: https://api.kraken.com/0/private/ClosedOrders
response:
body:
string: '{"error":[],"result":{"closed":{"OPVTXZ-5RISJ-CKZVHH":{"refid":null,"userref":0,"status":"closed","reason":null,"opentm":1618593523.7609,"closetm":1618593523.7627,"starttm":0,"expiretm":0,"descr":{"pair":"ETHEUR","type":"buy","ordertype":"limit","price":"2031.36","price2":"0","leverage":"none","order":"buy
0.00982008 ETHEUR @ limit 2031.36","close":""},"vol":"0.00982008","vol_exec":"0.00982008","cost":"33.33","fee":"0.05","price":"2031.36","stopprice":"0.00000","limitprice":"0.00000","misc":"","oflags":"fciq"}},"count":1}}'
string: '{"error":[],"result":{"closed":{"OPVTXZ-5RISJ-CKZVHH":{"refid":null,"userref":0,"status":"closed","reason":null,"opentm":1618593523.7609,"closetm":1618593523.7627,"starttm":0,"expiretm":0,"descr":{"pair":"ETHEUR","type":"buy","ordertype":"limit","price":"3385.26","price2":"0","leverage":"none","order":"buy
0.00982008 ETHEUR @ limit 2031.36","close":""},"vol":"0.00982008","vol_exec":"0.00982008","cost":"33.24","fee":"0.05","price":"2031.36","stopprice":"0.00000","limitprice":"0.00000","misc":"","oflags":"fciq"}},"count":1}}'
headers:
CF-Cache-Status:
- DYNAMIC
Expand Down
2 changes: 1 addition & 1 deletion tests/test_dca.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def test_handle_dca_logic_ignore_other_orders(self, capfd):
"system.\n"
"Current trade balance: 1650.3006 ZUSD.\n"
"Pair balances: 39.728 ZEUR, 0.109598362 XETH.\n"
"Ignoring an existing/closed order of 33.33\n"
"Ignoring an existing/closed order of 33.2435240208\n"
"Didn't DCA already today.\n"
"Current XETHZEUR ask price: 2083.16.\n"
"Create a 19.9481ZEUR buy limit order of 0.00957589XETH at "
Expand Down

0 comments on commit a87dc44

Please sign in to comment.