# 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

    According to the transaction variaties, select a correct account, and create its transaction object.

    Transaction Objects Accounts
    OpenSecTradeContext Securities account
    OpenFutureTradeContext Futures account
  • 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 moomoo 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 moomoo 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 moomoo 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