Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- exists_strategy = {'type': 'CHAIN', 'id': '00000000-0000-0000-0000-000000000001', 'payload': {'actions': [{'type': 'TRAILING_SELL', 'id': '00000000-0000-0000-0000-000000000002', 'payload': {'quantityUnits': 'percent', 'distance': 3, 'exchange': 'binance', 'market': 'USDT-BTC', 'distanceUnits': 'percent', 'quantity': 100}}, {'type': 'TRAILING_BUY', 'id': '00000000-0000-0000-0000-000000000003', 'payload': {'quantityUnits': 'basePercent', 'distance': 3, 'exchange': 'binance', 'market': 'USDT-BTC', 'distanceUnits': 'percent', 'quantity': 100}}, {'type': 'OR', 'id': '00000000-0000-0000-0000-000000000004', 'payload': {'actions': [{'type': 'CHAIN', 'id': '00000000-0000-0000-0000-000000000005', 'payload': {'actions': [{'type': 'STOP_LOSS', 'id': '00000000-0000-0000-0000-000000000006', 'payload': {'quantityUnits': 'percent', 'quantity': 100, 'stopRate': 3500, 'exchange': 'binance', 'market': 'USDT-BTC'}}]}}, {'type': 'CHAIN', 'id': '00000000-0000-0000-0000-000000000007', 'payload': {'actions': [{'type': 'WAIT_FOR_RATE', 'id': '00000000-0000-0000-0000-000000000008', 'payload': {'rate': 4500, 'exchange': 'binance', 'market': 'USDT-BTC', 'operator': '>='}}, {'type': 'TRAILING_SELL', 'id': '00000000-0000-0000-0000-000000000009', 'payload': {'quantityUnits': 'percent', 'distance': 5, 'exchange': 'binance', 'market': 'USDT-BTC', 'distanceUnits': 'percent', 'quantity': 100}}, {'type': 'AND', 'id': '00000000-0000-0000-0000-000000000010', 'payload': {'actions': [{'type': 'CHAIN', 'id': '00000000-0000-0000-0000-000000000011', 'payload': {'actions': [{'type': 'MARKET_BUY', 'id': '00000000-0000-0000-0000-000000000012', 'payload': {'quantityUnits': 'baseCoin', 'quantity': 100, 'exchange': 'binance', 'market': 'USDT-BTC'}}, {'type': 'MARKET_SELL', 'id': '00000000-0000-0000-0000-000000000013', 'payload': {'quantityUnits': 'percent', 'quantity': 100, 'exchange': 'binance', 'market': 'USDT-BTC'}}]}}, {'type': 'CHAIN', 'id': '00000000-0000-0000-0000-000000000014', 'payload': {'actions': [{'type': 'LIMIT_BUY', 'id': '00000000-0000-0000-0000-000000000015', 'payload': {'rate': 4500, 'quantity': 100, 'exchange': 'binance', 'market': 'USDT-BTC', 'quantityUnits': 'baseCoin'}}, {'type': 'LIMIT_SELL', 'id': '00000000-0000-0000-0000-000000000016', 'payload': {'rate': 4500, 'quantity': 100, 'exchange': 'binance', 'market': 'USDT-BTC', 'quantityUnits': 'percent'}}]}}]}}]}}]}}]}}
- import copy
- def delete_chunk_by_id(exists_strategy, chunk_id):
- strategy = copy.deepcopy(exists_strategy)
- if chunk_id == strategy.get('id'):
- return "Can't delete main node"
- def check_and_delete_chunk(chunk):
- for i, payload in enumerate(chunk):
- if payload.get('id') == chunk_id:
- return chunk.pop(i)
- if payload.get('payload').get('actions'):
- deleted_chunk = check_and_delete_chunk(payload.get('payload').get('actions'))
- if deleted_chunk:
- return deleted_chunk
- chunk = strategy.get('payload').get('actions')
- result = check_and_delete_chunk(chunk)
- return strategy if result else "ID not found"
- print(delete_chunk_by_id(strategy, chunk_id='00000000-0000-0000-0000-000000000002'))
Add Comment
Please, Sign In to add comment