i have ib gatway 4002 port running give a starting point to build this srs software:                 Interactive Brokers Trade Management App
                   Software Requirements Speciﬁcation
Purpose
   - Development of app with GUI for trade entry and management interfacing with Interactive
      Brokers

User Needs
   - App must facilitate basic trade entry functions (stock and futures
   - App should enable trade management capabilities
   - Integration with Interactive Brokers (IB) platform is essential, both TWS and Gateway (v.
      10.23.2a)
   - Ability to select from multiple accounts in IB
   - GUI needs to have several tabs as detailed below
   - It needs to be stable and run 24x7 and include auto-reconnect to IB feature
   - Send notiﬁcation (email and text msg) for different levels of communication (e.g. error,
      disconnection, successful trade entry/exit)
   - Logging (error, warning, information)
   - Import new trades and export closed trades via CSV
   - Six months of support to address any bugs in the system

Functional Requirements
   - Run on Windows 10 and above
   - Use PyQt for GUI development
   - Heartbeat monitor that checks the connection status with IB at regular intervals

GUI Requirements
   - Four tabs for trades (see trade logic below for more details on each tab)
          o Active Orders
          o Active Trades
          o Active Risk Summary
          o Closed Trades
   - Settings options
          o Default setting for trades (see example below)
          o Connection to IB
          o Setup of communication (email and txt)
          o Logs

System Features
   - Below is a trade logic diagram and trade example to explain the steps and math behind the
      logic
   - The last page includes the information for the Active Risk Summary Tab
                                                                Start




                                             Daily CSV entry sheet includes manual
For each ticker API                          entry of:
calculates:                                  +Ticker (Stock or Futures with
+Price range for entry                       Contract date)
(mkt order) based on                   <----  +Long or Short
previous day H/L                             +Initial stop loss to calculate shares
(depending if Short or                       +Full or partial take profit exit
Long)                                        +Manual adjustment stop loss
+Shares to buy based on                                                                     Trade Management includes:
Risk and Initial stop loss                   Constants to apply to all trades:
                                             +Risk $ to calculate position size             +++Active Orders+++
                                             +% to calculate price range for entry          - Ticker, Long/Short, shares, Price range for entry
                                             +Others (see next page)                        - Should have import CSV option and option for manual
                                                                                            entry
|
|

                                                                                            +++Active Trades+++
                                            API to:                                         - Ticker, avg. price entry, shares, short/long, Take Profit
                                            +Adjust or delete conditional                   and %, Stop loss (stop loss can be adjusted manually)
API creates:                                                                                - Date and Days until upcoming earnings report
                                            order based on Entry sheet –
+Conditional order in IB
                                            this is a daily update
                                                                                            +++Active Risk Summary+++
                                                                                            - Overall active trades risk ($)
                                                                                            - Broken down by Indices, Futures, Sectors

                                                         No    -->                             +++Closed Trades+++
                                                                                            -Record of trades including entry price, exit price(s),
  Did order get filled in                                                                   Shares, dates for entry and exit(s), P/L, commissions
           IB?                                                                              - Should have date filter and be exportable in CSV




            Yes
	then full or partial?
                                              API creates:
                                              +Take-Profit and Stop loss for full
                                              order based on fill price and formula
    Full or Partial Take                      using initial stop loss from Entry                 Stop-Loss or Take-
         Profit Exit         Full TP Exit
                                              Sheet.                                            Profit triggered in IB
                                              +Stop loss can be manually adjusted
                                              as trade progresses


       Partial TP Exit


API creates:
+Take-Profit for ½ order
based on fill price and
                                                                                          API creates:
formula using initial stop
                                               Stop-Loss or Take-                         +Trailing Stop for remaining
loss from Entry Sheet.                                                      Take-Profit
                                              Profit triggered in IB                      ½ order based on manual
+Stop loss for full order                        goes to stoploss or tp
                                                                                          adjustment of stop-loss
+Stop loss can be
manually adjusted as trade
progresses
                                                    Stop-Loss

                                       API creates:
                                       +Record of trade including
                                       entry price, exit price(s),
                                       Shares, dates for entry and
                                       exit(s), P/L, commissions




                                                      Stop
EXAMPLE – Trade Long, ﬂip logic for Short

Default settings that are applied to all trades, but can be manually adjusted for a given trade

   •    Risk $ to calculate position size: $2,000 [1]
   •    % to calculate price range for entry 1: 2% [2]
   •    % to calculate price range for entry 2: 25% [3]
   •    Stop loss hours: Regular Trading Hours (RTH)
   •    Take Proﬁt hours: Extended Trading Hours (e.g. outside RTH)
   •    Entry type hours: RTH
   •    Entry Time in Force: Good for day (Day)

Entry criteria (Ticker, Long/Short, SL, TP share%, manual adjustment stop loss, IB account)

   •    SPX [4]
   •    Long [5]
   •    5760 [6]
   •    50% [7]
   •    10% [8]
   •    3429294

API calculates:

    •   Previous day SPX High: $5,850 [9]
    •   Risk per contract (given that [5] is L, then Risk [9]-[6]): $90 [10]
    •   Price for entry 1 ([2]*[10]+[9]): $5,851.80 [11]
    •   Price for entry 2 ([3]*[10]+[9]): $5,872.50 [12]
    •   Contracts to buy (Rounddown([1]/[10])): 21 [13]

API creates Order Ticket in TWS

    •   [4] SPX mkt order
    •   [13] 21 contracts
    •   [11] Conditional entry low price
    •   [11] Conditional entry high price

Order is successful - API creates SL/TP in TWS

    •   Avg. entry at $5855 [14]
    •   Risk ([14]-[6]): $95 [15]
    •   TP (1R): $5,950 for half the position (see [7])
    •   SL ([14]-[8]*[15]): $5,845.50 [16]

Take proﬁt hit – API create SL based on manual input

    •   No TP
    •   SL based on daily manual adjustments
Active Risk Summary Tab

For each active trade calculate:

   •   Risk: Difference between Entry [14] and Stop Loss [16]. Note, if this is positive, then zero risk
   •   Stocks – Sector

Provide Summary Table of Active Risk by

   •   Overall Portfolio
   •   Indices
   •   Futures
   •   Sectors