这是我用来请求市场数据的脚本.
我还没有订阅数据馈送,所以我会自动返回延迟的市场数据,但显然我必须启用它,但无法找到这样做的地方.
这是脚本和我得到的错误,我只需要接收延迟数据,所以我可以测试我的算法.
from ib.opt import ibConnection, message
from ib.ext.Contract import Contract
from time import sleep
def fundamentalData_handler(msg):
print(msg)
def error_handler(msg):
print(msg)
tws = ibConnection(port=7496, clientId=100)
tws.register(error_handler, message.Error)
tws.register(fundamentalData_handler, message.fundamentalData)
tws.connect()
c = Contract()
c.m_symbol = 'AAPL'
c.m_secType = 'STK'
c.m_exchange = "SMART"
c.m_currency = "USD"
print "on it"
tws.reqMktData(897,c,"",False)
sleep(50)
tws.disconnect()
Run Code Online (Sandbox Code Playgroud)
错误:
<error id=-1, errorCode=2104, errorMsg=Market data farm connection is OK:hfarm>
<error id=-1, errorCode=2104, errorMsg=Market data farm connection is OK:eufarm>
<error id=-1, errorCode=2104, errorMsg=Market data farm connection is OK:jfarm> …Run Code Online (Sandbox Code Playgroud) 我定义了一个不时切换我的代理设置的功能,问题是我希望它在没有人工干预的情况下循环运行。但是,当我在sudo中执行程序时,它会在第一次顺利运行时被调用,第二次它会要求我提供我的sudo密码。这是一些代码:
def ProxySetting(Proxy):
print "ProxyStetting(Proxy)"
call("networksetup -setwebproxy 'Wi-Fi' %s" "on" % Proxy, shell = True)
call("networksetup -setsecurewebproxy 'Wi-Fi' %s" "on" % Proxy, shell = True)
call("networksetup -setftpproxy 'Wi-Fi' %s" "on" %Proxy , shell=True)
Run Code Online (Sandbox Code Playgroud)
我可以使用线程,但是可以肯定有一种方法不会引起问题。我该如何对sudo密码进行硬编码,使其在功能开始时运行?