Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions data/trades/1_trades.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@
{"timestamp": "2025-07-31 12:19:12.499042", "side": "BUY", "pair": "EURQ/USD", "quantity": 5.0, "price": 1.1401, "total_value": 5.7005, "account_id": 1, "base_currency": "EURQ", "quote_currency": "ZUSD", "balances_after": {"EURQ": 20.474200000000003, "ZUSD": 19.53358916}}
{"timestamp": "2025-07-31 12:20:58.785230", "side": "SELL", "pair": "EURQ/USD", "quantity": 5.0, "price": 1.1436, "total_value": 5.718, "account_id": 1, "base_currency": "EURQ", "quote_currency": "ZUSD", "balances_after": {"EURQ": 15.474200000000003, "ZUSD": 25.251589159999998}}
{"timestamp": "2025-07-31 12:22:08.372194", "side": "BUY", "pair": "EURQ/USD", "quantity": 5.0, "price": 1.1402, "total_value": 5.7010000000000005, "account_id": 1, "base_currency": "EURQ", "quote_currency": "ZUSD", "balances_after": {"EURQ": 20.474200000000003, "ZUSD": 19.550589159999998}}
{"timestamp": "2025-07-31 15:06:59.848647", "side": "BUY", "pair": "EURQ/USD", "quantity": 5.0, "price": 1.1407, "total_value": 5.7035, "account_id": 1, "base_currency": "EURQ", "quote_currency": "ZUSD", "balances_after": {"EURQ": 25.474200000000003, "ZUSD": 13.847089159999998}}
{"timestamp": "2025-08-01 21:10:37.045183", "side": "SELL", "pair": "EURQ/USD", "quantity": 1.3042, "price": 1.1589, "total_value": 1.51143738, "account_id": 1, "base_currency": "EURQ", "quote_currency": "ZUSD", "balances_after": {"EURQ": 24.17, "ZUSD": 15.358526539999998}}
2 changes: 1 addition & 1 deletion resources/data/settings/settings.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
program:
name: "TradeByte"
version: "2.1.6"
version: "2.2.0"
debug: false
82 changes: 82 additions & 0 deletions src/clients/kraken_python_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,4 +332,86 @@ def get_my_recent_trades(self, pair=None, since=None, count=None):
except Exception as e:
if self.error_message:
print(f"KrakenPythonClient.get_my_recent_trades: {e}")
return False

def cancel_all_orders(self, asset=None):
"""
Cancel all open orders for a specific asset or all assets.

Args:
asset (str, optional): Trading pair to cancel orders for (e.g., 'XBTUSD').
If None, cancels all orders for all assets.

Returns:
dict: Dictionary containing:
- success: List of successfully cancelled order IDs
- failed: List of failed order IDs with error messages
- total_cancelled: Number of successfully cancelled orders
- total_failed: Number of failed cancellations
bool: False if unable to get open orders
"""
try:
# Get all open orders for the specified asset
orders_df = self.get_my_recent_orders(pair=asset)

if orders_df is False:
if self.error_message:
print("KrakenPythonClient.cancel_all_orders: Failed to get open orders")
return False

if orders_df.empty:
if self.error_message:
print(f"KrakenPythonClient.cancel_all_orders: No open orders found for {asset or 'any asset'}")
return {
'success': [],
'failed': [],
'total_cancelled': 0,
'total_failed': 0
}

# Initialize result tracking
successful_cancellations = []
failed_cancellations = []

# Cancel each order
for _, order in orders_df.iterrows():
order_id = order['order_id']
try:
cancel_result = self.cancel_order(order_id)

if cancel_result is not False:
successful_cancellations.append(order_id)
if self.error_message:
print(f"Successfully cancelled order: {order_id}")
else:
failed_cancellations.append({
'order_id': order_id,
'error': 'Cancel operation returned False'
})
if self.error_message:
print(f"Failed to cancel order: {order_id}")

except Exception as e:
failed_cancellations.append({
'order_id': order_id,
'error': str(e)
})
if self.error_message:
print(f"Exception while cancelling order {order_id}: {e}")

result = {
'success': successful_cancellations,
'failed': failed_cancellations,
'total_cancelled': len(successful_cancellations),
'total_failed': len(failed_cancellations)
}

if self.error_message:
print(f"Cancel all orders completed. Cancelled: {result['total_cancelled']}, Failed: {result['total_failed']}")

return result

except Exception as e:
if self.error_message:
print(f"KrakenPythonClient.cancel_all_orders: {e}")
return False
Loading