Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请问怎么用query_history这个函数来查询k线数据呢? 完全找不到教程。写代码一直报错。 #68

Open
Richardggm opened this issue Feb 25, 2025 · 0 comments

Comments

@Richardggm
Copy link

from vnpy_evo.event import EventEngine
from vnpy_evo.trader.engine import MainEngine
from vnpy_binance import BinanceSpotGateway, BinanceLinearGateway, BinanceInverseGateway
from vnpy.trader.object import HistoryRequest,Interval
from vnpy.trader.constant import Interval
from datetime import datetime, timedelta
from vnpy_evo.trader.constant import Exchange


# 初始化事件引擎和主引擎
event_engine = EventEngine()
main_engine = MainEngine(event_engine)

# 加载 Binance 网关
main_engine.add_gateway(BinanceSpotGateway)
main_engine.add_gateway(BinanceLinearGateway)
main_engine.add_gateway(BinanceInverseGateway)

gateway_names = main_engine.get_all_gateway_names()
print(gateway_names)

# 设置 Binance 的 REST 和 WebSocket 地址
main_engine.connect({
    "apiKey": "",
    "secretKey": "",
    "sessionCount": 3,
    "server": "REAL",  # 或 "TEST" 用于测试环境
    "proxy_host": "127.0.0.1",  # 代理服务器地址
    "proxy_port": 7890,     # 代理服务器端口
    "base_url": "https://api.binance.com" 
}, "BINANCE")


# 定义查询条件
history_req = HistoryRequest(
    symbol="BTC-USDT",       # 合约代码
    exchange=Exchange.BINANCE,   # 交易所代码
    start=datetime(2024, 12, 1),  # 开始时间
    end=datetime(2024, 12, 31),  # 结束时间
    interval=Interval.MINUTE      # 时间间隔
)

bardatalist = main_engine.query_history(history_req, gateway_name="BINANCE_SPOT")


print(bardatalist)。

报错:
发生异常: MissingSchema
Invalid URL '/api/v3/klines': No scheme supplied. Perhaps you meant https:///api/v3/klines?
File "D:\1-编程学习\3-自己做的任务\5.2vnpy国际版2025-2-25\test_vnpy2-重点.py", line 43, in
bardatalist = main_engine.query_history(history_req, gateway_name="BINANCE_SPOT")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
requests.exceptions.MissingSchema: Invalid URL '/api/v3/klines': No scheme supplied. Perhaps you meant https:///api/v3/klines?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant