次のコードでは、Interactive Brokers から 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()