> This page is for Excel.

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

# Requests in DDE

## Understanding DDE Requests

Requests made through the Excel DDE are handled through two primary methods: An [Excel Formula Structure](#excel-formula-structure) or a [DDEPoke method call](#dde-poke-requests).

Requests with the TWS API that do not take any arguments, such as EClient.reqCurrentTime, EClient.reqOpenOrders, or EClient.reqPositions are all made using an Excel Formula request using the [DDERequest Method call](https://learn.microsoft.com/en-us/office/vba/api/excel.application.dderequest). Please note there is a known restriction in Excel that the DDERequest method can only send 255 symbols in its request.

For requests that contain at least one or more argument, such as EClient.reqMktData, EClient.reqContractDetails, or EClient.placeOrder, must be made using the [Visual Basic DDEPoke Method Call](https://learn.microsoft.com/en-us/office/vba/api/excel.application.ddepoke).

Please be sure to review the underlying [TWS API functions](/docs/tws-api/doc/introduction) to understand which requests have arguments and which do not.

---

## Excel Formula Structure

Requests with the TWS API that do not take any arguments, such as EClient.reqCurrentTime, EClient.reqOpenOrders, or EClient.reqPositions are all made using an Excel Formula request using the [DDERequest Method call](https://learn.microsoft.com/en-us/office/vba/api/excel.application.dderequest).

There is a known restriction in Excel that the DDERequest method can only send 255 symbols in its request.

The Excel DDE formula is comprised of several separate components. As a baseline there is the Server, also known as the Service Name from your DDE Socket Bridge. This is followed by your Request Type, and finally the Request String.

We will use this formula to elaborate on this structure: `=@Stwsserver|reqCurrentTime!id4?time`

* '=@Stwsserver': This first part indicates the Service Name set for our socket bridge connection. The '=@S' indicates the start of a formula, and that the next value will be our Service Name.
* '|': The pipe, the character typically above the Enter/Return key, is used to divide our service name from the rest of the request.
* 'reqCurrentTime' immediately after the pipe is used to state the Request Type we would like to make. These request types are based on the TWS API EClient request types documented in the [TWS API Documentation](/docs/tws-api/doc/introduction).\* "!'": The exclamation, (!) indicates the start of the request with the request ID. This is formatted as id1 or whichever number is pertinent.
  * After the ID we should indicate a question mark (?), to denote which parameter to receive. In the example above, we are both requesting the current time and then printing the time value to the cell using "?time".

---

## DDE Poke Requests

For requests that contain at least one or more argument, the request must be made using the [Visual Basic DDEPoke Method Call](https://learn.microsoft.com/en-us/office/vba/api/excel.application.ddepoke).

The DDEPoke request method call will send Excel table values in binary format to the [DdeSocketBridge](/docs/excel/dde/socket-bridge).

The VBA code below is an example of how DDE Poke requests are sent from Excel to the DDE Socket Bridge. Please be aware that this function call uses the sendPoke function of the TwsDde Sample's "util.bas" file located at "C:\TWS API\samples\Excel\TwsDde\util.bas".

```
Sub sendPlaceOrder(server As String, cell As Range)

    ' get id
    Dim id As String
    Dim placeOrderStr As String
    Dim requestStr As String
    Dim i As Integer
    Dim columnsArray() As Variant
    Dim columnIndex As Integer

    With Worksheets(STR_SHEET_NAME)
        id = .Cells(cell.row, errorColumnIndex + 1).value
        If id = util.STR_EMPTY Then ' none exists yet -- is original placement as opposed to modify
            id = OrderFunctions.makeId(server)

            ' fill "id" column with id
            .Cells(cell.row, errorColumnIndex + 1).value = id
        End If
        
        
        ' fill "error" column with formula
        .Cells(cell.row, errorColumnIndex).Formula = util.composeLink(server, requestStr, id, util.STR_ERROR)

        
        ' send request
        util.sendPoke Worksheets(STR_SHEET_NAME), server, placeOrderStr, id, cell, startOfContractColumns, getContractColumns(), 0, idColumnIndex, orderBaseColumnsStart, orderBaseColumnsEnd, orderExtColumnsStart, orderExtColumnsEnd
        
        ' fill columns with formulas
        For i = 0 To UBound(columnsArray) - LBound(columnsArray)
            .Cells(cell.row, columnIndex + i).Formula = util.composeLink(server, requestStr, id, columnsArray(i))
        Next i
    End With

End Sub
```