0

这是我在互联网上找到的用于扫描的代码,我不明白如何添加选项以在此时停止查找库存

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()
4

0 回答 0