这是我在互联网上找到的用于扫描的代码,我不明白如何添加选项来查找此时停止的股票
https://interactivebrokers.github.io/tws-api/tick_types.html#halted
from ibapi.client import EClient
from ibapi.wrapper import EWrapper
from ibapi.scanner import ScannerSubscription
import time
import threading
class TradeApp(EWrapper, EClient):
def __init__(self):
EClient.__init__(self, self)
def scannerData(self, reqId, rank, contractDetails, distance, benchmark, projection, legsStr):
super().scannerData(reqId, rank, contractDetails, distance, benchmark, projection, legsStr)
print("ScannerDate. ReqId:", reqId, contractDetails.contract, rank)
def usStkScan(asset_type="STK",asset_loc="STK.US.MAJOR", scan_code="TOP_PERC_GAIN"):
scanSub = ScannerSubscription()
scanSub.numberOfRows = 50
scanSub.abovePrice = 10
scanSub.belowPrice = 200
scanSub.aboveVolume = 1000000
scanSub.instrument = asset_type
scanSub.locationCode = asset_loc
scanSub.scanCode = scan_code
return scanSub
USE_DELAYED_DATA = True
def websocket_con():
app.run()
app=TradeApp()
app.connect(host='127.0.0.1', port=7497, clientId=23)
con_thread = threading.Thread(target=websocket_con)
con_thread.start()
time.sleep(1)
app.reqScannerSubscription(1,usStkScan(),[],[])
app.run()
您可以使用scan_Code = "HALTED"
来实现这一点,替换当前值"TOP_PERC_GAIN"
。
Scanner是一种预定义的服务器端查询,您可以在其中订阅以获得定期更新,稍后可以在其中执行其他活动,如收集价格。