# Transaction Objects

# Create the connection

OpenSecTradeContext(filter_trdmarket=TrdMarket.HK, host='127.0.0.1', port=11111, is_encrypt=None, security_firm=SecurityFirm.FUTUSECURITIES)

OpenFutureTradeContext(host='127.0.0.1', port=11111, is_encrypt=None, security_firm=SecurityFirm.FUTUSECURITIES)

  • Description

    Create transaction object and initialize transaction connection.
    Select the corresponding transaction objects according to the transaction varieties.

    Examples Transaction Varieties
    OpenSecTradeContext Securities Market
    OpenFutureTradeContext Futures Market
    OpenHKTradeContext HK Market (Obsolete)
    OpenUSTradeContext US Market (Obsolete)
    OpenHKCCTradeContext HKCC Market (Obsolete)
    OpenCNTradeContext A-share Market (Obsolete)
  • Parameters

    Parameter Type Description
    filter_trdmarket TrdMarket Filter accounts according to the transaction market authority.
    host str The IP listened by OpenD.
    port int The port listened by OpenD.
    is_encrypt bool Whether to enable encryption.
    security_firm SecurityFirm Specified security firm
  • Example

from futu import *
trd_ctx = OpenSecTradeContext(filter_trdmarket=TrdMarket.HK, host='127.0.0.1', port=11111, is_encrypt=None, security_firm=SecurityFirm.FUTUSECURITIES)
trd_ctx.close() # After using the connection, remember to close it to prevent the number of connections from running out
1
2
3

# Close the connection

close()

  • Description

    Close the trading object. By default, the threads created inside the Futu API will prevent the process from exiting, and the process can exit normally only after all Contexts are closed. But through set_all_thread_daemon, all internal threads can be set as daemon threads. At this time, even if close of Context is not called, the process can exit normally.

  • Example

from futu import *
trd_ctx = OpenSecTradeContext(filter_trdmarket=TrdMarket.HK, host='127.0.0.1', port=11111)
trd_ctx.close() # After using the connection, remember to close it to prevent the number of connections from running out
1
2
3