B
     9-e|                 @   s|   d Z ddlT ddlT ddlmZmZmZ ddlmZ ddl	m
Z
 ddlmZ ddlT ddlmZ eeZG dd	 d	Zd
S )z
Copyright (C) 2019 Interactive Brokers LLC. All rights reserved. This code is subject to the terms
 and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable.
    )*)ContractContractDetailsDeltaNeutralContract)Order)
OrderState)	Execution)CommissionReportc               @   sV  e Zd Zdd Zdd ZdeeedddZeed	d
dZ	dd Z
eedddZeeeedddZeeedddZedddZeeedddZeeedddZeeeeeeeeed	d d!Zeeeeeeeeeeed"d#d$Zeeeed%d&d'Zd(d) Zd*d+ Zeeeed,d-d.Zeeeeeeeed/d0d1Zed2d3d4Z ed5d6d7Z!ed8d9d:Z"ee#d;d<d=Z$ee#d;d>d?Z%edd@dAZ&eee'dBdCdDZ(eddEdFZ)eeeeeedGdHdIZ*eeeeeeee+dJdKdLZ,eeeedMdNdOZ-edPdQdRZ.e/edSdTdUZ0ee1dVdWdXZ2eeedYdZd[Z3ed\d]d^Z4eee#eeeed_d`daZ5eddbdcZ6eeeeeeeeedd	dedfZ7edgdhdiZ8eedjdkdlZ9ee:dmdndoZ;e<dpdqdrZ=eeeedsdtduZ>dvdw Z?eeeeedxdydzZ@edd{d|ZAed}d~dZBe+edddZCeedddZDe+edddZEeedddZFeedddZGeeeeeedddZHedddZIeeeeeedddZJedddZKeeeeeeeeeeedddZLeeeeeeMeNdddZOedddZPeeQdddZReSdddZTeeUdddZVeWdddZXeeeeeedddZYeeZdddZ[eeeedddZ\e]dddZ^eeedddZ_eeeeedddZ`ee+dddZaeedddÄZbeecdĜddƄZdee1dVddȄZeeeedɜdd˄Zfeeedɜdd̈́ZgeehdΜddЄZieeeedќddӄZjeeeeeedԜddքZkeele+dלddلZmeene+dלddۄZoeepe+dלdd݄ZqeeeeeereedޜddZseeeeeeetdddZueeedddZveeedddZweeedddZxdd ZyeedddZzeedddZ{eedddZ|eeeee}dddZ~eedddZdS )EWrapperc             C   s   d S )N )selfr   r   G:\My Drive\STUDY\EPAT\09 TBP - Trading & Back-testing Platforms\TBP04 - Backtesting & Live Trading\IB IBridgePy API\02 Python 3.7 IBridgePy_Win_Anaconda37_64\ibapi\wrapper.py__init__$   s    zEWrapper.__init__c             C   s:   t tjr6d|kr$t|}|d= n|}t d|| d S )Nr   zANSWER %s %s)loggerisEnabledForloggingINFOdictinfo)r   fnNamefnParamsprmsr   r   r   	logAnswer'   s    zEWrapper.logAnswer )reqId	errorCodeerrorStringc             C   s<   |  t t  |r(td|||| ntd||| dS )z}This event is called when there is an error with the
        communication or when TWS wants to send a message to the client.zERROR %s %s %s %szERROR %s %s %sN)r   current_fn_namevarsr   error)r   r   r   r   advancedOrderRejectJsonr   r   r   r   1   s    zEWrapper.error)text	lastErrorc             C   s   |  t t  d S )N)r   r   r   )r   r!   r"   r   r   r   winError;   s    zEWrapper.winErrorc             C   s   |  t t  dS )z9 callback signifying completion of successful connection N)r   r   r   )r   r   r   r   
connectAck?   s    zEWrapper.connectAck)r   marketDataTypec             C   s   |  t t  dS )a  TWS sends a marketDataType(type) callback to the API, where
        type is set to Frozen or RealTime, to announce that market data has been
        switched between frozen and real-time. This notification occurs only
        when market data switches between real-time and frozen. The
        marketDataType( ) callback accepts a reqId parameter and is sent per
        every subscription because different contracts can generally trade on a
        different schedule.N)r   r   r   )r   r   r%   r   r   r   r%   D   s    	zEWrapper.marketDataType)r   tickTypepriceattribc             C   s   |  t t  dS )zAMarket data tick price callback. Handles all price related ticks.N)r   r   r   )r   r   r&   r'   r(   r   r   r   	tickPriceP   s    zEWrapper.tickPrice)r   r&   sizec             C   s   |  t t  dS )z?Market data tick size callback. Handles all size-related ticks.N)r   r   r   )r   r   r&   r*   r   r   r   tickSizeW   s    zEWrapper.tickSize)r   c             C   s   |  t t  dS )zmWhen requesting market data snapshots, this market will indicate the
        snapshot reception is finished. N)r   r   r   )r   r   r   r   r   tickSnapshotEnd]   s    zEWrapper.tickSnapshotEnd)r   r&   valuec             C   s   |  t t  d S )N)r   r   r   )r   r   r&   r-   r   r   r   tickGenericd   s    zEWrapper.tickGenericc             C   s   |  t t  d S )N)r   r   r   )r   r   r&   r-   r   r   r   
tickStringh   s    zEWrapper.tickString)	r   r&   basisPointsformattedBasisPointstotalDividendsholdDaysfutureLastTradeDatedividendImpactdividendsToLastTradeDatec
       
      C   s$   |  t t  |  t t  d S )N)r   r   r   )
r   r   r&   r0   r1   r2   r3   r4   r5   r6   r   r   r   tickEFPl   s    zEWrapper.tickEFP)orderIdstatusfilled	remainingavgFillPricepermIdparentIdlastFillPriceclientIdwhyHeldmktCapPricec             C   s   |  t t  dS )a2  This event is called whenever the status of an order changes. It is
        also fired after reconnecting to TWS if the client has any open orders.

        orderId: OrderId - The order ID that was specified previously in the
            call to placeOrder()
        status:str - The order status. Possible values include:
            PendingSubmit - indicates that you have transmitted the order, but have not  yet received confirmation that it has been accepted by the order destination. NOTE: This order status is not sent by TWS and should be explicitly set by the API developer when an order is submitted.
            PendingCancel - indicates that you have sent a request to cancel the order but have not yet received cancel confirmation from the order destination. At this point, your order is not confirmed canceled. You may still receive an execution while your cancellation request is pending. NOTE: This order status is not sent by TWS and should be explicitly set by the API developer when an order is canceled.
            PreSubmitted - indicates that a simulated order type has been accepted by the IB system and that this order has yet to be elected. The order is held in the IB system until the election criteria are met. At that time the order is transmitted to the order destination as specified.
            Submitted - indicates that your order has been accepted at the order destination and is working.
            Cancelled - indicates that the balance of your order has been confirmed canceled by the IB system. This could occur unexpectedly when IB or the destination has rejected your order.
            Filled - indicates that the order has been completely filled.
            Inactive - indicates that the order has been accepted by the system (simulated orders) or an exchange (native orders) but that currently the order is inactive due to system, exchange or other issues.
        filled:int - Specifies the number of shares that have been executed.
            For more information about partial fills, see Order Status for Partial Fills.
        remaining:int -   Specifies the number of shares still outstanding.
        avgFillPrice:float - The average price of the shares that have been executed. This parameter is valid only if the filled parameter value is greater than zero. Otherwise, the price parameter will be zero.
        permId:int -  The TWS id used to identify orders. Remains the same over TWS sessions.
        parentId:int - The order ID of the parent order, used for bracket and auto trailing stop orders.
        lastFilledPrice:float - The last price of the shares that have been executed. This parameter is valid only if the filled parameter value is greater than zero. Otherwise, the price parameter will be zero.
        clientId:int - The ID of the client (or TWS) that placed the order. Note that TWS orders have a fixed clientId and orderId of 0 that distinguishes them from API orders.
        whyHeld:str - This field is used to identify an order held when TWS is trying to locate shares for a short sell. The value used to indicate this is 'locate'.

        N)r   r   r   )r   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   r   r   r   orderStatus   s    zEWrapper.orderStatus)r8   contractorder
orderStatec             C   s   |  t t  dS )a  This function is called to feed in open orders.

        orderID: OrderId - The order ID assigned by TWS. Use to cancel or
            update TWS order.
        contract: Contract - The Contract class attributes describe the contract.
        order: Order - The Order class gives the details of the open order.
        orderState: OrderState - The orderState class includes attributes Used
            for both pre and post trade margin and commission data.N)r   r   r   )r   r8   rD   rE   rF   r   r   r   	openOrder   s    zEWrapper.openOrderc             C   s   |  t t  dS )z=This is called at the end of a given request for open orders.N)r   r   r   )r   r   r   r   openOrderEnd   s    zEWrapper.openOrderEndc             C   s   |  t t  dS )zzThis function is called when TWS closes the sockets
        connection with the ActiveX control, or when TWS is shut down.N)r   r   r   )r   r   r   r   connectionClosed   s    zEWrapper.connectionClosed)keyvalcurrencyaccountNamec             C   s   |  t t  dS )zg This function is called only when ReqAccountUpdates on
        EEClientSocket object has been called. N)r   r   r   )r   rJ   rK   rL   rM   r   r   r   updateAccountValue   s    zEWrapper.updateAccountValue)rD   positionmarketPricemarketValueaverageCostunrealizedPNLrealizedPNLrM   c	       	      C   s   |  t t  dS )zeThis function is called only when reqAccountUpdates on
        EEClientSocket object has been called.N)r   r   r   )	r   rD   rO   rP   rQ   rR   rS   rT   rM   r   r   r   updatePortfolio   s    zEWrapper.updatePortfolio)	timeStampc             C   s   |  t t  d S )N)r   r   r   )r   rV   r   r   r   updateAccountTime   s    zEWrapper.updateAccountTime)rM   c             C   s   |  t t  dS )zXThis is called after a batch updateAccountValue() and
        updatePortfolio() is sent.N)r   r   r   )r   rM   r   r   r   accountDownloadEnd   s    zEWrapper.accountDownloadEnd)r8   c             C   s   |  t t  dS )z Receives next valid order id.N)r   r   r   )r   r8   r   r   r   nextVa1idId   s    zEWrapper.nextVa1idId)r   contractDetailsc             C   s   |  t t  dS )zReceives the full contract's definitions. This method will return all
        contracts matching the requested via EEClientSocket::reqContractDetails.
        For example, one can obtain the whole option chain with it.N)r   r   r   )r   r   rZ   r   r   r   rZ      s    zEWrapper.contractDetailsc             C   s   |  t t  dS )z[This function is called when reqContractDetails function
        has been called for bonds.N)r   r   r   )r   r   rZ   r   r   r   bondContractDetails   s    zEWrapper.bondContractDetailsc             C   s   |  t t  dS )zThis function is called once all contract details for a given
        request are received. This helps to define the end of an option
        chain.N)r   r   r   )r   r   r   r   r   contractDetailsEnd   s    zEWrapper.contractDetailsEnd)r   rD   	executionc             C   s   |  t t  dS )zhThis event is fired when the reqExecutions() functions is
        invoked, or when an order is filled.  N)r   r   r   )r   r   rD   r]   r   r   r   execDetails   s    zEWrapper.execDetailsc             C   s   |  t t  dS )znThis function is called once all executions have been sent to
        a client in response to reqExecutions().N)r   r   r   )r   r   r   r   r   execDetailsEnd   s    zEWrapper.execDetailsEnd)r   rO   	operationsider'   r*   c             C   s   |  t t  dS )a  Returns the order book.

        tickerId -  the request's identifier
        position -  the order book's row being updated
        operation - how to refresh the row:
            0 = insert (insert this new order into the row identified by 'position')
            1 = update (update the existing order in the row identified by 'position')
            2 = delete (delete the existing order at the row identified by 'position').
        side -  0 for ask, 1 for bid
        price - the order's price
        size -  the order's sizeN)r   r   r   )r   r   rO   r`   ra   r'   r*   r   r   r   updateMktDepth  s    zEWrapper.updateMktDepth)r   rO   marketMakerr`   ra   r'   r*   isSmartDepthc	       	      C   s   |  t t  dS )aw  Returns the order book.

        tickerId -  the request's identifier
        position -  the order book's row being updated
        marketMaker - the exchange holding the order
        operation - how to refresh the row:
            0 = insert (insert this new order into the row identified by 'position')
            1 = update (update the existing order in the row identified by 'position')
            2 = delete (delete the existing order at the row identified by 'position').
        side -  0 for ask, 1 for bid
        price - the order's price
        size -  the order's size
        isSmartDepth - is SMART Depth requestN)r   r   r   )	r   r   rO   rc   r`   ra   r'   r*   rd   r   r   r   updateMktDepthL2  s    zEWrapper.updateMktDepthL2)msgIdmsgTypenewsMessage
originExchc             C   s   |  t t  dS )a:   provides IB's bulletins
        msgId - the bulletin's identifier
        msgType - one of: 1 - Regular news bulletin 2 - Exchange no longer
            available for trading 3 - Exchange is available for trading
        message - the message
        origExchange -    the exchange where the message comes from.  N)r   r   r   )r   rf   rg   rh   ri   r   r   r   updateNewsBulletin)  s    	zEWrapper.updateNewsBulletin)accountsListc             C   s   |  t t  dS )z?Receives a comma-separated string with the managed account ids.N)r   r   r   )r   rk   r   r   r   managedAccounts5  s    zEWrapper.managedAccounts)faDatacxmlc             C   s   |  t t  dS )a9   receives the Financial Advisor's configuration available in the TWS

        faDataType - one of:
            Groups: offer traders a way to create a group of accounts and apply
                 a single allocation method to all accounts in the group.
            Profiles: let you allocate shares on an account-by-account basis
                using a predefined calculation value.
            Account Aliases: let you easily identify the accounts by meaningful
                 names rather than account numbers.
        faXmlData -  the xml-formatted configuration N)r   r   r   )r   rm   rn   r   r   r   	receiveFA:  s    zEWrapper.receiveFA)r   barc             C   s   |  t t  dS )a   returns the requested historical data bars

        reqId - the request's identifier
        date  - the bar's date and time (either as a yyyymmss hh:mm:ssformatted
             string or as system time according to the request)
        open  - the bar's open point
        high  - the bar's high point
        low   - the bar's low point
        close - the bar's closing point
        volume - the bar's traded volume if available
        count - the number of trades during the bar's timespan (only available
            for TRADES).
        WAP -   the bar's Weighted Average Price
        hasGaps  -indicates if the data has gaps or not. N)r   r   r   )r   r   rp   r   r   r   historicalDataH  s    zEWrapper.historicalData)r   startendc             C   s   |  t t  dS )z4 Marks the ending of the historical bars reception. N)r   r   r   )r   r   rr   rs   r   r   r   historicalDataEnd[  s    zEWrapper.historicalDataEnd)xmlc             C   s   |  t t  dS )z Provides the xml-formatted parameters available to create a market
        scanner.

        xml -   the xml-formatted string with the available parameters.N)r   r   r   )r   ru   r   r   r   scannerParameters`  s    zEWrapper.scannerParameters)r   rankrZ   distance	benchmark
projectionlegsStrc             C   s   |  t t  dS )a   Provides the data resulting from the market scanner request.

        reqid - the request's identifier.
        rank -  the ranking within the response of this bar.
        contractDetails - the data's ContractDetails
        distance -      according to query.
        benchmark -     according to query.
        projection -    according to query.
        legStr - describes the combo legs when the scanner is returning EFPN)r   r   r   )r   r   rw   rZ   rx   ry   rz   r{   r   r   r   scannerDatah  s    zEWrapper.scannerDatac             C   s   |  t t  dS )z_ Indicates the scanner data reception has terminated.

        reqId - the request's identifierN)r   r   r   )r   r   r   r   r   scannerDataEndw  s    zEWrapper.scannerDataEnd)	r   timeopen_highlowclosevolumewapcountc
       
      C   s   |  t t  dS )af   Updates the real time 5 seconds bars

        reqId - the request's identifier
        bar.time  - start of bar in unix (or 'epoch') time
        bar.endTime - for synthetic bars, the end time (requires TWS v964). Otherwise -1.
        bar.open_  - the bar's open value
        bar.high  - the bar's high value
        bar.low   - the bar's low value
        bar.close - the bar's closing value
        bar.volume - the bar's traded volume if available
        bar.WAP   - the bar's Weighted Average Price
        bar.count - the number of trades during the bar's timespan (only available
            for TRADES).N)r   r   r   )
r   r   r~   r   r   r   r   r   r   r   r   r   r   realtimeBar  s    zEWrapper.realtimeBar)r~   c             C   s   |  t t  dS )z Server's current time. This method will receive IB server's system
        time resulting after the invokation of reqCurrentTime. N)r   r   r   )r   r~   r   r   r   current  s    zEWrapper.current)r   datac             C   s   |  t t  dS )zThis function is called to receive fundamental
        market data. The appropriate market data subscription must be set
        up in Account Management before you can receive this data.N)r   r   r   )r   r   r   r   r   r   fundamentalData  s    zEWrapper.fundamentalData)r   deltaNeutralContractc             C   s   |  t t  dS )a  Upon accepting a Delta-Neutral RFQ(request for quote), the
        server sends a deltaNeutralValidation() message with the DeltaNeutralContract
        structure. If the delta and price fields are empty in the original
        request, the confirmation will contain the current values from the
        server. These values are locked when the RFQ is processed and remain
        locked until the RFQ is canceled.N)r   r   r   )r   r   r   r   r   r   deltaNeutralValidation  s    zEWrapper.deltaNeutralValidation)commissionReportc             C   s   |  t t  dS )zThe commissionReport() callback is triggered as follows:
        - immediately after a trade execution
        - by calling reqExecutions().N)r   r   r   )r   r   r   r   r   r     s    zEWrapper.commissionReport)accountrD   rO   avgCostc             C   s   |  t t  dS )ziThis event returns real-time positions for all accounts in
        response to the reqPositions() method.N)r   r   r   )r   r   rD   rO   r   r   r   r   rO     s    zEWrapper.positionc             C   s   |  t t  dS )zThis is called once all position data for a given request are
        received and functions as an end marker for the position() data. N)r   r   r   )r   r   r   r   positionEnd  s    zEWrapper.positionEnd)r   r   tagr-   rL   c             C   s   |  t t  dS )zdReturns the data from the TWS Account Window Summary tab in
        response to reqAccountSummary().N)r   r   r   )r   r   r   r   r-   rL   r   r   r   accountSummary  s    zEWrapper.accountSummaryc             C   s   |  t t  dS )z]This method is called once all account summary data for a
        given request are received.N)r   r   r   )r   r   r   r   r   accountSummaryEnd  s    zEWrapper.accountSummaryEnd)apiDatac             C   s   |  t t  dS )z Deprecated Function N)r   r   r   )r   r   r   r   r   verifyMessageAPI  s    zEWrapper.verifyMessageAPI)isSuccessful	errorTextc             C   s   |  t t  d S )N)r   r   r   )r   r   r   r   r   r   verifyCompleted  s    zEWrapper.verifyCompleted)r   xyzChallangec             C   s   |  t t  d S )N)r   r   r   )r   r   r   r   r   r   verifyAndAuthMessageAPI  s    z EWrapper.verifyAndAuthMessageAPIc             C   s   |  t t  d S )N)r   r   r   )r   r   r   r   r   r   verifyAndAuthCompleted  s    zEWrapper.verifyAndAuthCompleted)r   groupsc             C   s   |  t t  dS )a  This callback is a one-time response to queryDisplayGroups().

        reqId - The requestId specified in queryDisplayGroups().
        groups - A list of integers representing visible group ID separated by
            the | character, and sorted by most used group first. This list will
             not change during TWS session (in other words, user cannot add a
            new group; sorting can change though).N)r   r   r   )r   r   r   r   r   r   displayGroupList  s    	zEWrapper.displayGroupList)r   contractInfoc             C   s   |  t t  dS )a  This is sent by TWS to the API client once after receiving
        the subscription request subscribeToGroupEvents(), and will be sent
        again if the selected contract in the subscribed display group has
        changed.

        requestId - The requestId specified in subscribeToGroupEvents().
        contractInfo - The encoded value that uniquely represents the contract
            in IB. Possible values include:
            none = empty selection
            contractID@exchange = any non-combination contract.
                Examples: 8314@SMART for IBM SMART; 8314@ARCA for IBM @ARCA.
            combo = if any combo is selected.  N)r   r   r   )r   r   r   r   r   r   displayGroupUpdated  s    zEWrapper.displayGroupUpdated)r   r   	modelCoderD   posr   c             C   s   |  t t  dS )zGsame as position() except it can be for a certain
        account/modelN)r   r   r   )r   r   r   r   rD   r   r   r   r   r   positionMulti  s    zEWrapper.positionMultic             C   s   |  t t  dS )zJsame as positionEnd() except it can be for a certain
        account/modelN)r   r   r   )r   r   r   r   r   positionMultiEnd  s    zEWrapper.positionMultiEnd)r   r   r   rJ   r-   rL   c             C   s   |  t t  dS )zQsame as updateAccountValue() except it can be for a certain
        account/modelN)r   r   r   )r   r   r   r   rJ   r-   rL   r   r   r   accountUpdateMulti  s    zEWrapper.accountUpdateMultic             C   s   |  t t  dS )zQsame as accountDownloadEnd() except it can be for a certain
        account/modelN)r   r   r   )r   r   r   r   r   accountUpdateMultiEnd  s    zEWrapper.accountUpdateMultiEnd)r   r&   
tickAttrib
impliedVoldeltaoptPrice
pvDividendgammavegathetaundPricec             C   s   |  t t  dS )zThis function is called when the market in an option or its
        underlier moves. TWS's option model volatilities, prices, and
        deltas, along with the present value of dividends expected on that
        options underlier are received.N)r   r   r   )r   r   r&   r   r   r   r   r   r   r   r   r   r   r   r   tickOptionComputation"  s    zEWrapper.tickOptionComputation)r   exchangeunderlyingConIdtradingClass
multiplierexpirationsstrikesc             C   s   |  t t  dS )a   Returns the option chain for an underlying on an exchange
        specified in reqSecDefOptParams There will be multiple callbacks to
        securityDefinitionOptionParameter if multiple exchanges are specified
        in reqSecDefOptParams

        reqId - ID of the request initiating the callback
        underlyingConId - The conID of the underlying security
        tradingClass -  the option trading class
        multiplier -    the option multiplier
        expirations - a list of the expiries for the options of this underlying
             on this exchange
        strikes - a list of the possible strikes for options of this underlying
             on this exchange N)r   r   r   )r   r   r   r   r   r   r   r   r   r   r   !securityDefinitionOptionParameter-  s    z*EWrapper.securityDefinitionOptionParameterc             C   s   |  t t  dS )z Called when all callbacks to securityDefinitionOptionParameter are
        complete

        reqId - the ID used in the call to securityDefinitionOptionParameter N)r   r   r   )r   r   r   r   r   $securityDefinitionOptionParameterEndA  s    z-EWrapper.securityDefinitionOptionParameterEnd)r   tiersc             C   s   |  t t  dS )z Called when receives Soft Dollar Tier configuration information

        reqId - The request ID used in the call to EEClient::reqSoftDollarTiers
        tiers - Stores a list of SoftDollarTier that contains all Soft Dollar
            Tiers information N)r   r   r   )r   r   r   r   r   r   softDollarTiersJ  s    zEWrapper.softDollarTiers)familyCodesc             C   s   |  t t  dS )z returns array of family codes N)r   r   r   )r   r   r   r   r   r   T  s    zEWrapper.familyCodes)r   contractDescriptionsc             C   s   |  t t  dS )z/ returns array of sample contract descriptions N)r   r   r   )r   r   r   r   r   r   symbolSamplesY  s    zEWrapper.symbolSamples)depthMktDataDescriptionsc             C   s   |  t t  dS )zB returns array of exchanges which return depth to UpdateMktDepthL2N)r   r   r   )r   r   r   r   r   mktDepthExchanges^  s    zEWrapper.mktDepthExchanges)tickerIdrV   providerCode	articleIdheadline	extraDatac             C   s   |  t t  dS )z returns news headlinesN)r   r   r   )r   r   rV   r   r   r   r   r   r   r   tickNewsb  s    zEWrapper.tickNews)r   smartComponentMapc             C   s   |  t t  dS )z"returns exchange component mappingN)r   r   r   )r   r   r   r   r   r   smartComponentsf  s    zEWrapper.smartComponents)r   minTickbboExchangesnapshotPermissionsc             C   s   |  t t  dS )z-returns exchange map of a particular contractN)r   r   r   )r   r   r   r   r   r   r   r   tickReqParamsj  s    zEWrapper.tickReqParams)newsProvidersc             C   s   |  t t  dS )z0returns available, subscribed API news providersN)r   r   r   )r   r   r   r   r   r   n  s    zEWrapper.newsProviders)	requestIdarticleTypearticleTextc             C   s   |  t t  dS )zreturns body of news articleN)r   r   r   )r   r   r   r   r   r   r   newsArticler  s    zEWrapper.newsArticle)r   r~   r   r   r   c             C   s   |  t t  dS )z!returns historical news headlinesN)r   r   r   )r   r   r~   r   r   r   r   r   r   historicalNewsv  s    zEWrapper.historicalNews)r   hasMorec             C   s   |  t t  dS )zsignals end of historical newsN)r   r   r   )r   r   r   r   r   r   historicalNewsEndz  s    zEWrapper.historicalNewsEnd)r   headTimestampc             C   s   |  t t  dS )zKreturns earliest available data of a type of data for a particular contractN)r   r   r   )r   r   r   r   r   r   r   ~  s    zEWrapper.headTimestamp)r   itemsc             C   s   |  t t  dS )z%returns histogram data for a contractN)r   r   r   )r   r   r   r   r   r   histogramData  s    zEWrapper.histogramDatac             C   s   |  t t  dS )z=returns updates in real time when keepUpToDate is set to TrueN)r   r   r   )r   r   rp   r   r   r   historicalDataUpdate  s    zEWrapper.historicalDataUpdate)r   conIdr   c             C   s   |  t t  dS )z@returns reroute CFD contract information for market data requestN)r   r   r   )r   r   r   r   r   r   r   rerouteMktDataReq  s    zEWrapper.rerouteMktDataReqc             C   s   |  t t  dS )zAreturns reroute CFD contract information for market depth requestN)r   r   r   )r   r   r   r   r   r   r   rerouteMktDepthReq  s    zEWrapper.rerouteMktDepthReq)marketRuleIdpriceIncrementsc             C   s   |  t t  dS )zIreturns minimum price increment structure for a particular market rule IDN)r   r   r   )r   r   r   r   r   r   
marketRule  s    zEWrapper.marketRule)r   dailyPnLunrealizedPnLrealizedPnLc             C   s   |  t t  dS )z%returns the daily PnL for the accountN)r   r   r   )r   r   r   r   r   r   r   r   pnl  s    zEWrapper.pnl)r   r   r   r   r   r-   c             C   s   |  t t  dS )z:returns the daily PnL for a single position in the accountN)r   r   r   )r   r   r   r   r   r   r-   r   r   r   	pnlSingle  s    zEWrapper.pnlSingle)r   ticksdonec             C   s   |  t t  dS )z5returns historical tick data when whatToShow=MIDPOINTN)r   r   r   )r   r   r   r   r   r   r   historicalTicks  s    zEWrapper.historicalTicksc             C   s   |  t t  dS )z4returns historical tick data when whatToShow=BID_ASKN)r   r   r   )r   r   r   r   r   r   r   historicalTicksBidAsk  s    zEWrapper.historicalTicksBidAskc             C   s   |  t t  dS )z3returns historical tick data when whatToShow=TRADESN)r   r   r   )r   r   r   r   r   r   r   historicalTicksLast  s    zEWrapper.historicalTicksLast)r   r&   r~   r'   r*   tickAttribLastr   specialConditionsc	       	      C   s   |  t t  dS )z=returns tick-by-tick data for tickType = "Last" or "AllLast" N)r   r   r   )	r   r   r&   r~   r'   r*   r   r   r   r   r   r   tickByTickAllLast  s    zEWrapper.tickByTickAllLast)r   r~   bidPriceaskPricebidSizeaskSizetickAttribBidAskc             C   s   |  t t  dS )z2returns tick-by-tick data for tickType = "BidAsk" N)r   r   r   )r   r   r~   r   r   r   r   r   r   r   r   tickByTickBidAsk  s    zEWrapper.tickByTickBidAsk)r   r~   midPointc             C   s   |  t t  dS )z4returns tick-by-tick data for tickType = "MidPoint" N)r   r   r   )r   r   r~   r   r   r   r   tickByTickMidPoint  s    zEWrapper.tickByTickMidPoint)r   apiClientId
apiOrderIdc             C   s   |  t t  dS )zreturns orderBound notificationN)r   r   r   )r   r   r   r   r   r   r   
orderBound  s    zEWrapper.orderBound)rD   rE   rF   c             C   s   |  t t  dS )a7  This function is called to feed in completed orders.

        contract: Contract - The Contract class attributes describe the contract.
        order: Order - The Order class gives the details of the completed order.
        orderState: OrderState - The orderState class includes completed order status details.N)r   r   r   )r   rD   rE   rF   r   r   r   completedOrder  s    zEWrapper.completedOrderc             C   s   |  t t  dS )zBThis is called at the end of a given request for completed orders.N)r   r   r   )r   r   r   r   completedOrdersEnd  s    zEWrapper.completedOrdersEnd)r   r!   c             C   s   |  t t  dS )z*This is called at the end of a replace FA.N)r   r   r   )r   r   r!   r   r   r   replaceFAEnd  s    zEWrapper.replaceFAEnd)r   dataJsonc             C   s   |  t t  d S )N)r   r   r   )r   r   r   r   r   r   wshMetaData  s    zEWrapper.wshMetaDatac             C   s   |  t t  d S )N)r   r   r   )r   r   r   r   r   r   wshEventData  s    zEWrapper.wshEventData)r   startDateTimeendDateTimetimeZonesessionsc             C   s   |  t t  dS )zPreturns historical schedule for historical data request with whatToShow=SCHEDULEN)r   r   r   )r   r   r   r   r   r   r   r   r   historicalSchedule  s    zEWrapper.historicalSchedule)r   whiteBrandingIdc             C   s   |  t t  dS )zreturns user infoN)r   r   r   )r   r   r   r   r   r   userInfo  s    zEWrapper.userInfoN)r   )__name__
__module____qualname__r   r   TickerIdintstrr   r#   r$   r%   TickTypefloat
TickAttribr)   Decimalr+   r,   r.   r/   r7   OrderIdrC   r   r   r   rG   rH   rI   rN   rU   rW   rX   rY   r   rZ   r[   r\   r   r^   r_   rb   boolre   rj   rl   
FaDataTypero   BarDatarq   rt   rv   r|   r}   r   r   r   r   r   r	   r   rO   r   r   r   r   r   r   r   r   r   r   r   r   r   r   ZSetOfStringZ
SetOfFloatr   r   listr   ZListOfFamilyCoder   ZListOfContractDescriptionr   ZListOfDepthExchangesr   r   ZSmartComponentMapr   r   ZListOfNewsProvidersr   r   r   r   r   HistogramDatar   r   r   r   ZListOfPriceIncrementsr   r   r   ZListOfHistoricalTickr   ZListOfHistoricalTickBidAskr   ZListOfHistoricalTickLastr   TickAttribLastr   TickAttribBidAskr   r   r   r   r   r   r   r   ZListOfHistoricalSessionsr   r   r   r   r   r   r
   #   s   

		
	r
   N)__doc__ibapi.commonibapi.utilsibapi.contractr   r   r   ibapi.orderr   Zibapi.order_stater   ibapi.executionr   ibapi.ticktypeZibapi.commission_reportr	   r   	getLoggerr  r   r
   r   r   r   r   <module>   s   
