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

# newOrderWebhook

> New order from webhook. [Tutorial setup](https://alphainsider.com/resources#trading-view).<br/>Note, by default you go fully in or out of a position at `leverage`. Set `pyramiding` to scale into a position over multiple same-direction alerts.



## OpenAPI

````yaml /openapi.yaml post /newOrderWebhook
openapi: 3.1.0
info:
  title: AlphaInsider
  version: '1.0'
  description: >-
    The official API and websocket documentation for
    [AlphaInsider.com](https://alphainsider.com/)
servers:
  - url: https://alphainsider.com/api
security: []
tags:
  - name: Introduction
  - name: Authentication
  - name: Users
  - name: Strategies
  - name: Subscriptions
  - name: Payments
  - name: Withdrawals
  - name: Timelines
  - name: Stocks
  - name: Trades
  - name: Webhooks
  - name: Bots
  - name: Websockets
paths:
  /newOrderWebhook:
    post:
      tags:
        - Webhooks
      summary: newOrderWebhook
      description: >-
        New order from webhook. [Tutorial
        setup](https://alphainsider.com/resources#trading-view).<br/>Note, by
        default you go fully in or out of a position at `leverage`. Set
        `pyramiding` to scale into a position over multiple same-direction
        alerts.
      operationId: newOrderWebhook
      requestBody:
        content:
          application/json:
            schema:
              type: object
              required:
                - strategy_id
                - stock_id
                - action
                - api_token
              properties:
                strategy_id:
                  $ref: '#/components/schemas/strategy_id'
                stock_id:
                  $ref: '#/components/schemas/stock_id'
                action:
                  type: string
                  description: >-
                    Order actions. Action "buy" is the same as "long", "sell" is
                    the same as "short", "close" is the same as "flat".

                    It is recommended for TradingView webhooks to use the
                    **{{strategy.market_position}}** to get all strategy
                    actions.

                    [See TradingView strategy alert guide for full list of
                    automated
                    actions](https://www.tradingview.com/support/solutions/43000481368-strategy-alerts/).
                  enum:
                    - buy
                    - long
                    - sell
                    - short
                    - close
                    - flat
                leverage:
                  type: number
                  minimum: 0
                  maximum: 2
                  multipleOf: 0.01
                  default: 1
                  description: Leverage to trade at. Defaults to 1 if not set.
                pyramiding:
                  type: integer
                  minimum: 1
                  maximum: 100
                  description: >-
                    Number of same-direction trades needed to reach full
                    `leverage`. Each same-direction alert steps the position by
                    `leverage / pyramiding` toward full leverage. Once at full
                    leverage, additional same-direction alerts rebalance the
                    position back to exactly `leverage`. An opposite-direction
                    alert reverses the position to the first step on the new
                    side. Ignored for "close"/"flat", which liquidates the
                    strategy. If not set, each alert goes fully in or out of the
                    position at `leverage`.
                slippage:
                  type: number
                  minimum: 0
                  maximum: 0.05
                  multipleOf: 0.001
                  default: 0.002
                  description: >-
                    Slippage represents the percentage offset from the current
                    bid/ask price when placing a limit order. This adjustment
                    helps ensure that orders are more likely to fill by
                    accounting for potential price movements. Defaults to 0.002
                    if not set.
                api_token:
                  type: string
                  format: JWT
                  description: User API token with `newOrderWebhook` permission.
            examples:
              request_sample:
                value:
                  strategy_id: <string>
                  stock_id: <string>
                  action: '{{strategy.market_position}}'
                  leverage: 1.5
                  pyramiding: 5
                  api_token: <string>
      responses:
        '200':
          description: Request was successful.
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    $ref: '#/components/schemas/success'
                  response:
                    type: object
                    description: >-
                      Endpoint-specific response payload, or an error message
                      when `success` is false.
                    properties:
                      order_id:
                        $ref: '#/components/schemas/order_id'
                      strategy_id:
                        $ref: '#/components/schemas/strategy_id'
                      type:
                        type: string
                        enum:
                          - market
                          - limit
                          - stop_market
                          - stop_limit
                          - oco
                          - liquidate
                        description: Type or category for this object.
                      action:
                        type: string
                        enum:
                          - buy
                          - sell
                        description: Order or signal action.
                      stop_price:
                        type:
                          - string
                          - 'null'
                        description: Stop trigger price.
                      price:
                        type:
                          - string
                          - 'null'
                        description: Price or execution price, depending on context.
                      amount:
                        type: string
                        description: Amount.
                      total:
                        type:
                          - string
                          - 'null'
                        description: >-
                          Total value; for positions/orders this is
                          strategy-normalized unless documented otherwise.
                      created_at:
                        $ref: '#/components/schemas/created_at'
                      stock_id:
                        $ref: '#/components/schemas/stock_id'
                      figi_composite:
                        type:
                          - string
                          - 'null'
                        description: Composite FIGI identifier when available.
                      symbol:
                        type: string
                        description: Ticker or asset symbol.
                      name:
                        type: string
                        description: Display name.
                      sector:
                        type: string
                        description: Sector or asset category.
                      security:
                        type: string
                        enum:
                          - cryptocurrency
                          - stock
                        description: Security type, such as stock or cryptocurrency.
                      exchange:
                        type: string
                        description: Exchange code.
                      stock:
                        type: string
                        description: Stock symbol as stored by AlphaInsider.
                      peg:
                        type: string
                        description: Peg or quote currency.
                      provider:
                        type: string
                        enum:
                          - coinbase
                          - binance
                          - massive
                          - alphainsider
                        description: External provider or data provider.
                      slippage:
                        type: string
                        description: Slippage value or configured slippage fraction.
                      fee:
                        type: string
                        description: Fee value.
                      links:
                        type: object
                        description: External research and market-data links.
                      stock_status:
                        type: string
                        enum:
                          - active
                          - deleted
                        description: Current stock status.
                      bid:
                        type: string
                        description: Current bid price.
                      ask:
                        type: string
                        description: Current ask price.
                      last:
                        type: string
                        description: Last traded price.
                      order_dependencies:
                        type: array
                        description: >-
                          Order IDs this order is waiting on; `[]` means the
                          order has no outstanding dependencies.
                        items:
                          type: string
              examples:
                '200':
                  value:
                    success: true
                    response:
                      order_id: qoppbNXH4lG0-4x21YLCp
                      strategy_id: 7Wy5AzIKY9bCmkIqjcLSg
                      type: market
                      action: sell
                      stop_price: null
                      price: null
                      amount: '0.000200000000000'
                      total: null
                      created_at: '2024-10-22T21:47:19.540Z'
                      stock_id: v3lhjrwEhNuAOxPT29oxO
                      figi_composite: null
                      symbol: ETH-USD
                      name: Ethereum
                      sector: Cryptocurrencies
                      security: cryptocurrency
                      exchange: COINBASE
                      stock: ETH-USD
                      peg: USD
                      provider: coinbase
                      slippage: '0.000000000000000'
                      fee: '0.002500000000000'
                      links:
                        trading_view: >-
                          https://www.tradingview.com/symbols/ETHUSD/?exchange=COINBASE
                        yahoo_finance: https://finance.yahoo.com/quote/ETH-USD
                        coin_marketcap: https://coinmarketcap.com/currencies/ethereum/
                        google_finance: https://www.google.com/finance/quote/ETH-USD
                      stock_status: active
                      bid: '2633.43'
                      ask: '2633.43'
                      last: '2633.43'
                      order_dependencies: []
        '400':
          $ref: '#/components/responses/400'
        '401':
          $ref: '#/components/responses/401'
components:
  schemas:
    strategy_id:
      type: string
      description: AlphaInsider strategy identifier.
    stock_id:
      type: string
      description: AlphaInsider stock identifier, or `SYMBOL:EXCHANGE` in requests.
    success:
      type: boolean
      description: True when the request succeeded.
    order_id:
      type: string
      description: Order identifier.
    created_at:
      type: string
      format: date-time
      description: Creation timestamp.
  responses:
    '400':
      description: Request failed.
      content:
        application/json:
          schema:
            type: object
            properties:
              success:
                type: boolean
                description: False when the request failed.
              response:
                type: string
                description: Error message.
          examples:
            '400':
              value:
                success: false
                response: Request failed.
    '401':
      description: Authentication failed.
      content:
        application/json:
          schema:
            type: object
            properties:
              success:
                type: boolean
                description: False when the request failed.
              response:
                type: string
                description: Error message.
          examples:
            '401':
              value:
                success: false
                response: Authentication failed.

````