> ## Documentation Index
> Fetch the complete documentation index at: https://docs.fairground.fi/llms.txt
> Use this file to discover all available pages before exploring further.

# updatePositionLeverage

> Python SDK reference for updatePositionLeverage.

Update position leverage and return the updated position object.

<ParamField path="marketId" type="int" required>
  The market ID of the position to update
</ParamField>

<ParamField path="leverage" type="float" required>
  The new target leverage
</ParamField>

<ResponseField name="returns" type="string" required>
  Updated position object as a dictionary with modified leverage field,
  or None if position doesn't exist
</ResponseField>

```python theme={null}
async def updatePositionLeverage(marketId: int, leverage: float):
    existing = await retrieveExistingPosition(marketId)
    if existing is None:
        print('No position to update')
        return None
    original_leverage = existing.leverage
    if leverage > original_leverage:
        is_long = existing.side == Side.SIDE_LONG
        print(f'Increasing leverage from {original_leverage}x to {leverage}x')
        await openOrder(marketId, existing.allocated_margin, convertFloatToUINT(leverage, LEVERAGE_SCALAR), is_long, existing.entry_price)
    elif leverage < original_leverage:
        print(f'Decreasing leverage from {original_leverage}x to {leverage}x')
        size_reduction = existing.nominalSize * (1 - leverage / original_leverage)
        orderId = existing.associated_orders[0].order_id
        await reduceOrder(marketId, orderId, convertFloatToUINT(size_reduction, LEVERAGE_SCALAR), existing.entry_price)
    else:
        print(f'Leverage unchanged at {leverage}x')
        return MessageToDict(existing, always_print_fields_with_no_presence=True)
    existing.leverage = leverage
    print(f'Transaction submitted successfully (leverage: {original_leverage}x → {leverage}x)')
    return MessageToDict(existing, always_print_fields_with_no_presence=True)
```
