0

在下面的代码中,我收到了来自盈透证券的 XAUUSD 头寸。有人能告诉我如何在另一个 python 文件中捕获变量 maypos 的更新值吗?

from ib.opt import Connection, message
from ib.ext.Contract import Contract
from ib.ext.Order import Order
import time
import os
import datetime
import random


def error_handler(msg):
    print ("Server Error: %s" % msg)
    return


def replies_handler(msg):
    print ("Server Response: %s, %s" % (msg.typeName, msg))
    return


def print_portfolio_position(msg):

    if msg.contract.m_symbol == "XAUUSD":
       mypos = msg.position
       print("Position:", msg.contract.m_symbol, msg.position, 
               msg.marketPrice, msg.contract.m_currency, msg.contract.m_secType)


if __name__ == "__main__":

    while 1:


        time.sleep(5)
        conn = Connection.create(port=4096, clientId=1)
        conn.connect()
        conn.register(error_handler, 'Error')
        conn.register(print_portfolio_position, 'UpdatePortfolio')
        conn.register(replies_handler, 'UpdateAccountValue')
        conn.reqAccountUpdates(1, '')
        time.sleep(2)
        conn.disconnect()
4

1 回答 1

1

问题:如何在另一个 python 文件中捕获变量 maypos 的更新值?

from another python file import maypos

value = maypos.updated value 
于 2017-04-30T14:20:58.950 回答