> This page is for TWS API.

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://ibkrcampus.com/docs/llms.txt.

# Next Valid ID

## Introduction

`EWrapper.nextValidId` provides the next valid identifier needed to place a new order. After initially obtaining the next valid ID, it is recommended to increment this value locally for subsequent orders within the same session rather than making repeated requests.

---

## Request Next Valid ID

`EClient.reqIds(numIds)`

Requests the next valid order ID at the current moment.

**`numIds`** `int`

Depreciated. This value will not affect the value returned to `nextValidId`. A value of `-1` is suggested.

---

\


#### Python

```python
self.reqIds(-1)
```

#### Java

```java
client.reqIds(-1);
```

#### C++

```cpp
m_pClient->reqIds(-1);
```

#### C\#

```csharp
client.reqIds(-1);
```

#### VB.NET

```vbnet
client.reqIds(-1)
```

---

## Receive Next Valid ID

`EWrapper.nextValidId(orderId)`

Receives the next valid order ID. This function is invoked automatically upon a successful connection as well as after any `EClient.reqIds` call.

**`orderId`** `int`

The next available valid ID for placing orders.

---

\


#### Python

```python
def nextValidId(self, orderId: int):
	super().nextValidId(orderId)
	self.nextOrderId = orderId
	print("NextValidId:", orderId)
```

#### Java

```java
@Override
public void nextValidId(int orderId) {
	super.nextValidId(orderId);
	System.out.println("Next Valid Id: ["+orderId+"]");
	nextOrderId = orderId;
}
```

#### C++

```cpp
void TestCppClient::nextValidId( OrderId orderId) {
    printf( "Next Valid Id: %ld\n", orderId);
    m_orderId = orderId;
}
```

#### C\#

```csharp
public virtual void nextValidId(int orderId)
{
	Console.WriteLine("Next Valid Id: "+orderId);
	nextOrderId = orderId;
}
```

#### VB.NET

```vbnet
Public Sub nextValidId(orderId As Integer) Implements IBApi.EWrapper.nextValidId
	Me.NextOrderId = orderId
End Sub
```

---

## Reset Order ID Sequence

The order ID sequence can be reset from within the TWS API Settings. To do so, open TWS Global Configuration, navigate to the API Settings, and select the **Reset API order ID sequence** button.

![Reset API Order ID Sequence](/docs/_fern-files/_img/a1d3e8fb968af26baa1af260bb7b94ad8f504a2a29c99a86ecae9543d72316d7.webp)

> **Info**
>
> The order ID sequence persists between sessions. If you restart your application without resetting, the next valid ID continues from where it left off.

> **Warning**
>
> The order ID sequence can only be reset if there are no active API orders currently open.