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

# Overview

By default, all Wires created in the sandbox environment are moved through the normal [Wire workflow](/reference/wire#workflow), eventually ending with the status `sent`.

Wire simulations allow developers to manually trigger a wire into various states that may arise in the course of production money movement. Developers can better understand the flow of funds by manually updating a wire’s status to `sent` or `error` at an accelerated timeline, as defined in the [Simulation Types](#wire-simulation-types) table below. The corresponding impact to an account’s balance, transactions, and holds (if applicable) can also be observed by calling the various respective endpoints.

The three wire simulation types are listed below.

## Wire Simulation Types

| Simulation Type         | Explanation                                                                                                                                                                                                                      |
| ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| wire.processing\_sent   | Simulate a wire being sent by validating, processing and sending the wire immediately. If a wire fails validation or processing, the wire is instead updated to an `error` status.                                               |
| wire.processing\_voided | Simulate a wire being voided by validating, processing, sending and then erroring the wire immediately. Similarly to processing\_sent, any validation or processing failure will cause the wire status to be updated to `error`. |
| wire.incoming\_wire     | Simulate an incoming wire.                                                                                                                                                                                                       |

## Setting up a Wire Sent or Voided Simulation

A wire must first be created via a `POST` request to the `/wire` endpoint with all the required parameters. In addition to this, the optional `userdata` field must be set and have the following parameters in order to be eligible for wire simulations:

| Parameter | Type    | Required? | Description                                                                                                                               |
| --------- | ------- | --------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
| manual    | boolean | Required  | `true` should be provided to indicate that this is a simulation request. This field prevents the wire from automatically being processed. |

## Create a Wire Sent or Voided Simulation

Initiate either a `wire.processing_sent` or a `wire.processing_voided` simulation.

<CodeGroup>
  ```bash bash theme={null}
  POST https://api.sandbox.treasuryprime.com/simulation
  ```
</CodeGroup>

### Wire Sent or Voided Request Body

| Parameter  | Type   | Required? | Description                        |
| ---------- | ------ | --------- | ---------------------------------- |
| type       | string | Required  | The wire simulation type.          |
| simulation | object | Required  | The simulation request sub-object. |

##### Simulation Sub-Object

| Parameter | Type   | Required? | Description                                                     |
| --------- | ------ | --------- | --------------------------------------------------------------- |
| wire\_id  | string | Required  | ID of the wire to use as the source for simulated transactions. |

##### Example Request

<CodeGroup>
  ```bash bash theme={null}
  $ curl -u $API_KEY_ID:$API_SECRET_KEY https://api.sandbox.treasuryprime.com/simulation \
    -H 'Content-Type: application/json' \
    -d '{
          "type": "wire.processing_sent",
          "simulation": {
            "wire_id": "wire_123456",
          }
        }'
  ```
</CodeGroup>

##### Success Response

There will be no response body. The response code will be a `202 - accepted`.

##### Error Response

<CodeGroup>
  ```bash bash theme={null}
  {
    "error": "Invalid simulation request or simulation not implemented"
  }
  ```
</CodeGroup>

### Example: How to Simulate a Sent Wire

A common flow for a wire simulation is creating a wire, and then calling the simulation endpoint with the id of the wire. See [wire](/reference/wire) for example wire requests. The following calls outline simulating a wire sent simulation.

<CodeGroup>
  ```bash bash theme={null}
  $ curl -u $API_KEY_ID:$API_SECRET_KEY https://api.sandbox.treasuryprime.com/wire \
    -H 'Content-Type: application/json' \
    -d '{
          "account_id": "acct_1234567890",
          "amount": "10300.00",
          "counterparty_id": "cp_0987654321",
          "userdata": {
            "manual": true
          }
        }'
  ```
</CodeGroup>

<CodeGroup>
  ```bash bash theme={null}
  $ curl -u $API_KEY_ID:$API_SECRET_KEY https://api.sandbox.treasuryprime.com/simulation \
    -H 'Content-Type: application/json' \
    -d '{
          "type": "wire.processing_sent",
          "simulation": {
            "wire_id": "wire_104",
          }
        }'
  ```
</CodeGroup>

##### Response

No response body is returned. A `202` HTTP status indicates a successful simulation.

#### Verifying a Successful Simulation

To ensure that the simulation was run successfully, call the `GET /wire/:id` endpoint to confirm that the status of the wire has been updated to `sent` or `error`. The funds should have been moved to/from an account and a corresponding transaction should appear.

## Create an Incoming Wire Simulation

Initiating a `wire.incoming_wire` simulates a wire that was originated outside of the Treasury Prime API from a different bank. This will create a transaction on an account as well as an [incoming wire object](/reference/incoming-wire#the-incoming-wire-transfer-object). You can then use the [/incoming wire](/reference/incoming-wire) endpoint to access this object.

<CodeGroup>
  ```bash bash theme={null}
  POST https://api.sandbox.treasuryprime.com/simulation
  ```
</CodeGroup>

### Simulation Request Body

| Parameter                         | Type   | Required? | Description                                                                                         |
| --------------------------------- | ------ | --------- | --------------------------------------------------------------------------------------------------- |
| account\_id                       | string | Required  | The id of the account that this wire should be originated from.                                     |
| amount                            | string | Required  | Amount of money in dollars to transfer, as a string with two-decimal precision.                     |
| originator                        | object | Required  | A Wire Bank sub-object containing information about the wire originator (See below for definition). |
| originator\_to\_beneficiary\_info | string | Required  | Information sent by the wire originator to the receiver.                                            |

##### Originator Sub-object

| Parameter  | Type   | Required? | Description                                                |
| ---------- | ------ | --------- | ---------------------------------------------------------- |
| address    | object |           | A Wire Bank Address sub-object (See below for definition). |
| name       | string |           | Name of the intermediary bank (maximum of 35 characters).  |
| bank\_data | object | Required  | Bank details sub-ojbect (See below for definition).        |

##### Wire Bank Address Sub-object

| Parameter       | Type   | Required? | Description                                                            |
| --------------- | ------ | --------- | ---------------------------------------------------------------------- |
| street\_line\_1 | string | Required  | Street address (first line; maximum of 35 characters).                 |
| street\_line\_2 | string |           | Street address (second line, if applicable; maximum of 35 characters). |
| city            | string | Required  | City (maximum of 21 characters.)                                       |
| state           | string | Required  | U.S. State (two letter abbreviation).                                  |
| postal\_code    | string | Required  | Postal code (5-digit or 5+4 Zip Code for U.S. addresses).              |

##### Wire Bank Data Sub-object

| Parameter       | Type   | Required? | Description                                                                                                                 |
| --------------- | ------ | --------- | --------------------------------------------------------------------------------------------------------------------------- |
| account\_number | string | Required  | Bank Account number.                                                                                                        |
| account\_type   | string | Required  | Account type.                                                                                                               |
| address         | array  |           | Unparsed bank address data.                                                                                                 |
| bank\_name      | string |           | Name of the bank.                                                                                                           |
| routing\_number | string | Required  | Valid 9-digit [ABA routing transit number](https://en.wikipedia.org/wiki/Routing_transit_number) associated with this bank. |

##### Example Request

The following call outlines simulating an incoming wire.

<CodeGroup>
  ```bash bash theme={null}
  $ curl -u $API_KEY_ID:$API_SECRET_KEY https://api.sandbox.treasuryprime.com/simulation \
    -H 'Content-Type: application/json' \
    -d '{
          "type": "wire.incoming_wire",
          "simulation": {
            "account_id": "acct_123456",
            "originator_to_beneficiary_info": "DEPOSIT",
            "amount": "100.00",
            "originator": {
              "name": "ORIGINATOR LLC",
              "address": [
                "22 Main St",
                "Town GA 012345-7500"
              ],
              "bank_data": {
               "account_number": "123456789",
               "account_type": "checking",
               "address": [],
               "bank_name": "",
               "routing_number": "123456789"
              }
            }
          }
        }'
  ```
</CodeGroup>

##### Success Response

There will be no response body. The response code will be a `202 - Accepted`.

##### Error Response

<CodeGroup>
  ```bash bash theme={null}
  {
    "error": "Invalid simulation request or simulation not implemented"
  }
  ```
</CodeGroup>

##### Verifying a Successful Simulation

To ensure that the simulation was run successfully, call the [`GET /wire/incoming_wire`](/reference/incoming-wire) endpoint to list the incoming wires and fetch the most recently created ID. The funds should have been moved to the corresponding account and a corresponding transaction should appear when running `GET /account/:id/transaction`.
