IBAPI:期货和重新建立“ 321错误验证请求”。-' bs' :原因 - 请输入本地符号或有效期。

发布于 2025-02-02 18:09:54 字数 2478 浏览 4 评论 0原文

问题:

> "321   Error validating request.-'bS' : cause - Please enter a local
> symbol or an expiry"

我对ReqhistoricalData没有运气,我找不到任何符号作为最低可行的工作产品,我只需要一个基线,我希望看到的是期货合约的OHLCV数据。

我尝试了什么: 在将GetMarketData用于同一未来合同对象时,我没有同样的问题。

各种符号并注释了合同对象旁边的错误。

#needs to be set to live data

from ibapi.client import EClient
from ibapi.wrapper import EWrapper
from ibapi.common import *
from ibapi.contract import *
import time

class TestApp(EWrapper, EClient):
    def __init__(self):
        EClient.__init__(self, self)
        
    def error(self, reqId, errorCode, errorString):
        print("Error: ", reqId, " ", errorCode, " ", errorString)
        
    def historicalData(self, reqId, bar):
        print("HistoricalData. ", reqId, " Date:", bar.date, "Open:", bar.open, "High:", bar.high, "Low:", bar.low, "Close:", bar.close, "Volume:", bar.volume, "Count:", bar.barCount, "WAP:", bar.average)
              
def main():
    app = TestApp()
    app.connect("127.0.0.1", 7497, 0)    
    
    #"200   No security definition has been found for the request"
    BTC_futures__contract = Contract()
    BTC_futures__contract.symbol = 'BRR'
    BTC_futures__contract.secType = 'FUT'
    BTC_futures__contract.exchange = 'CMECRYPTO'
    BTC_futures__contract.lastTradeDateOrContractMonth  = '202003' 
    
    "321   Error validating request.-'bS' : cause - Please enter a local symbol or an expiry"
    ES_contract = Contract()
    #ES_contract.symbol = "ES"
    ES_contract.symbol = "ESM2"
    #added
    
    ES_contract.LocalSymbol = 'ES IND'
    ES_contract.TradingClass = 'ES'
    
    ES_contract.secType = "FUT"
    ES_contract.exchange = "GLOBEX"
    ES_contract.currency = "USD"
    ES_contract.lasttradedateorcontractmonth = "202206"
    
    RTY_contract = Contract()
    #RTY_contract.symbol = "ES"
    RTY_contract.symbol = "RTY"
    #added
    
    #RTY_contract.LocalSymbol = 'ES IND'
    #RTY_contract.TradingClass = 'ES'
    
    RTY_contract.secType = "FUT"
    RTY_contract.exchange = "GLOBEX"
    RTY_contract.currency = "USD"
    RTY_contract.lasttradedateorcontractmonth = "202206"
    
    #app.reqHistoricalData(1, ES_contract, "", "1 D", "1 min", "MIDPOINT", 1, 1, False, [])
    #snapshot
    app.reqHistoricalData(1, RTY_contract, "", "1 D", "1 min", "MIDPOINT", 1, 1, False, [])
    
    app.run()
    
    time.sleep(2)
    app.disconnect()
    
if __name__ == "__main__":
    main()

Problem:

> "321   Error validating request.-'bS' : cause - Please enter a local
> symbol or an expiry"

I have no luck with reqHistoricalData, I can't find any symbol as a minimum viable working product, I just need a baseline and what I hope to see is OHLCV data for futures contracts.

What I've tried:
I don't have the same issue when using getMarketData for the same future contract object.

Various symbols and annotated their errors next to the contract object.

#needs to be set to live data

from ibapi.client import EClient
from ibapi.wrapper import EWrapper
from ibapi.common import *
from ibapi.contract import *
import time

class TestApp(EWrapper, EClient):
    def __init__(self):
        EClient.__init__(self, self)
        
    def error(self, reqId, errorCode, errorString):
        print("Error: ", reqId, " ", errorCode, " ", errorString)
        
    def historicalData(self, reqId, bar):
        print("HistoricalData. ", reqId, " Date:", bar.date, "Open:", bar.open, "High:", bar.high, "Low:", bar.low, "Close:", bar.close, "Volume:", bar.volume, "Count:", bar.barCount, "WAP:", bar.average)
              
def main():
    app = TestApp()
    app.connect("127.0.0.1", 7497, 0)    
    
    #"200   No security definition has been found for the request"
    BTC_futures__contract = Contract()
    BTC_futures__contract.symbol = 'BRR'
    BTC_futures__contract.secType = 'FUT'
    BTC_futures__contract.exchange = 'CMECRYPTO'
    BTC_futures__contract.lastTradeDateOrContractMonth  = '202003' 
    
    "321   Error validating request.-'bS' : cause - Please enter a local symbol or an expiry"
    ES_contract = Contract()
    #ES_contract.symbol = "ES"
    ES_contract.symbol = "ESM2"
    #added
    
    ES_contract.LocalSymbol = 'ES IND'
    ES_contract.TradingClass = 'ES'
    
    ES_contract.secType = "FUT"
    ES_contract.exchange = "GLOBEX"
    ES_contract.currency = "USD"
    ES_contract.lasttradedateorcontractmonth = "202206"
    
    RTY_contract = Contract()
    #RTY_contract.symbol = "ES"
    RTY_contract.symbol = "RTY"
    #added
    
    #RTY_contract.LocalSymbol = 'ES IND'
    #RTY_contract.TradingClass = 'ES'
    
    RTY_contract.secType = "FUT"
    RTY_contract.exchange = "GLOBEX"
    RTY_contract.currency = "USD"
    RTY_contract.lasttradedateorcontractmonth = "202206"
    
    #app.reqHistoricalData(1, ES_contract, "", "1 D", "1 min", "MIDPOINT", 1, 1, False, [])
    #snapshot
    app.reqHistoricalData(1, RTY_contract, "", "1 D", "1 min", "MIDPOINT", 1, 1, False, [])
    
    app.run()
    
    time.sleep(2)
    app.disconnect()
    
if __name__ == "__main__":
    main()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文