def sync_operation(operation_dict: Dict, operation: model.Operation = None) -> model.Operation: if not operation: operation = model.Operation() if operation_dict.get('position_id'): operation.position_id = operation_dict['position_id'] operation.kind = operation_dict['kind'] operation.future = operation_dict['future_symbol'] operation.future_price = operation_dict['future_price'] operation.spot = operation_dict['spot_symbol'] operation.spot_price = operation_dict['spot_price'] operation.direct_ratio = operation_dict['direct_ratio'] operation.hours = operation_dict['hours'] operation.hour_ratio = operation_dict['hour_ratio'] operation.days = operation_dict['days'] operation.year_ratio = operation_dict['year_ratio'] operation.contract_size = operation_dict['contract_size'] operation.contract_qty = operation_dict['contract_qty'] operation.buy_per_contract = operation_dict['buy_per_contract'] operation.tick_size = operation_dict['tick_size'] operation.base_asset = operation_dict['base_asset'] operation.state = operation_dict['state'] operation.close_reason = operation_dict.get('close_reason') return operation