# Order Vault

**Initialize**

This function initializes the `OrderVault` contract.

```solidity
initialize()
```

**Init**

This function initializes the `OrderVault` contract with various dependencies, including the priceManager, positionVault, settingsManager, vault, and operators contracts.

```solidity
init(
IPriceManager _priceManager, 
IPositionVault _positionVault, 
ISettingsManager _settingsManager, 
IVault _vault, 
IOperators _operators
)
```

**Create New Order**

This function is used by the positionVault contract to create a new order for opening a position. It takes parameters such as the position ID, account address, position type, token ID, position size and collateral, limit and stop prices, and referral address.

```solidity
createNewOrder(
uint256 _posId, 
address _account, 
bool _isLong, 
uint256 _tokenId, 
uint256 _positionType, 
uint256[] memory _params, 
address _refer
) external
```

**Cancel Market Order**

This function cancels a market order for a position. It sets the order's status to `CANCELED` and emits a `FinishOrder` event.

```solidity
cancelMarketOrder(uint256 _posId) public
```

**Cancel Pending Order**

This function cancels a pending order by setting its status to canceled. It requires the caller to be the owner of the position and the order to be in the pending status.

```solidity
cancelPendingOrder(address _account, uint256 _posId) external
```

**Update Order**

This function updates the information of an order, including its position type, collateral, size, and status.

```solidity
updateOrder(
uint256 _posId, 
uint256 _positionType, 
uint256 _collateral, 
uint256 _size, 
OrderStatus _status
) public status);
```

**Create Add Position Order**

This function creates an add position order for a position. It sets the owner, collateral delta, size delta, allowed price, timestamp, and fee for the add position order.

```solidity
createAddPositionOrder(
address _owner, 
uint256 _posId, 
uint256 _collateralDelta, 
uint256 _sizeDelta, 
uint256 _allowedPrice, 
uint256 _fee) external
```

**Cancel Add Position Order**

This function cancels an add position order by refunding the collateral and fee associated with the order.

```solidity
cancelAddPositionOrder(uint256 _posId) external
```

**Delete Add Position Order**

This function deletes an add position order without refunding the collateral or fee.

```solidity
deleteAddPositionOrder(uint256 _posId) external
```

**Create Decrease Position Order**

This function creates a decrease position order, which decreases the size of a position. It requires the order not to already exist for the given position ID.

```solidity
createDecreasePositionOrder(
uint256 _posId, 
uint256 _sizeDelta, 
uint256 _allowedPrice
) external
```

**Delete Decrease Position Order**

This function deletes a decrease position order.

```solidity
deleteDecreasePositionOrder(uint256 _posId) external
```

**Add Trigger Orders**

This function adds trigger orders to a position for take-profit and stop-loss purposes. It takes arrays of booleans indicating the type of trigger order, prices at which to trigger, and amount percentages to close.

```solidity
addTriggerOrders(
uint256 _posId, 
address _account, 
bool[] memory _isTPs, 
uint256[] memory _prices, 
uint256[] memory _amountPercents
) external
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.vela.exchange/vela-knowledge-base/developers/contract-functions/order-vault.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
