Class TradingApi

java.lang.Object
markets.alpaca.client.openapi.broker.api.TradingApi

public class TradingApi extends Object
Generated client for TradingApi operations.

This class is generated from the configured OpenAPI spec. Operation method Javadocs include OAS summaries, descriptions, parameters, return types, response details, and external documentation links when present in the spec.

Operations

  • closeAllPositionsForAccount: Close All Positions for an Account
  • closePositionForAccountBySymbol: Close a Position for an Account
  • createOrderForAccount: Create an Order for an Account
  • deleteAllOrdersForAccount: Cancel all Open Orders For an Account
  • deleteOrderForAccount: Cancel an Open Order
  • getAllOrdersForAccount: Retrieve a List of Orders
  • getOrderByClientOrderIdForAccount: Retrieves a single order specified by the client order ID.
  • getOrderForAccount: Retrieve an Order by its ID
  • getPositionsForAccount: List Open Positions for an Account
  • getPositionsForAccountBySymbol: Get an Open Position for account by Symbol or AssetId
  • getV1AccountTradingLimits: Retrieve real-time Trading Limits for an Account
  • getV1AccountsPositions: Bulk Fetch All Accounts Positions
  • getV1TradingAccountsAccountIdOrdersEstimation: Estimate an Order
  • optionDoNotExercise: Do Not Exercise an Options Position
  • optionExercise: Exercise an Options Position
  • patchPATCHV1TradingAccountsAccountIdAccountConfigurations: Update Trading Configurations for an Account
  • replaceOrderForAccount: Replace an Order
  • subscribeToTradeV2SSE: Subscribe to Trade Events (SSE)
  • Constructor Details

    • TradingApi

      public TradingApi()
    • TradingApi

      public TradingApi(ApiClient apiClient)
  • Method Details

    • getApiClient

      public ApiClient getApiClient()
    • setApiClient

      public void setApiClient(ApiClient apiClient)
    • getHostIndex

      public int getHostIndex()
    • setHostIndex

      public void setHostIndex(int hostIndex)
    • getCustomBaseUrl

      public String getCustomBaseUrl()
    • setCustomBaseUrl

      public void setCustomBaseUrl(String customBaseUrl)
    • closeAllPositionsForAccountCall

      public okhttp3.Call closeAllPositionsForAccountCall(@Nonnull UUID accountId, @Nullable Boolean cancelOrders, ApiCallback _callback) throws ApiException
      Build call for closeAllPositionsForAccount
      Parameters:
      accountId - Account identifier. (required)
      cancelOrders - If true is specified, cancel all open orders before liquidating all positions. (optional)
      _callback - Callback for upload/download progress
      Returns:
      Call to execute
      Throws:
      ApiException - If fail to serialize the request body object
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      207 HTTP 207 Multi-Status with body; an array of objects that include the order id and http status code for each status request. -
      500 Failed to liquidate some positions -
    • closeAllPositionsForAccount

      public List<PositionClosedResponse> closeAllPositionsForAccount(@Nonnull UUID accountId, @Nullable Boolean cancelOrders) throws ApiException
      Close All Positions for an Account Closes (liquidates) all of the account's open long and short positions. A response will be provided for each order that is attempted to be cancelled. If an order is no longer cancelable, the server will respond with status 500 and reject the request.
      Parameters:
      accountId - Account identifier. (required)
      cancelOrders - If true is specified, cancel all open orders before liquidating all positions. (optional)
      Returns:
      List<PositionClosedResponse>
      Throws:
      ApiException - If fail to call the API, e.g. server error or cannot deserialize the response body
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      207 HTTP 207 Multi-Status with body; an array of objects that include the order id and http status code for each status request. -
      500 Failed to liquidate some positions -
    • closeAllPositionsForAccountWithHttpInfo

      public ApiResponse<List<PositionClosedResponse>> closeAllPositionsForAccountWithHttpInfo(@Nonnull UUID accountId, @Nullable Boolean cancelOrders) throws ApiException
      Close All Positions for an Account Closes (liquidates) all of the account's open long and short positions. A response will be provided for each order that is attempted to be cancelled. If an order is no longer cancelable, the server will respond with status 500 and reject the request.
      Parameters:
      accountId - Account identifier. (required)
      cancelOrders - If true is specified, cancel all open orders before liquidating all positions. (optional)
      Returns:
      ApiResponse<List<PositionClosedResponse>>
      Throws:
      ApiException - If fail to call the API, e.g. server error or cannot deserialize the response body
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      207 HTTP 207 Multi-Status with body; an array of objects that include the order id and http status code for each status request. -
      500 Failed to liquidate some positions -
    • closeAllPositionsForAccountAsync

      public okhttp3.Call closeAllPositionsForAccountAsync(@Nonnull UUID accountId, @Nullable Boolean cancelOrders, ApiCallback<List<PositionClosedResponse>> _callback) throws ApiException
      Close All Positions for an Account (asynchronously) Closes (liquidates) all of the account's open long and short positions. A response will be provided for each order that is attempted to be cancelled. If an order is no longer cancelable, the server will respond with status 500 and reject the request.
      Parameters:
      accountId - Account identifier. (required)
      cancelOrders - If true is specified, cancel all open orders before liquidating all positions. (optional)
      _callback - The callback to be executed when the API call finishes
      Returns:
      The request call
      Throws:
      ApiException - If fail to process the API call, e.g. serializing the request body object
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      207 HTTP 207 Multi-Status with body; an array of objects that include the order id and http status code for each status request. -
      500 Failed to liquidate some positions -
    • closePositionForAccountBySymbolCall

      public okhttp3.Call closePositionForAccountBySymbolCall(@Nonnull UUID accountId, @Nonnull String symbolOrAssetId, @Nullable String qty, @Nullable String percentage, ApiCallback _callback) throws ApiException
      Build call for closePositionForAccountBySymbol
      Parameters:
      accountId - Account identifier. (required)
      symbolOrAssetId - The symbol or asset_id (required)
      qty - Optional the number of shares to liquidate. Can accept up to 9 decimal points. Cannot work with percentage (optional)
      percentage - percentage of position to liquidate. Must be between 0 and 100. Would only sell fractional if position is originally fractional. Can accept up to 9 decimal points. Cannot work with qty (optional)
      _callback - Callback for upload/download progress
      Returns:
      Call to execute
      Throws:
      ApiException - If fail to serialize the request body object
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      200 OK -
    • closePositionForAccountBySymbol

      public Order closePositionForAccountBySymbol(@Nonnull UUID accountId, @Nonnull String symbolOrAssetId, @Nullable String qty, @Nullable String percentage) throws ApiException
      Close a Position for an Account Closes (liquidates) the account's open position for the given symbol. Works for both long and short positions.
      Parameters:
      accountId - Account identifier. (required)
      symbolOrAssetId - The symbol or asset_id (required)
      qty - Optional the number of shares to liquidate. Can accept up to 9 decimal points. Cannot work with percentage (optional)
      percentage - percentage of position to liquidate. Must be between 0 and 100. Would only sell fractional if position is originally fractional. Can accept up to 9 decimal points. Cannot work with qty (optional)
      Returns:
      Order
      Throws:
      ApiException - If fail to call the API, e.g. server error or cannot deserialize the response body
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      200 OK -
    • closePositionForAccountBySymbolWithHttpInfo

      public ApiResponse<Order> closePositionForAccountBySymbolWithHttpInfo(@Nonnull UUID accountId, @Nonnull String symbolOrAssetId, @Nullable String qty, @Nullable String percentage) throws ApiException
      Close a Position for an Account Closes (liquidates) the account's open position for the given symbol. Works for both long and short positions.
      Parameters:
      accountId - Account identifier. (required)
      symbolOrAssetId - The symbol or asset_id (required)
      qty - Optional the number of shares to liquidate. Can accept up to 9 decimal points. Cannot work with percentage (optional)
      percentage - percentage of position to liquidate. Must be between 0 and 100. Would only sell fractional if position is originally fractional. Can accept up to 9 decimal points. Cannot work with qty (optional)
      Returns:
      ApiResponse<Order>
      Throws:
      ApiException - If fail to call the API, e.g. server error or cannot deserialize the response body
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      200 OK -
    • closePositionForAccountBySymbolAsync

      public okhttp3.Call closePositionForAccountBySymbolAsync(@Nonnull UUID accountId, @Nonnull String symbolOrAssetId, @Nullable String qty, @Nullable String percentage, ApiCallback<Order> _callback) throws ApiException
      Close a Position for an Account (asynchronously) Closes (liquidates) the account's open position for the given symbol. Works for both long and short positions.
      Parameters:
      accountId - Account identifier. (required)
      symbolOrAssetId - The symbol or asset_id (required)
      qty - Optional the number of shares to liquidate. Can accept up to 9 decimal points. Cannot work with percentage (optional)
      percentage - percentage of position to liquidate. Must be between 0 and 100. Would only sell fractional if position is originally fractional. Can accept up to 9 decimal points. Cannot work with qty (optional)
      _callback - The callback to be executed when the API call finishes
      Returns:
      The request call
      Throws:
      ApiException - If fail to process the API call, e.g. serializing the request body object
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      200 OK -
    • createOrderForAccountCall

      public okhttp3.Call createOrderForAccountCall(@Nonnull UUID accountId, @Nonnull CreateOrderRequest createOrderRequest, ApiCallback _callback) throws ApiException
      Build call for createOrderForAccount
      Parameters:
      accountId - Account identifier. (required)
      createOrderRequest - (required)
      _callback - Callback for upload/download progress
      Returns:
      Call to execute
      Throws:
      ApiException - If fail to serialize the request body object
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      200 OK -
      400 Malformed input. -
      403 Request is forbidden -
      404 Resource does not exist. -
      422 Some parameters are not valid -
    • createOrderForAccount

      public Order createOrderForAccount(@Nonnull UUID accountId, @Nonnull CreateOrderRequest createOrderRequest) throws ApiException
      Create an Order for an Account Creating an order for your end customer. Each trading request must pass in the account_id in the URL. - Note that when submitting crypto orders, `market`, `limit` and `stop_limit` orders are supported while the supported `time_in_force` values are `gtc`, and `ioc`. - For equities and crypto we accept fractional orders as well with either `notional` or `qty` provided. - Note that submitting an options order is only available for partners who have been enabled for Options BETA. - In case of Fixed Income, only `market` and `limit` order types with `day` `time_in_force` are supported, and order replacement is not supported. Note that submitting Fixed Income orders is only available for partners who have been enabled for Fixed Income. - Note that submitting DMA orders (using `advanced_instructions` with `algorithm: DMA`) is only available for partners/correspondents who have been enabled for DMA. - For IPO indications of interest (`asset_class: \"ipo\"`), the `symbol` is the offering reference returned by [`GET /v1/ipos`](#operation/listIPOOfferings) (e.g. `FI111225`). IPO orders are notional-only (`notional` required, `qty` must be omitted), buy-side, `market` type, and `gtc` time_in_force. Indications of interest can be replaced or canceled while the offering is open via [`PATCH /v1/trading/accounts/{account_id}/orders/{order_id}`](#operation/replaceOrderForAccount) and [`DELETE /v1/trading/accounts/{account_id}/orders/{order_id}`](#operation/deleteOrderForAccount).
      Parameters:
      accountId - Account identifier. (required)
      createOrderRequest - (required)
      Returns:
      Order
      Throws:
      ApiException - If fail to call the API, e.g. server error or cannot deserialize the response body
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      200 OK -
      400 Malformed input. -
      403 Request is forbidden -
      404 Resource does not exist. -
      422 Some parameters are not valid -
    • createOrderForAccountWithHttpInfo

      public ApiResponse<Order> createOrderForAccountWithHttpInfo(@Nonnull UUID accountId, @Nonnull CreateOrderRequest createOrderRequest) throws ApiException
      Create an Order for an Account Creating an order for your end customer. Each trading request must pass in the account_id in the URL. - Note that when submitting crypto orders, `market`, `limit` and `stop_limit` orders are supported while the supported `time_in_force` values are `gtc`, and `ioc`. - For equities and crypto we accept fractional orders as well with either `notional` or `qty` provided. - Note that submitting an options order is only available for partners who have been enabled for Options BETA. - In case of Fixed Income, only `market` and `limit` order types with `day` `time_in_force` are supported, and order replacement is not supported. Note that submitting Fixed Income orders is only available for partners who have been enabled for Fixed Income. - Note that submitting DMA orders (using `advanced_instructions` with `algorithm: DMA`) is only available for partners/correspondents who have been enabled for DMA. - For IPO indications of interest (`asset_class: \"ipo\"`), the `symbol` is the offering reference returned by [`GET /v1/ipos`](#operation/listIPOOfferings) (e.g. `FI111225`). IPO orders are notional-only (`notional` required, `qty` must be omitted), buy-side, `market` type, and `gtc` time_in_force. Indications of interest can be replaced or canceled while the offering is open via [`PATCH /v1/trading/accounts/{account_id}/orders/{order_id}`](#operation/replaceOrderForAccount) and [`DELETE /v1/trading/accounts/{account_id}/orders/{order_id}`](#operation/deleteOrderForAccount).
      Parameters:
      accountId - Account identifier. (required)
      createOrderRequest - (required)
      Returns:
      ApiResponse<Order>
      Throws:
      ApiException - If fail to call the API, e.g. server error or cannot deserialize the response body
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      200 OK -
      400 Malformed input. -
      403 Request is forbidden -
      404 Resource does not exist. -
      422 Some parameters are not valid -
    • createOrderForAccountAsync

      public okhttp3.Call createOrderForAccountAsync(@Nonnull UUID accountId, @Nonnull CreateOrderRequest createOrderRequest, ApiCallback<Order> _callback) throws ApiException
      Create an Order for an Account (asynchronously) Creating an order for your end customer. Each trading request must pass in the account_id in the URL. - Note that when submitting crypto orders, `market`, `limit` and `stop_limit` orders are supported while the supported `time_in_force` values are `gtc`, and `ioc`. - For equities and crypto we accept fractional orders as well with either `notional` or `qty` provided. - Note that submitting an options order is only available for partners who have been enabled for Options BETA. - In case of Fixed Income, only `market` and `limit` order types with `day` `time_in_force` are supported, and order replacement is not supported. Note that submitting Fixed Income orders is only available for partners who have been enabled for Fixed Income. - Note that submitting DMA orders (using `advanced_instructions` with `algorithm: DMA`) is only available for partners/correspondents who have been enabled for DMA. - For IPO indications of interest (`asset_class: \"ipo\"`), the `symbol` is the offering reference returned by [`GET /v1/ipos`](#operation/listIPOOfferings) (e.g. `FI111225`). IPO orders are notional-only (`notional` required, `qty` must be omitted), buy-side, `market` type, and `gtc` time_in_force. Indications of interest can be replaced or canceled while the offering is open via [`PATCH /v1/trading/accounts/{account_id}/orders/{order_id}`](#operation/replaceOrderForAccount) and [`DELETE /v1/trading/accounts/{account_id}/orders/{order_id}`](#operation/deleteOrderForAccount).
      Parameters:
      accountId - Account identifier. (required)
      createOrderRequest - (required)
      _callback - The callback to be executed when the API call finishes
      Returns:
      The request call
      Throws:
      ApiException - If fail to process the API call, e.g. serializing the request body object
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      200 OK -
      400 Malformed input. -
      403 Request is forbidden -
      404 Resource does not exist. -
      422 Some parameters are not valid -
    • deleteAllOrdersForAccountCall

      public okhttp3.Call deleteAllOrdersForAccountCall(@Nonnull UUID accountId, ApiCallback _callback) throws ApiException
      Build call for deleteAllOrdersForAccount
      Parameters:
      accountId - Account identifier. (required)
      _callback - Callback for upload/download progress
      Returns:
      Call to execute
      Throws:
      ApiException - If fail to serialize the request body object
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      207 HTTP 207 Multi-Status with body, which is an array of objects that include the order id, http status code and an order object for each cancellation request. -
      400 Malformed input. -
      404 Resource does not exist. -
    • deleteAllOrdersForAccount

      public List<OrderClosedResponse> deleteAllOrdersForAccount(@Nonnull UUID accountId) throws ApiException
      Cancel all Open Orders For an Account Attempts to cancel all open orders. A response will be provided for each order that is attempted to be cancelled.
      Parameters:
      accountId - Account identifier. (required)
      Returns:
      List<OrderClosedResponse>
      Throws:
      ApiException - If fail to call the API, e.g. server error or cannot deserialize the response body
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      207 HTTP 207 Multi-Status with body, which is an array of objects that include the order id, http status code and an order object for each cancellation request. -
      400 Malformed input. -
      404 Resource does not exist. -
    • deleteAllOrdersForAccountWithHttpInfo

      public ApiResponse<List<OrderClosedResponse>> deleteAllOrdersForAccountWithHttpInfo(@Nonnull UUID accountId) throws ApiException
      Cancel all Open Orders For an Account Attempts to cancel all open orders. A response will be provided for each order that is attempted to be cancelled.
      Parameters:
      accountId - Account identifier. (required)
      Returns:
      ApiResponse<List<OrderClosedResponse>>
      Throws:
      ApiException - If fail to call the API, e.g. server error or cannot deserialize the response body
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      207 HTTP 207 Multi-Status with body, which is an array of objects that include the order id, http status code and an order object for each cancellation request. -
      400 Malformed input. -
      404 Resource does not exist. -
    • deleteAllOrdersForAccountAsync

      public okhttp3.Call deleteAllOrdersForAccountAsync(@Nonnull UUID accountId, ApiCallback<List<OrderClosedResponse>> _callback) throws ApiException
      Cancel all Open Orders For an Account (asynchronously) Attempts to cancel all open orders. A response will be provided for each order that is attempted to be cancelled.
      Parameters:
      accountId - Account identifier. (required)
      _callback - The callback to be executed when the API call finishes
      Returns:
      The request call
      Throws:
      ApiException - If fail to process the API call, e.g. serializing the request body object
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      207 HTTP 207 Multi-Status with body, which is an array of objects that include the order id, http status code and an order object for each cancellation request. -
      400 Malformed input. -
      404 Resource does not exist. -
    • deleteOrderForAccountCall

      public okhttp3.Call deleteOrderForAccountCall(@Nonnull UUID accountId, @Nonnull String orderId, ApiCallback _callback) throws ApiException
      Build call for deleteOrderForAccount
      Parameters:
      accountId - Account identifier. (required)
      orderId - Order identifier. (required)
      _callback - Callback for upload/download progress
      Returns:
      Call to execute
      Throws:
      ApiException - If fail to serialize the request body object
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      204 Success (No Content) -
      400 Malformed input. -
      404 Resource does not exist. -
    • deleteOrderForAccount

      public void deleteOrderForAccount(@Nonnull UUID accountId, @Nonnull String orderId) throws ApiException
      Cancel an Open Order Attempts to cancel an open order. If the order is no longer cancelable (for example if the status is \"filled\"), the server will respond with status 422, and reject the request. Upon acceptance of the cancel request, it returns status 204.
      Parameters:
      accountId - Account identifier. (required)
      orderId - Order identifier. (required)
      Throws:
      ApiException - If fail to call the API, e.g. server error or cannot deserialize the response body
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      204 Success (No Content) -
      400 Malformed input. -
      404 Resource does not exist. -
    • deleteOrderForAccountWithHttpInfo

      public ApiResponse<Void> deleteOrderForAccountWithHttpInfo(@Nonnull UUID accountId, @Nonnull String orderId) throws ApiException
      Cancel an Open Order Attempts to cancel an open order. If the order is no longer cancelable (for example if the status is \"filled\"), the server will respond with status 422, and reject the request. Upon acceptance of the cancel request, it returns status 204.
      Parameters:
      accountId - Account identifier. (required)
      orderId - Order identifier. (required)
      Returns:
      ApiResponse<Void>
      Throws:
      ApiException - If fail to call the API, e.g. server error or cannot deserialize the response body
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      204 Success (No Content) -
      400 Malformed input. -
      404 Resource does not exist. -
    • deleteOrderForAccountAsync

      public okhttp3.Call deleteOrderForAccountAsync(@Nonnull UUID accountId, @Nonnull String orderId, ApiCallback<Void> _callback) throws ApiException
      Cancel an Open Order (asynchronously) Attempts to cancel an open order. If the order is no longer cancelable (for example if the status is \"filled\"), the server will respond with status 422, and reject the request. Upon acceptance of the cancel request, it returns status 204.
      Parameters:
      accountId - Account identifier. (required)
      orderId - Order identifier. (required)
      _callback - The callback to be executed when the API call finishes
      Returns:
      The request call
      Throws:
      ApiException - If fail to process the API call, e.g. serializing the request body object
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      204 Success (No Content) -
      400 Malformed input. -
      404 Resource does not exist. -
    • getAllOrdersForAccountCall

      public okhttp3.Call getAllOrdersForAccountCall(@Nonnull UUID accountId, @Nullable String status, @Nullable Integer limit, @Nullable List<String> assetClass, @Nullable OffsetDateTime after, @Nullable OffsetDateTime until, @Nullable String direction, @Nullable Boolean nested, @Nullable String symbols, @Nullable String qtyAbove, @Nullable String qtyBelow, @Nullable String subtag, ApiCallback _callback) throws ApiException
      Build call for getAllOrdersForAccount
      Parameters:
      accountId - Account identifier. (required)
      status - Order status to be queried. open, closed or all. Defaults to open. (optional)
      limit - The maximum number of orders in response. Defaults to 50 and max is 500. (optional)
      assetClass - A comma-separated list of asset classes, the response will include only orders in the specified asset classes. By specifying `us_option` as the class, you can query option orders by underlying symbol using the symbols parameter. (optional)
      after - The response will include only ones submitted after this timestamp (exclusive) (optional)
      until - The response will include only ones submitted until this timestamp (exclusive) (optional)
      direction - The chronological order of response based on the submission time. asc or desc. Defaults to desc. (optional)
      nested - If true, the result will roll up multi-leg orders under the legs field of primary order. (optional)
      symbols - A comma-separated list of symbols to filter by. (optional)
      qtyAbove - (optional)
      qtyBelow - (optional)
      subtag - (optional)
      _callback - Callback for upload/download progress
      Returns:
      Call to execute
      Throws:
      ApiException - If fail to serialize the request body object
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      200 Retrieves a list of orders for the account, filtered by the supplied query parameters. -
      400 Malformed input. -
      404 Resource does not exist. -
    • getAllOrdersForAccount

      public List<Order> getAllOrdersForAccount(@Nonnull UUID accountId, @Nullable String status, @Nullable Integer limit, @Nullable List<String> assetClass, @Nullable OffsetDateTime after, @Nullable OffsetDateTime until, @Nullable String direction, @Nullable Boolean nested, @Nullable String symbols, @Nullable String qtyAbove, @Nullable String qtyBelow, @Nullable String subtag) throws ApiException
      Retrieve a List of Orders Retrieves a list of orders for the account, filtered by the supplied query parameters. Endpoint defaults to open orders if no parameters are provided.
      Parameters:
      accountId - Account identifier. (required)
      status - Order status to be queried. open, closed or all. Defaults to open. (optional)
      limit - The maximum number of orders in response. Defaults to 50 and max is 500. (optional)
      assetClass - A comma-separated list of asset classes, the response will include only orders in the specified asset classes. By specifying `us_option` as the class, you can query option orders by underlying symbol using the symbols parameter. (optional)
      after - The response will include only ones submitted after this timestamp (exclusive) (optional)
      until - The response will include only ones submitted until this timestamp (exclusive) (optional)
      direction - The chronological order of response based on the submission time. asc or desc. Defaults to desc. (optional)
      nested - If true, the result will roll up multi-leg orders under the legs field of primary order. (optional)
      symbols - A comma-separated list of symbols to filter by. (optional)
      qtyAbove - (optional)
      qtyBelow - (optional)
      subtag - (optional)
      Returns:
      List<Order>
      Throws:
      ApiException - If fail to call the API, e.g. server error or cannot deserialize the response body
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      200 Retrieves a list of orders for the account, filtered by the supplied query parameters. -
      400 Malformed input. -
      404 Resource does not exist. -
    • getAllOrdersForAccountWithHttpInfo

      public ApiResponse<List<Order>> getAllOrdersForAccountWithHttpInfo(@Nonnull UUID accountId, @Nullable String status, @Nullable Integer limit, @Nullable List<String> assetClass, @Nullable OffsetDateTime after, @Nullable OffsetDateTime until, @Nullable String direction, @Nullable Boolean nested, @Nullable String symbols, @Nullable String qtyAbove, @Nullable String qtyBelow, @Nullable String subtag) throws ApiException
      Retrieve a List of Orders Retrieves a list of orders for the account, filtered by the supplied query parameters. Endpoint defaults to open orders if no parameters are provided.
      Parameters:
      accountId - Account identifier. (required)
      status - Order status to be queried. open, closed or all. Defaults to open. (optional)
      limit - The maximum number of orders in response. Defaults to 50 and max is 500. (optional)
      assetClass - A comma-separated list of asset classes, the response will include only orders in the specified asset classes. By specifying `us_option` as the class, you can query option orders by underlying symbol using the symbols parameter. (optional)
      after - The response will include only ones submitted after this timestamp (exclusive) (optional)
      until - The response will include only ones submitted until this timestamp (exclusive) (optional)
      direction - The chronological order of response based on the submission time. asc or desc. Defaults to desc. (optional)
      nested - If true, the result will roll up multi-leg orders under the legs field of primary order. (optional)
      symbols - A comma-separated list of symbols to filter by. (optional)
      qtyAbove - (optional)
      qtyBelow - (optional)
      subtag - (optional)
      Returns:
      ApiResponse<List<Order>>
      Throws:
      ApiException - If fail to call the API, e.g. server error or cannot deserialize the response body
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      200 Retrieves a list of orders for the account, filtered by the supplied query parameters. -
      400 Malformed input. -
      404 Resource does not exist. -
    • getAllOrdersForAccountAsync

      public okhttp3.Call getAllOrdersForAccountAsync(@Nonnull UUID accountId, @Nullable String status, @Nullable Integer limit, @Nullable List<String> assetClass, @Nullable OffsetDateTime after, @Nullable OffsetDateTime until, @Nullable String direction, @Nullable Boolean nested, @Nullable String symbols, @Nullable String qtyAbove, @Nullable String qtyBelow, @Nullable String subtag, ApiCallback<List<Order>> _callback) throws ApiException
      Retrieve a List of Orders (asynchronously) Retrieves a list of orders for the account, filtered by the supplied query parameters. Endpoint defaults to open orders if no parameters are provided.
      Parameters:
      accountId - Account identifier. (required)
      status - Order status to be queried. open, closed or all. Defaults to open. (optional)
      limit - The maximum number of orders in response. Defaults to 50 and max is 500. (optional)
      assetClass - A comma-separated list of asset classes, the response will include only orders in the specified asset classes. By specifying `us_option` as the class, you can query option orders by underlying symbol using the symbols parameter. (optional)
      after - The response will include only ones submitted after this timestamp (exclusive) (optional)
      until - The response will include only ones submitted until this timestamp (exclusive) (optional)
      direction - The chronological order of response based on the submission time. asc or desc. Defaults to desc. (optional)
      nested - If true, the result will roll up multi-leg orders under the legs field of primary order. (optional)
      symbols - A comma-separated list of symbols to filter by. (optional)
      qtyAbove - (optional)
      qtyBelow - (optional)
      subtag - (optional)
      _callback - The callback to be executed when the API call finishes
      Returns:
      The request call
      Throws:
      ApiException - If fail to process the API call, e.g. serializing the request body object
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      200 Retrieves a list of orders for the account, filtered by the supplied query parameters. -
      400 Malformed input. -
      404 Resource does not exist. -
    • getOrderByClientOrderIdForAccountCall

      public okhttp3.Call getOrderByClientOrderIdForAccountCall(@Nonnull UUID accountId, @Nonnull String clientOrderId, ApiCallback _callback) throws ApiException
      Build call for getOrderByClientOrderIdForAccount
      Parameters:
      accountId - Account identifier. (required)
      clientOrderId - The client-assigned order ID. (required)
      _callback - Callback for upload/download progress
      Returns:
      Call to execute
      Throws:
      ApiException - If fail to serialize the request body object
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      200 Successfully retrieved the order matching the client_order_id. -
      400 Malformed input. -
      404 Resource does not exist. -
    • getOrderByClientOrderIdForAccount

      public Order getOrderByClientOrderIdForAccount(@Nonnull UUID accountId, @Nonnull String clientOrderId) throws ApiException
      Retrieves a single order specified by the client order ID. Retrieves a single order specified by the client order ID.
      Parameters:
      accountId - Account identifier. (required)
      clientOrderId - The client-assigned order ID. (required)
      Returns:
      Order
      Throws:
      ApiException - If fail to call the API, e.g. server error or cannot deserialize the response body
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      200 Successfully retrieved the order matching the client_order_id. -
      400 Malformed input. -
      404 Resource does not exist. -
    • getOrderByClientOrderIdForAccountWithHttpInfo

      public ApiResponse<Order> getOrderByClientOrderIdForAccountWithHttpInfo(@Nonnull UUID accountId, @Nonnull String clientOrderId) throws ApiException
      Retrieves a single order specified by the client order ID. Retrieves a single order specified by the client order ID.
      Parameters:
      accountId - Account identifier. (required)
      clientOrderId - The client-assigned order ID. (required)
      Returns:
      ApiResponse<Order>
      Throws:
      ApiException - If fail to call the API, e.g. server error or cannot deserialize the response body
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      200 Successfully retrieved the order matching the client_order_id. -
      400 Malformed input. -
      404 Resource does not exist. -
    • getOrderByClientOrderIdForAccountAsync

      public okhttp3.Call getOrderByClientOrderIdForAccountAsync(@Nonnull UUID accountId, @Nonnull String clientOrderId, ApiCallback<Order> _callback) throws ApiException
      Retrieves a single order specified by the client order ID. (asynchronously) Retrieves a single order specified by the client order ID.
      Parameters:
      accountId - Account identifier. (required)
      clientOrderId - The client-assigned order ID. (required)
      _callback - The callback to be executed when the API call finishes
      Returns:
      The request call
      Throws:
      ApiException - If fail to process the API call, e.g. serializing the request body object
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      200 Successfully retrieved the order matching the client_order_id. -
      400 Malformed input. -
      404 Resource does not exist. -
    • getOrderForAccountCall

      public okhttp3.Call getOrderForAccountCall(@Nonnull UUID accountId, @Nonnull String orderId, ApiCallback _callback) throws ApiException
      Build call for getOrderForAccount
      Parameters:
      accountId - Account identifier. (required)
      orderId - Order identifier. (required)
      _callback - Callback for upload/download progress
      Returns:
      Call to execute
      Throws:
      ApiException - If fail to serialize the request body object
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      200 The requested Order object -
      400 Malformed input. -
      404 Resource does not exist. -
    • getOrderForAccount

      public Order getOrderForAccount(@Nonnull UUID accountId, @Nonnull String orderId) throws ApiException
      Retrieve an Order by its ID Retrieves a single order for the given order_id.
      Parameters:
      accountId - Account identifier. (required)
      orderId - Order identifier. (required)
      Returns:
      Order
      Throws:
      ApiException - If fail to call the API, e.g. server error or cannot deserialize the response body
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      200 The requested Order object -
      400 Malformed input. -
      404 Resource does not exist. -
    • getOrderForAccountWithHttpInfo

      public ApiResponse<Order> getOrderForAccountWithHttpInfo(@Nonnull UUID accountId, @Nonnull String orderId) throws ApiException
      Retrieve an Order by its ID Retrieves a single order for the given order_id.
      Parameters:
      accountId - Account identifier. (required)
      orderId - Order identifier. (required)
      Returns:
      ApiResponse<Order>
      Throws:
      ApiException - If fail to call the API, e.g. server error or cannot deserialize the response body
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      200 The requested Order object -
      400 Malformed input. -
      404 Resource does not exist. -
    • getOrderForAccountAsync

      public okhttp3.Call getOrderForAccountAsync(@Nonnull UUID accountId, @Nonnull String orderId, ApiCallback<Order> _callback) throws ApiException
      Retrieve an Order by its ID (asynchronously) Retrieves a single order for the given order_id.
      Parameters:
      accountId - Account identifier. (required)
      orderId - Order identifier. (required)
      _callback - The callback to be executed when the API call finishes
      Returns:
      The request call
      Throws:
      ApiException - If fail to process the API call, e.g. serializing the request body object
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      200 The requested Order object -
      400 Malformed input. -
      404 Resource does not exist. -
    • getPositionsForAccountCall

      public okhttp3.Call getPositionsForAccountCall(@Nonnull UUID accountId, ApiCallback _callback) throws ApiException
      Build call for getPositionsForAccount
      Parameters:
      accountId - Account identifier. (required)
      _callback - Callback for upload/download progress
      Returns:
      Call to execute
      Throws:
      ApiException - If fail to serialize the request body object
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      200 Success -
    • getPositionsForAccount

      public List<Position> getPositionsForAccount(@Nonnull UUID accountId) throws ApiException
      List Open Positions for an Account List open positions for an account
      Parameters:
      accountId - Account identifier. (required)
      Returns:
      List<Position>
      Throws:
      ApiException - If fail to call the API, e.g. server error or cannot deserialize the response body
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      200 Success -
    • getPositionsForAccountWithHttpInfo

      public ApiResponse<List<Position>> getPositionsForAccountWithHttpInfo(@Nonnull UUID accountId) throws ApiException
      List Open Positions for an Account List open positions for an account
      Parameters:
      accountId - Account identifier. (required)
      Returns:
      ApiResponse<List<Position>>
      Throws:
      ApiException - If fail to call the API, e.g. server error or cannot deserialize the response body
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      200 Success -
    • getPositionsForAccountAsync

      public okhttp3.Call getPositionsForAccountAsync(@Nonnull UUID accountId, ApiCallback<List<Position>> _callback) throws ApiException
      List Open Positions for an Account (asynchronously) List open positions for an account
      Parameters:
      accountId - Account identifier. (required)
      _callback - The callback to be executed when the API call finishes
      Returns:
      The request call
      Throws:
      ApiException - If fail to process the API call, e.g. serializing the request body object
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      200 Success -
    • getPositionsForAccountBySymbolCall

      public okhttp3.Call getPositionsForAccountBySymbolCall(@Nonnull UUID accountId, @Nonnull String symbolOrAssetId, ApiCallback _callback) throws ApiException
      Build call for getPositionsForAccountBySymbol
      Parameters:
      accountId - Account identifier. (required)
      symbolOrAssetId - The symbol or asset_id (required)
      _callback - Callback for upload/download progress
      Returns:
      Call to execute
      Throws:
      ApiException - If fail to serialize the request body object
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      200 The requested Position object -
      404 Account doesn't have a position for this symbol or asset_id -
    • getPositionsForAccountBySymbol

      public Position getPositionsForAccountBySymbol(@Nonnull UUID accountId, @Nonnull String symbolOrAssetId) throws ApiException
      Get an Open Position for account by Symbol or AssetId Retrieves the account's open position for the given symbol or asset_id.
      Parameters:
      accountId - Account identifier. (required)
      symbolOrAssetId - The symbol or asset_id (required)
      Returns:
      Position
      Throws:
      ApiException - If fail to call the API, e.g. server error or cannot deserialize the response body
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      200 The requested Position object -
      404 Account doesn't have a position for this symbol or asset_id -
    • getPositionsForAccountBySymbolWithHttpInfo

      public ApiResponse<Position> getPositionsForAccountBySymbolWithHttpInfo(@Nonnull UUID accountId, @Nonnull String symbolOrAssetId) throws ApiException
      Get an Open Position for account by Symbol or AssetId Retrieves the account's open position for the given symbol or asset_id.
      Parameters:
      accountId - Account identifier. (required)
      symbolOrAssetId - The symbol or asset_id (required)
      Returns:
      ApiResponse<Position>
      Throws:
      ApiException - If fail to call the API, e.g. server error or cannot deserialize the response body
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      200 The requested Position object -
      404 Account doesn't have a position for this symbol or asset_id -
    • getPositionsForAccountBySymbolAsync

      public okhttp3.Call getPositionsForAccountBySymbolAsync(@Nonnull UUID accountId, @Nonnull String symbolOrAssetId, ApiCallback<Position> _callback) throws ApiException
      Get an Open Position for account by Symbol or AssetId (asynchronously) Retrieves the account's open position for the given symbol or asset_id.
      Parameters:
      accountId - Account identifier. (required)
      symbolOrAssetId - The symbol or asset_id (required)
      _callback - The callback to be executed when the API call finishes
      Returns:
      The request call
      Throws:
      ApiException - If fail to process the API call, e.g. serializing the request body object
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      200 The requested Position object -
      404 Account doesn't have a position for this symbol or asset_id -
    • getV1AccountTradingLimitsCall

      public okhttp3.Call getV1AccountTradingLimitsCall(@Nonnull String accountId, ApiCallback _callback) throws ApiException
      Build call for getV1AccountTradingLimits
      Parameters:
      accountId - (required)
      _callback - Callback for upload/download progress
      Returns:
      Call to execute
      Throws:
      ApiException - If fail to serialize the request body object
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      200 Returns the trading limit set for the account and the real-time usage of the limit -
      404 Returned when the account is not configured for trading limits -
    • getV1AccountTradingLimits

      public AccountTradingLimit getV1AccountTradingLimits(@Nonnull String accountId) throws ApiException
      Retrieve real-time Trading Limits for an Account This endpoint is only available to accounts with the trading limits feature enabled, and not on JIT. The daily trading limit is set at the correspondent level (or the account level) and is used as the limit for the total amount due to Alpaca on the date of settlement. The limit in use returns the real time usage of this limit, based on the setup it uses the usage is calculated differently. If the limit in use reaches the `daily_net_limit` or `available` is zero, further purchasing activity will be halted, however, the limit can be adjusted by reaching out to Alpaca with the proposed new limit and the reason for the change.
      Parameters:
      accountId - (required)
      Returns:
      AccountTradingLimit
      Throws:
      ApiException - If fail to call the API, e.g. server error or cannot deserialize the response body
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      200 Returns the trading limit set for the account and the real-time usage of the limit -
      404 Returned when the account is not configured for trading limits -
    • getV1AccountTradingLimitsWithHttpInfo

      public ApiResponse<AccountTradingLimit> getV1AccountTradingLimitsWithHttpInfo(@Nonnull String accountId) throws ApiException
      Retrieve real-time Trading Limits for an Account This endpoint is only available to accounts with the trading limits feature enabled, and not on JIT. The daily trading limit is set at the correspondent level (or the account level) and is used as the limit for the total amount due to Alpaca on the date of settlement. The limit in use returns the real time usage of this limit, based on the setup it uses the usage is calculated differently. If the limit in use reaches the `daily_net_limit` or `available` is zero, further purchasing activity will be halted, however, the limit can be adjusted by reaching out to Alpaca with the proposed new limit and the reason for the change.
      Parameters:
      accountId - (required)
      Returns:
      ApiResponse<AccountTradingLimit>
      Throws:
      ApiException - If fail to call the API, e.g. server error or cannot deserialize the response body
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      200 Returns the trading limit set for the account and the real-time usage of the limit -
      404 Returned when the account is not configured for trading limits -
    • getV1AccountTradingLimitsAsync

      public okhttp3.Call getV1AccountTradingLimitsAsync(@Nonnull String accountId, ApiCallback<AccountTradingLimit> _callback) throws ApiException
      Retrieve real-time Trading Limits for an Account (asynchronously) This endpoint is only available to accounts with the trading limits feature enabled, and not on JIT. The daily trading limit is set at the correspondent level (or the account level) and is used as the limit for the total amount due to Alpaca on the date of settlement. The limit in use returns the real time usage of this limit, based on the setup it uses the usage is calculated differently. If the limit in use reaches the `daily_net_limit` or `available` is zero, further purchasing activity will be halted, however, the limit can be adjusted by reaching out to Alpaca with the proposed new limit and the reason for the change.
      Parameters:
      accountId - (required)
      _callback - The callback to be executed when the API call finishes
      Returns:
      The request call
      Throws:
      ApiException - If fail to process the API call, e.g. serializing the request body object
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      200 Returns the trading limit set for the account and the real-time usage of the limit -
      404 Returned when the account is not configured for trading limits -
    • getV1AccountsPositionsCall

      @Deprecated public okhttp3.Call getV1AccountsPositionsCall(@Nullable Integer page, ApiCallback _callback) throws ApiException
      Deprecated.
      Build call for getV1AccountsPositions
      Parameters:
      page - The number of the page of the results to be fetched. (optional)
      _callback - Callback for upload/download progress
      Returns:
      Call to execute
      Throws:
      ApiException - If fail to serialize the request body object
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      200 The response contains two fields: asof: the timestamp for which the positions are returned. It is always the last market close positions: an account-id to position list map, contains the requested page's accounts The positions map is empty for the last page. Note: when fetching bulk positions, which can take multiple minutes depending on the number of accounts managed have, a market close can happen, and after that a new set of results might be returned. To make sure results are consistent, please always check that the as_of field didn't change during the whole fetching process. -
    • getV1AccountsPositions

      @Deprecated public GetV1AccountsPositions200Response getV1AccountsPositions(@Nullable Integer page) throws ApiException
      Deprecated.
      Bulk Fetch All Accounts Positions Retrieves a list of the account's open positions. This endpoint is deprecated and will be removed in the future. Please use the [GET /v1/reporting/eod/positions endpoint](https://docs.alpaca.markets/reference/get-v1-reporting-eod-positions) instead.
      Parameters:
      page - The number of the page of the results to be fetched. (optional)
      Returns:
      GetV1AccountsPositions200Response
      Throws:
      ApiException - If fail to call the API, e.g. server error or cannot deserialize the response body
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      200 The response contains two fields: asof: the timestamp for which the positions are returned. It is always the last market close positions: an account-id to position list map, contains the requested page's accounts The positions map is empty for the last page. Note: when fetching bulk positions, which can take multiple minutes depending on the number of accounts managed have, a market close can happen, and after that a new set of results might be returned. To make sure results are consistent, please always check that the as_of field didn't change during the whole fetching process. -
    • getV1AccountsPositionsWithHttpInfo

      @Deprecated public ApiResponse<GetV1AccountsPositions200Response> getV1AccountsPositionsWithHttpInfo(@Nullable Integer page) throws ApiException
      Deprecated.
      Bulk Fetch All Accounts Positions Retrieves a list of the account's open positions. This endpoint is deprecated and will be removed in the future. Please use the [GET /v1/reporting/eod/positions endpoint](https://docs.alpaca.markets/reference/get-v1-reporting-eod-positions) instead.
      Parameters:
      page - The number of the page of the results to be fetched. (optional)
      Returns:
      ApiResponse<GetV1AccountsPositions200Response>
      Throws:
      ApiException - If fail to call the API, e.g. server error or cannot deserialize the response body
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      200 The response contains two fields: asof: the timestamp for which the positions are returned. It is always the last market close positions: an account-id to position list map, contains the requested page's accounts The positions map is empty for the last page. Note: when fetching bulk positions, which can take multiple minutes depending on the number of accounts managed have, a market close can happen, and after that a new set of results might be returned. To make sure results are consistent, please always check that the as_of field didn't change during the whole fetching process. -
    • getV1AccountsPositionsAsync

      @Deprecated public okhttp3.Call getV1AccountsPositionsAsync(@Nullable Integer page, ApiCallback<GetV1AccountsPositions200Response> _callback) throws ApiException
      Deprecated.
      Bulk Fetch All Accounts Positions (asynchronously) Retrieves a list of the account's open positions. This endpoint is deprecated and will be removed in the future. Please use the [GET /v1/reporting/eod/positions endpoint](https://docs.alpaca.markets/reference/get-v1-reporting-eod-positions) instead.
      Parameters:
      page - The number of the page of the results to be fetched. (optional)
      _callback - The callback to be executed when the API call finishes
      Returns:
      The request call
      Throws:
      ApiException - If fail to process the API call, e.g. serializing the request body object
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      200 The response contains two fields: asof: the timestamp for which the positions are returned. It is always the last market close positions: an account-id to position list map, contains the requested page's accounts The positions map is empty for the last page. Note: when fetching bulk positions, which can take multiple minutes depending on the number of accounts managed have, a market close can happen, and after that a new set of results might be returned. To make sure results are consistent, please always check that the as_of field didn't change during the whole fetching process. -
    • getV1TradingAccountsAccountIdOrdersEstimationCall

      public okhttp3.Call getV1TradingAccountsAccountIdOrdersEstimationCall(@Nonnull String accountId, @Nullable GetV1TradingAccountsAccountIdOrdersEstimationRequest getV1TradingAccountsAccountIdOrdersEstimationRequest, ApiCallback _callback) throws ApiException
      Build call for getV1TradingAccountsAccountIdOrdersEstimation
      Parameters:
      accountId - (required)
      getV1TradingAccountsAccountIdOrdersEstimationRequest - (optional)
      _callback - Callback for upload/download progress
      Returns:
      Call to execute
      Throws:
      ApiException - If fail to serialize the request body object
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      200 OK -
    • getV1TradingAccountsAccountIdOrdersEstimation

      public Order getV1TradingAccountsAccountIdOrdersEstimation(@Nonnull String accountId, @Nullable GetV1TradingAccountsAccountIdOrdersEstimationRequest getV1TradingAccountsAccountIdOrdersEstimationRequest) throws ApiException
      Estimate an Order Order estimation endpoint will display, based on user's account balance, the estimated quantity and price they will receive for their notional order. For LCT - customer's order will include the Alpaca swap_fee, while correspondent side swap_fee is configurable in the API call. Utilising this API does not result in a real order and after the calculation - the user's buying power reverts to the previous state. Responses and Errors are the same as with the Orders API Please note that the estimation is based on the market condition at the time of submission and a live order will differ. The output should be considered indicative. **Note:** This does not support Crypto or non-market orders at this time.
      Parameters:
      accountId - (required)
      getV1TradingAccountsAccountIdOrdersEstimationRequest - (optional)
      Returns:
      Order
      Throws:
      ApiException - If fail to call the API, e.g. server error or cannot deserialize the response body
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      200 OK -
    • getV1TradingAccountsAccountIdOrdersEstimationWithHttpInfo

      public ApiResponse<Order> getV1TradingAccountsAccountIdOrdersEstimationWithHttpInfo(@Nonnull String accountId, @Nullable GetV1TradingAccountsAccountIdOrdersEstimationRequest getV1TradingAccountsAccountIdOrdersEstimationRequest) throws ApiException
      Estimate an Order Order estimation endpoint will display, based on user's account balance, the estimated quantity and price they will receive for their notional order. For LCT - customer's order will include the Alpaca swap_fee, while correspondent side swap_fee is configurable in the API call. Utilising this API does not result in a real order and after the calculation - the user's buying power reverts to the previous state. Responses and Errors are the same as with the Orders API Please note that the estimation is based on the market condition at the time of submission and a live order will differ. The output should be considered indicative. **Note:** This does not support Crypto or non-market orders at this time.
      Parameters:
      accountId - (required)
      getV1TradingAccountsAccountIdOrdersEstimationRequest - (optional)
      Returns:
      ApiResponse<Order>
      Throws:
      ApiException - If fail to call the API, e.g. server error or cannot deserialize the response body
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      200 OK -
    • getV1TradingAccountsAccountIdOrdersEstimationAsync

      public okhttp3.Call getV1TradingAccountsAccountIdOrdersEstimationAsync(@Nonnull String accountId, @Nullable GetV1TradingAccountsAccountIdOrdersEstimationRequest getV1TradingAccountsAccountIdOrdersEstimationRequest, ApiCallback<Order> _callback) throws ApiException
      Estimate an Order (asynchronously) Order estimation endpoint will display, based on user's account balance, the estimated quantity and price they will receive for their notional order. For LCT - customer's order will include the Alpaca swap_fee, while correspondent side swap_fee is configurable in the API call. Utilising this API does not result in a real order and after the calculation - the user's buying power reverts to the previous state. Responses and Errors are the same as with the Orders API Please note that the estimation is based on the market condition at the time of submission and a live order will differ. The output should be considered indicative. **Note:** This does not support Crypto or non-market orders at this time.
      Parameters:
      accountId - (required)
      getV1TradingAccountsAccountIdOrdersEstimationRequest - (optional)
      _callback - The callback to be executed when the API call finishes
      Returns:
      The request call
      Throws:
      ApiException - If fail to process the API call, e.g. serializing the request body object
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      200 OK -
    • optionDoNotExerciseCall

      public okhttp3.Call optionDoNotExerciseCall(@Nonnull UUID accountId, @Nonnull UUID symbolOrContractId, @Nullable Object body, ApiCallback _callback) throws ApiException
      Build call for optionDoNotExercise
      Parameters:
      accountId - Account identifier. (required)
      symbolOrContractId - Option contract symbol or ID. (required)
      body - (optional)
      _callback - Callback for upload/download progress
      Returns:
      Call to execute
      Throws:
      ApiException - If fail to serialize the request body object
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      200 Successful Response -
      403 Forbidden -
      422 Invalid Symbol The specified symbol_or_contract_id is invalid. -
    • optionDoNotExercise

      public Object optionDoNotExercise(@Nonnull UUID accountId, @Nonnull UUID symbolOrContractId, @Nullable Object body) throws ApiException
      Do Not Exercise an Options Position This endpoint enables users to submit a do-not-exercise (DNE) instruction for a held option contract, preventing automatic exercise at expiry. By default, Alpaca will automatically exercise in-the-money (ITM) contracts at expiry. This endpoint allows users to override that behavior. DNE requests will be processed immediately once received. DNE requests submitted between market close and midnight will be rejected to avoid any confusion about when the instruction will take effect. To cancel a DNE request or to submit an exercise instruction, please contact our support team.
      Parameters:
      accountId - Account identifier. (required)
      symbolOrContractId - Option contract symbol or ID. (required)
      body - (optional)
      Returns:
      Object
      Throws:
      ApiException - If fail to call the API, e.g. server error or cannot deserialize the response body
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      200 Successful Response -
      403 Forbidden -
      422 Invalid Symbol The specified symbol_or_contract_id is invalid. -
    • optionDoNotExerciseWithHttpInfo

      public ApiResponse<Object> optionDoNotExerciseWithHttpInfo(@Nonnull UUID accountId, @Nonnull UUID symbolOrContractId, @Nullable Object body) throws ApiException
      Do Not Exercise an Options Position This endpoint enables users to submit a do-not-exercise (DNE) instruction for a held option contract, preventing automatic exercise at expiry. By default, Alpaca will automatically exercise in-the-money (ITM) contracts at expiry. This endpoint allows users to override that behavior. DNE requests will be processed immediately once received. DNE requests submitted between market close and midnight will be rejected to avoid any confusion about when the instruction will take effect. To cancel a DNE request or to submit an exercise instruction, please contact our support team.
      Parameters:
      accountId - Account identifier. (required)
      symbolOrContractId - Option contract symbol or ID. (required)
      body - (optional)
      Returns:
      ApiResponse<Object>
      Throws:
      ApiException - If fail to call the API, e.g. server error or cannot deserialize the response body
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      200 Successful Response -
      403 Forbidden -
      422 Invalid Symbol The specified symbol_or_contract_id is invalid. -
    • optionDoNotExerciseAsync

      public okhttp3.Call optionDoNotExerciseAsync(@Nonnull UUID accountId, @Nonnull UUID symbolOrContractId, @Nullable Object body, ApiCallback<Object> _callback) throws ApiException
      Do Not Exercise an Options Position (asynchronously) This endpoint enables users to submit a do-not-exercise (DNE) instruction for a held option contract, preventing automatic exercise at expiry. By default, Alpaca will automatically exercise in-the-money (ITM) contracts at expiry. This endpoint allows users to override that behavior. DNE requests will be processed immediately once received. DNE requests submitted between market close and midnight will be rejected to avoid any confusion about when the instruction will take effect. To cancel a DNE request or to submit an exercise instruction, please contact our support team.
      Parameters:
      accountId - Account identifier. (required)
      symbolOrContractId - Option contract symbol or ID. (required)
      body - (optional)
      _callback - The callback to be executed when the API call finishes
      Returns:
      The request call
      Throws:
      ApiException - If fail to process the API call, e.g. serializing the request body object
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      200 Successful Response -
      403 Forbidden -
      422 Invalid Symbol The specified symbol_or_contract_id is invalid. -
    • optionExerciseCall

      public okhttp3.Call optionExerciseCall(@Nonnull UUID accountId, @Nonnull UUID symbolOrContractId, @Nullable ExerciseRequest exerciseRequest, ApiCallback _callback) throws ApiException
      Build call for optionExercise
      Parameters:
      accountId - Account identifier. (required)
      symbolOrContractId - Option contract symbol or ID. (required)
      exerciseRequest - (optional)
      _callback - Callback for upload/download progress
      Returns:
      Call to execute
      Throws:
      ApiException - If fail to serialize the request body object
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      200 Successful Response -
      403 Forbidden Available position quantity is not sufficient. -
    • optionExercise

      public ExerciseResponse optionExercise(@Nonnull UUID accountId, @Nonnull UUID symbolOrContractId, @Nullable ExerciseRequest exerciseRequest) throws ApiException
      Exercise an Options Position This endpoint enables users to exercise a held option contract, converting it into the underlying asset based on the specified terms. All available held shares of this option contract will be exercised. By default, Alpaca will automatically exercise in-the-money (ITM) contracts at expiry. Exercise requests will be processed immediately once received. Exercise requests submitted between market close and midnight will be rejected to avoid any confusion about when the exercise will settle. To cancel an exercise request or to submit a Do-not-exercise (DNE) instruction, you can use the do-not-exercise endpoint or contact our support team.
      Parameters:
      accountId - Account identifier. (required)
      symbolOrContractId - Option contract symbol or ID. (required)
      exerciseRequest - (optional)
      Returns:
      ExerciseResponse
      Throws:
      ApiException - If fail to call the API, e.g. server error or cannot deserialize the response body
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      200 Successful Response -
      403 Forbidden Available position quantity is not sufficient. -
    • optionExerciseWithHttpInfo

      public ApiResponse<ExerciseResponse> optionExerciseWithHttpInfo(@Nonnull UUID accountId, @Nonnull UUID symbolOrContractId, @Nullable ExerciseRequest exerciseRequest) throws ApiException
      Exercise an Options Position This endpoint enables users to exercise a held option contract, converting it into the underlying asset based on the specified terms. All available held shares of this option contract will be exercised. By default, Alpaca will automatically exercise in-the-money (ITM) contracts at expiry. Exercise requests will be processed immediately once received. Exercise requests submitted between market close and midnight will be rejected to avoid any confusion about when the exercise will settle. To cancel an exercise request or to submit a Do-not-exercise (DNE) instruction, you can use the do-not-exercise endpoint or contact our support team.
      Parameters:
      accountId - Account identifier. (required)
      symbolOrContractId - Option contract symbol or ID. (required)
      exerciseRequest - (optional)
      Returns:
      ApiResponse<ExerciseResponse>
      Throws:
      ApiException - If fail to call the API, e.g. server error or cannot deserialize the response body
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      200 Successful Response -
      403 Forbidden Available position quantity is not sufficient. -
    • optionExerciseAsync

      public okhttp3.Call optionExerciseAsync(@Nonnull UUID accountId, @Nonnull UUID symbolOrContractId, @Nullable ExerciseRequest exerciseRequest, ApiCallback<ExerciseResponse> _callback) throws ApiException
      Exercise an Options Position (asynchronously) This endpoint enables users to exercise a held option contract, converting it into the underlying asset based on the specified terms. All available held shares of this option contract will be exercised. By default, Alpaca will automatically exercise in-the-money (ITM) contracts at expiry. Exercise requests will be processed immediately once received. Exercise requests submitted between market close and midnight will be rejected to avoid any confusion about when the exercise will settle. To cancel an exercise request or to submit a Do-not-exercise (DNE) instruction, you can use the do-not-exercise endpoint or contact our support team.
      Parameters:
      accountId - Account identifier. (required)
      symbolOrContractId - Option contract symbol or ID. (required)
      exerciseRequest - (optional)
      _callback - The callback to be executed when the API call finishes
      Returns:
      The request call
      Throws:
      ApiException - If fail to process the API call, e.g. serializing the request body object
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      200 Successful Response -
      403 Forbidden Available position quantity is not sufficient. -
    • patchPATCHV1TradingAccountsAccountIdAccountConfigurationsCall

      public okhttp3.Call patchPATCHV1TradingAccountsAccountIdAccountConfigurationsCall(@Nonnull String accountId, @Nullable AccountConfigurations accountConfigurations, ApiCallback _callback) throws ApiException
      Build call for patchPATCHV1TradingAccountsAccountIdAccountConfigurations
      Parameters:
      accountId - (required)
      accountConfigurations - (optional)
      _callback - Callback for upload/download progress
      Returns:
      Call to execute
      Throws:
      ApiException - If fail to serialize the request body object
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      200 Response will contain the account configuration settings for the account. -
    • patchPATCHV1TradingAccountsAccountIdAccountConfigurations

      public AccountConfigurations patchPATCHV1TradingAccountsAccountIdAccountConfigurations(@Nonnull String accountId, @Nullable AccountConfigurations accountConfigurations) throws ApiException
      Update Trading Configurations for an Account You can also set the margin settings for your users' account by passing a PATCH request. By default any account with funds under $2,000 is set a margin multiplier of 1.0, and accounts with over $2,000 are set to 2.0.
      Parameters:
      accountId - (required)
      accountConfigurations - (optional)
      Returns:
      AccountConfigurations
      Throws:
      ApiException - If fail to call the API, e.g. server error or cannot deserialize the response body
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      200 Response will contain the account configuration settings for the account. -
    • patchPATCHV1TradingAccountsAccountIdAccountConfigurationsWithHttpInfo

      public ApiResponse<AccountConfigurations> patchPATCHV1TradingAccountsAccountIdAccountConfigurationsWithHttpInfo(@Nonnull String accountId, @Nullable AccountConfigurations accountConfigurations) throws ApiException
      Update Trading Configurations for an Account You can also set the margin settings for your users' account by passing a PATCH request. By default any account with funds under $2,000 is set a margin multiplier of 1.0, and accounts with over $2,000 are set to 2.0.
      Parameters:
      accountId - (required)
      accountConfigurations - (optional)
      Returns:
      ApiResponse<AccountConfigurations>
      Throws:
      ApiException - If fail to call the API, e.g. server error or cannot deserialize the response body
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      200 Response will contain the account configuration settings for the account. -
    • patchPATCHV1TradingAccountsAccountIdAccountConfigurationsAsync

      public okhttp3.Call patchPATCHV1TradingAccountsAccountIdAccountConfigurationsAsync(@Nonnull String accountId, @Nullable AccountConfigurations accountConfigurations, ApiCallback<AccountConfigurations> _callback) throws ApiException
      Update Trading Configurations for an Account (asynchronously) You can also set the margin settings for your users' account by passing a PATCH request. By default any account with funds under $2,000 is set a margin multiplier of 1.0, and accounts with over $2,000 are set to 2.0.
      Parameters:
      accountId - (required)
      accountConfigurations - (optional)
      _callback - The callback to be executed when the API call finishes
      Returns:
      The request call
      Throws:
      ApiException - If fail to process the API call, e.g. serializing the request body object
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      200 Response will contain the account configuration settings for the account. -
    • replaceOrderForAccountCall

      public okhttp3.Call replaceOrderForAccountCall(@Nonnull UUID accountId, @Nonnull String orderId, @Nonnull UpdateOrderRequest updateOrderRequest, ApiCallback _callback) throws ApiException
      Build call for replaceOrderForAccount
      Parameters:
      accountId - Account identifier. (required)
      orderId - Order identifier. (required)
      updateOrderRequest - (required)
      _callback - Callback for upload/download progress
      Returns:
      Call to execute
      Throws:
      ApiException - If fail to serialize the request body object
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      200 A new Order object with a new order_id -
      400 Malformed input. -
      403 Buying power or shares are not sufficient -
      404 Resource does not exist. -
    • replaceOrderForAccount

      public Order replaceOrderForAccount(@Nonnull UUID accountId, @Nonnull String orderId, @Nonnull UpdateOrderRequest updateOrderRequest) throws ApiException
      Replace an Order Replaces a single order with updated parameters. Each parameter overrides the corresponding attribute of the existing order. The other attributes remain the same as the existing order. A success return code from a replaced order does NOT guarantee the existing open order has been replaced. If the existing open order is filled before the replacing (new) order reaches the execution venue, the replacing (new) order is rejected, and these events are sent in the trade_updates stream channel found [here](https://docs.alpaca.markets/reference/subscribetotradev2sse). While an order is being replaced, the account's buying power is reduced by the larger of the two orders that have been placed (the old order being replaced, and the newly placed order to replace it). If you are replacing a buy entry order with a higher limit price than the original order, the buying power is calculated based on the newly placed order. If you are replacing it with a lower limit price, the buying power is calculated based on the old order. Note: Order cannot be replaced when the status is `accepted`, `pending_new`, `pending_cancel` or `pending_replace`. Note: Notional orders for non-IPO asset classes cannot be replaced. Any attempt to modify a non-IPO notional order via this endpoint will be rejected; cancel it and submit a new one instead. Note: IPO indications of interest (`asset_class: \"ipo\"`) **are** notional and **can** be replaced via this endpoint by providing a new `notional` value. `qty` and `notional` are mutually exclusive on a single replace request. Note that submitting DMA orders (using `advanced_instructions` with `algorithm: DMA`) is only available for partners/correspondents who have been enabled for DMA.
      Parameters:
      accountId - Account identifier. (required)
      orderId - Order identifier. (required)
      updateOrderRequest - (required)
      Returns:
      Order
      Throws:
      ApiException - If fail to call the API, e.g. server error or cannot deserialize the response body
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      200 A new Order object with a new order_id -
      400 Malformed input. -
      403 Buying power or shares are not sufficient -
      404 Resource does not exist. -
    • replaceOrderForAccountWithHttpInfo

      public ApiResponse<Order> replaceOrderForAccountWithHttpInfo(@Nonnull UUID accountId, @Nonnull String orderId, @Nonnull UpdateOrderRequest updateOrderRequest) throws ApiException
      Replace an Order Replaces a single order with updated parameters. Each parameter overrides the corresponding attribute of the existing order. The other attributes remain the same as the existing order. A success return code from a replaced order does NOT guarantee the existing open order has been replaced. If the existing open order is filled before the replacing (new) order reaches the execution venue, the replacing (new) order is rejected, and these events are sent in the trade_updates stream channel found [here](https://docs.alpaca.markets/reference/subscribetotradev2sse). While an order is being replaced, the account's buying power is reduced by the larger of the two orders that have been placed (the old order being replaced, and the newly placed order to replace it). If you are replacing a buy entry order with a higher limit price than the original order, the buying power is calculated based on the newly placed order. If you are replacing it with a lower limit price, the buying power is calculated based on the old order. Note: Order cannot be replaced when the status is `accepted`, `pending_new`, `pending_cancel` or `pending_replace`. Note: Notional orders for non-IPO asset classes cannot be replaced. Any attempt to modify a non-IPO notional order via this endpoint will be rejected; cancel it and submit a new one instead. Note: IPO indications of interest (`asset_class: \"ipo\"`) **are** notional and **can** be replaced via this endpoint by providing a new `notional` value. `qty` and `notional` are mutually exclusive on a single replace request. Note that submitting DMA orders (using `advanced_instructions` with `algorithm: DMA`) is only available for partners/correspondents who have been enabled for DMA.
      Parameters:
      accountId - Account identifier. (required)
      orderId - Order identifier. (required)
      updateOrderRequest - (required)
      Returns:
      ApiResponse<Order>
      Throws:
      ApiException - If fail to call the API, e.g. server error or cannot deserialize the response body
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      200 A new Order object with a new order_id -
      400 Malformed input. -
      403 Buying power or shares are not sufficient -
      404 Resource does not exist. -
    • replaceOrderForAccountAsync

      public okhttp3.Call replaceOrderForAccountAsync(@Nonnull UUID accountId, @Nonnull String orderId, @Nonnull UpdateOrderRequest updateOrderRequest, ApiCallback<Order> _callback) throws ApiException
      Replace an Order (asynchronously) Replaces a single order with updated parameters. Each parameter overrides the corresponding attribute of the existing order. The other attributes remain the same as the existing order. A success return code from a replaced order does NOT guarantee the existing open order has been replaced. If the existing open order is filled before the replacing (new) order reaches the execution venue, the replacing (new) order is rejected, and these events are sent in the trade_updates stream channel found [here](https://docs.alpaca.markets/reference/subscribetotradev2sse). While an order is being replaced, the account's buying power is reduced by the larger of the two orders that have been placed (the old order being replaced, and the newly placed order to replace it). If you are replacing a buy entry order with a higher limit price than the original order, the buying power is calculated based on the newly placed order. If you are replacing it with a lower limit price, the buying power is calculated based on the old order. Note: Order cannot be replaced when the status is `accepted`, `pending_new`, `pending_cancel` or `pending_replace`. Note: Notional orders for non-IPO asset classes cannot be replaced. Any attempt to modify a non-IPO notional order via this endpoint will be rejected; cancel it and submit a new one instead. Note: IPO indications of interest (`asset_class: \"ipo\"`) **are** notional and **can** be replaced via this endpoint by providing a new `notional` value. `qty` and `notional` are mutually exclusive on a single replace request. Note that submitting DMA orders (using `advanced_instructions` with `algorithm: DMA`) is only available for partners/correspondents who have been enabled for DMA.
      Parameters:
      accountId - Account identifier. (required)
      orderId - Order identifier. (required)
      updateOrderRequest - (required)
      _callback - The callback to be executed when the API call finishes
      Returns:
      The request call
      Throws:
      ApiException - If fail to process the API call, e.g. serializing the request body object
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      200 A new Order object with a new order_id -
      400 Malformed input. -
      403 Buying power or shares are not sufficient -
      404 Resource does not exist. -
    • subscribeToTradeV2SSECall

      public okhttp3.Call subscribeToTradeV2SSECall(@Nullable LocalDate since, @Nullable LocalDate until, @Nullable String sinceId, @Nullable String untilId, ApiCallback _callback) throws ApiException
      Build call for subscribeToTradeV2SSE
      Parameters:
      since - Format: YYYY-MM-DD (optional)
      until - Format: YYYY-MM-DD (optional)
      sinceId - (optional)
      untilId - (optional)
      _callback - Callback for upload/download progress
      Returns:
      Call to execute
      Throws:
      ApiException - If fail to serialize the request body object
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      200 Connected. Events will now start streaming as long as you keep the connection open. -
    • subscribeToTradeV2SSE

      public List<TradeUpdateEventV2> subscribeToTradeV2SSE(@Nullable LocalDate since, @Nullable LocalDate until, @Nullable String sinceId, @Nullable String untilId) throws ApiException
      Subscribe to Trade Events (SSE) The Events API provides event push as well as historical queries via SSE (server sent events). You can listen to events related to trade updates. Most market trades sent during market hours are filled instantly; you can listen to limit order updates through this endpoint. Historical events are streamed immediately if queried, and updates are pushed as events occur. Query Params Rules: - `since` required if `until` specified - `since_id` required if `until_id` specified - `since` and `since_id` can't be used at the same time Behavior: - if `since` or `since_id` not specified this will not return any historic data - if `until` or `until_id` reached stream will end (status 200) --- Note for people using the clients generated from this OAS spec. Currently OAS-3 doesn't have full support for representing SSE style responses from an API, so if you are using a generated client and don't specify a `since` and `until` there is a good chance the generated clients will hang waiting for the response to end. If you require the streaming capabilities we recommend not using the generated clients for this specific usecase until the OAS-3 standards come to a consensus on how to represent this correctly in OAS-3. --- **Legacy trade events API** **Deprecation notice** As part of the deprecation process, the legacy trade events API is now only available for existing broker-partners at: `GET /v1/events/trades` only for compatibility reasons. All new broker partners will not have the option for the legacy trade event endpoint. All new broker partners will have to integrate with the new `/v2/events/trades` endpoint. Also, all existing broker partners are now recommended to upgrade to the `/v2/events/trades` endpoint, which provides faster event delivery times. The legacy trade events api works the same way as the new one with the exception of the event_id which is an integer except of an ULID. This results in the request's since_id and until_id are also being integers. This integer is monotonically increasing over time for events. Please note that the new `/v2` endpoint, is the same as, and was originally available under `/v2beta1`. We encourage all customers to adjust their codebase from that interim beta endpoint to the `/v2` stable endpoint. In the near future we will setup permanent redirect from `/v2beta1` to `/v2` before we completely remove the beta endpoint. --- ### Comment messages According to the SSE specification, any line that starts with a colon is a comment which does not contain data. It is typically a free text that does not follow any data schema. A few examples mentioned below for comment messages. ##### Slow client The server sends a comment when the client is not consuming messages fast enough. Example: `: you are reading too slowly, dropped 10000 messages` ##### Internal server error An error message is sent as a comment when the server closes the connection on an internal server error (only sent by the v2 and v2beta1 endpoints). Example: `: internal server error` --- **Common events** These are the events that are the expected results of actions you may have taken by sending API requests. The meaning of the timestamp field changes for each type; the meanings have been specified here for which types the timestamp field will be present. - `accepted` Sent when an order is received and accepted by Alpaca - `pending_new` Sent when the order has been received by Alpaca and routed to the exchanges, but has not yet been accepted for execution. - `new` Sent when an order has been routed to exchanges for execution. - `fill` Sent when your order has been completely filled. - timestamp: The time at which the order was filled. - `partial_fill` Sent when a number of shares less than the total remaining quantity on your order has been filled. - timestamp: The time at which the shares were filled. - `canceled` Sent when your requested cancellation of an order is processed. - timestamp: The time at which the order was canceled. - `expired` Sent when an order has reached the end of its lifespan, as determined by the order's time in force value. - timestamp: The time at which the order expired. - `done_for_day` Sent when the order is done executing for the day, and will not receive further updates until the next trading day. - `replaced` Sent when your requested replacement of an order is processed. - timestamp: The time at which the order was replaced. **Rarer events** These are events that may rarely be sent due to unexpected circumstances on the exchanges. It is unlikely you will need to design your code around them, but you may still wish to account for the possibility that they will occur. - `rejected` Sent when your order has been rejected. - timestamp: The time at which the rejection occurred. - `held` For multi-leg orders, the secondary orders (stop loss, take profit) will enter this state while waiting to be triggered. - `stopped` Sent when your order has been stopped, and a trade is guaranteed for the order, usually at a stated price or better, but has not yet occurred. - `pending_cancel` Sent when the order is awaiting cancellation. Most cancellations will occur without the order entering this state. - `pending_replace` Sent when the order is awaiting replacement. - `calculated` Sent when the order has been completed for the day - it is either filled or done_for_day - but remaining settlement calculations are still pending. - `suspended` Sent when the order has been suspended and is not eligible for trading. - `order_replace_rejected` Sent when the order replace has been rejected. - `order_cancel_rejected` Sent when the order cancel has been rejected. - `trade_bust`: Sent when a previously reported execution has been canceled (\"busted\") by the upstream exchange. - `trade_correct`: Sent when a previously reported trade has been corrected. For example, the exchange may have updated the price, quantity, or another execution parameter after the trade was initially reported. - `restated`: Sent when the order is manually modified.
      Parameters:
      since - Format: YYYY-MM-DD (optional)
      until - Format: YYYY-MM-DD (optional)
      sinceId - (optional)
      untilId - (optional)
      Returns:
      List<TradeUpdateEventV2>
      Throws:
      ApiException - If fail to call the API, e.g. server error or cannot deserialize the response body
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      200 Connected. Events will now start streaming as long as you keep the connection open. -
    • subscribeToTradeV2SSEWithHttpInfo

      public ApiResponse<List<TradeUpdateEventV2>> subscribeToTradeV2SSEWithHttpInfo(@Nullable LocalDate since, @Nullable LocalDate until, @Nullable String sinceId, @Nullable String untilId) throws ApiException
      Subscribe to Trade Events (SSE) The Events API provides event push as well as historical queries via SSE (server sent events). You can listen to events related to trade updates. Most market trades sent during market hours are filled instantly; you can listen to limit order updates through this endpoint. Historical events are streamed immediately if queried, and updates are pushed as events occur. Query Params Rules: - `since` required if `until` specified - `since_id` required if `until_id` specified - `since` and `since_id` can't be used at the same time Behavior: - if `since` or `since_id` not specified this will not return any historic data - if `until` or `until_id` reached stream will end (status 200) --- Note for people using the clients generated from this OAS spec. Currently OAS-3 doesn't have full support for representing SSE style responses from an API, so if you are using a generated client and don't specify a `since` and `until` there is a good chance the generated clients will hang waiting for the response to end. If you require the streaming capabilities we recommend not using the generated clients for this specific usecase until the OAS-3 standards come to a consensus on how to represent this correctly in OAS-3. --- **Legacy trade events API** **Deprecation notice** As part of the deprecation process, the legacy trade events API is now only available for existing broker-partners at: `GET /v1/events/trades` only for compatibility reasons. All new broker partners will not have the option for the legacy trade event endpoint. All new broker partners will have to integrate with the new `/v2/events/trades` endpoint. Also, all existing broker partners are now recommended to upgrade to the `/v2/events/trades` endpoint, which provides faster event delivery times. The legacy trade events api works the same way as the new one with the exception of the event_id which is an integer except of an ULID. This results in the request's since_id and until_id are also being integers. This integer is monotonically increasing over time for events. Please note that the new `/v2` endpoint, is the same as, and was originally available under `/v2beta1`. We encourage all customers to adjust their codebase from that interim beta endpoint to the `/v2` stable endpoint. In the near future we will setup permanent redirect from `/v2beta1` to `/v2` before we completely remove the beta endpoint. --- ### Comment messages According to the SSE specification, any line that starts with a colon is a comment which does not contain data. It is typically a free text that does not follow any data schema. A few examples mentioned below for comment messages. ##### Slow client The server sends a comment when the client is not consuming messages fast enough. Example: `: you are reading too slowly, dropped 10000 messages` ##### Internal server error An error message is sent as a comment when the server closes the connection on an internal server error (only sent by the v2 and v2beta1 endpoints). Example: `: internal server error` --- **Common events** These are the events that are the expected results of actions you may have taken by sending API requests. The meaning of the timestamp field changes for each type; the meanings have been specified here for which types the timestamp field will be present. - `accepted` Sent when an order is received and accepted by Alpaca - `pending_new` Sent when the order has been received by Alpaca and routed to the exchanges, but has not yet been accepted for execution. - `new` Sent when an order has been routed to exchanges for execution. - `fill` Sent when your order has been completely filled. - timestamp: The time at which the order was filled. - `partial_fill` Sent when a number of shares less than the total remaining quantity on your order has been filled. - timestamp: The time at which the shares were filled. - `canceled` Sent when your requested cancellation of an order is processed. - timestamp: The time at which the order was canceled. - `expired` Sent when an order has reached the end of its lifespan, as determined by the order's time in force value. - timestamp: The time at which the order expired. - `done_for_day` Sent when the order is done executing for the day, and will not receive further updates until the next trading day. - `replaced` Sent when your requested replacement of an order is processed. - timestamp: The time at which the order was replaced. **Rarer events** These are events that may rarely be sent due to unexpected circumstances on the exchanges. It is unlikely you will need to design your code around them, but you may still wish to account for the possibility that they will occur. - `rejected` Sent when your order has been rejected. - timestamp: The time at which the rejection occurred. - `held` For multi-leg orders, the secondary orders (stop loss, take profit) will enter this state while waiting to be triggered. - `stopped` Sent when your order has been stopped, and a trade is guaranteed for the order, usually at a stated price or better, but has not yet occurred. - `pending_cancel` Sent when the order is awaiting cancellation. Most cancellations will occur without the order entering this state. - `pending_replace` Sent when the order is awaiting replacement. - `calculated` Sent when the order has been completed for the day - it is either filled or done_for_day - but remaining settlement calculations are still pending. - `suspended` Sent when the order has been suspended and is not eligible for trading. - `order_replace_rejected` Sent when the order replace has been rejected. - `order_cancel_rejected` Sent when the order cancel has been rejected. - `trade_bust`: Sent when a previously reported execution has been canceled (\"busted\") by the upstream exchange. - `trade_correct`: Sent when a previously reported trade has been corrected. For example, the exchange may have updated the price, quantity, or another execution parameter after the trade was initially reported. - `restated`: Sent when the order is manually modified.
      Parameters:
      since - Format: YYYY-MM-DD (optional)
      until - Format: YYYY-MM-DD (optional)
      sinceId - (optional)
      untilId - (optional)
      Returns:
      ApiResponse<List<TradeUpdateEventV2>>
      Throws:
      ApiException - If fail to call the API, e.g. server error or cannot deserialize the response body
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      200 Connected. Events will now start streaming as long as you keep the connection open. -
    • subscribeToTradeV2SSEAsync

      public okhttp3.Call subscribeToTradeV2SSEAsync(@Nullable LocalDate since, @Nullable LocalDate until, @Nullable String sinceId, @Nullable String untilId, ApiCallback<List<TradeUpdateEventV2>> _callback) throws ApiException
      Subscribe to Trade Events (SSE) (asynchronously) The Events API provides event push as well as historical queries via SSE (server sent events). You can listen to events related to trade updates. Most market trades sent during market hours are filled instantly; you can listen to limit order updates through this endpoint. Historical events are streamed immediately if queried, and updates are pushed as events occur. Query Params Rules: - `since` required if `until` specified - `since_id` required if `until_id` specified - `since` and `since_id` can't be used at the same time Behavior: - if `since` or `since_id` not specified this will not return any historic data - if `until` or `until_id` reached stream will end (status 200) --- Note for people using the clients generated from this OAS spec. Currently OAS-3 doesn't have full support for representing SSE style responses from an API, so if you are using a generated client and don't specify a `since` and `until` there is a good chance the generated clients will hang waiting for the response to end. If you require the streaming capabilities we recommend not using the generated clients for this specific usecase until the OAS-3 standards come to a consensus on how to represent this correctly in OAS-3. --- **Legacy trade events API** **Deprecation notice** As part of the deprecation process, the legacy trade events API is now only available for existing broker-partners at: `GET /v1/events/trades` only for compatibility reasons. All new broker partners will not have the option for the legacy trade event endpoint. All new broker partners will have to integrate with the new `/v2/events/trades` endpoint. Also, all existing broker partners are now recommended to upgrade to the `/v2/events/trades` endpoint, which provides faster event delivery times. The legacy trade events api works the same way as the new one with the exception of the event_id which is an integer except of an ULID. This results in the request's since_id and until_id are also being integers. This integer is monotonically increasing over time for events. Please note that the new `/v2` endpoint, is the same as, and was originally available under `/v2beta1`. We encourage all customers to adjust their codebase from that interim beta endpoint to the `/v2` stable endpoint. In the near future we will setup permanent redirect from `/v2beta1` to `/v2` before we completely remove the beta endpoint. --- ### Comment messages According to the SSE specification, any line that starts with a colon is a comment which does not contain data. It is typically a free text that does not follow any data schema. A few examples mentioned below for comment messages. ##### Slow client The server sends a comment when the client is not consuming messages fast enough. Example: `: you are reading too slowly, dropped 10000 messages` ##### Internal server error An error message is sent as a comment when the server closes the connection on an internal server error (only sent by the v2 and v2beta1 endpoints). Example: `: internal server error` --- **Common events** These are the events that are the expected results of actions you may have taken by sending API requests. The meaning of the timestamp field changes for each type; the meanings have been specified here for which types the timestamp field will be present. - `accepted` Sent when an order is received and accepted by Alpaca - `pending_new` Sent when the order has been received by Alpaca and routed to the exchanges, but has not yet been accepted for execution. - `new` Sent when an order has been routed to exchanges for execution. - `fill` Sent when your order has been completely filled. - timestamp: The time at which the order was filled. - `partial_fill` Sent when a number of shares less than the total remaining quantity on your order has been filled. - timestamp: The time at which the shares were filled. - `canceled` Sent when your requested cancellation of an order is processed. - timestamp: The time at which the order was canceled. - `expired` Sent when an order has reached the end of its lifespan, as determined by the order's time in force value. - timestamp: The time at which the order expired. - `done_for_day` Sent when the order is done executing for the day, and will not receive further updates until the next trading day. - `replaced` Sent when your requested replacement of an order is processed. - timestamp: The time at which the order was replaced. **Rarer events** These are events that may rarely be sent due to unexpected circumstances on the exchanges. It is unlikely you will need to design your code around them, but you may still wish to account for the possibility that they will occur. - `rejected` Sent when your order has been rejected. - timestamp: The time at which the rejection occurred. - `held` For multi-leg orders, the secondary orders (stop loss, take profit) will enter this state while waiting to be triggered. - `stopped` Sent when your order has been stopped, and a trade is guaranteed for the order, usually at a stated price or better, but has not yet occurred. - `pending_cancel` Sent when the order is awaiting cancellation. Most cancellations will occur without the order entering this state. - `pending_replace` Sent when the order is awaiting replacement. - `calculated` Sent when the order has been completed for the day - it is either filled or done_for_day - but remaining settlement calculations are still pending. - `suspended` Sent when the order has been suspended and is not eligible for trading. - `order_replace_rejected` Sent when the order replace has been rejected. - `order_cancel_rejected` Sent when the order cancel has been rejected. - `trade_bust`: Sent when a previously reported execution has been canceled (\"busted\") by the upstream exchange. - `trade_correct`: Sent when a previously reported trade has been corrected. For example, the exchange may have updated the price, quantity, or another execution parameter after the trade was initially reported. - `restated`: Sent when the order is manually modified.
      Parameters:
      since - Format: YYYY-MM-DD (optional)
      until - Format: YYYY-MM-DD (optional)
      sinceId - (optional)
      untilId - (optional)
      _callback - The callback to be executed when the API call finishes
      Returns:
      The request call
      Throws:
      ApiException - If fail to process the API call, e.g. serializing the request body object
      HTTP Response Details:
      Response Details
      Status Code Description Response Headers
      200 Connected. Events will now start streaming as long as you keep the connection open. -