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

奇怪 我都跑起来是这样 #5

Open
yangmeishu opened this issue Feb 27, 2024 · 6 comments
Open

奇怪 我都跑起来是这样 #5

yangmeishu opened this issue Feb 27, 2024 · 6 comments

Comments

@yangmeishu
Copy link

` history_candle = self.market.get_history_candle(
instId='BTC-USDT',
start='2024-01-01 00:00:00',
end='2024-01-01 23:59:00',
bar='2H',
)

    eprint(history_candle)
    print('candle.shape=', history_candle['data'].shape)`

返回的是
{'code': 'CANDLE_START_ERROR', 'data': array([], shape=(0, 9), dtype=float64), 'msg': 'BTC-USDT[candle empty]'} candle.shape= (0, 9)

@pyted
Copy link
Owner

pyted commented Feb 28, 2024

这是成功的代码:

from okx.app.market import MarketSPOT
from okx.app.utils import eprint

if __name__ == '__main__':
    proxy_host = None
    marketSPOT = MarketSPOT(proxy_host=proxy_host)
    history_candle = marketSPOT.get_history_candle(
        instId='BTC-USDT',
        start='2024-01-01 00:00:00',
        end='2024-01-01 22:00:00',
        bar='2H',
    )
    eprint(history_candle)

输出结果:

{'code': '0',
'data': array([[1.70403840e+12, 4.24576000e+04, 4.27007000e+04, 4.24301000e+04,
4.26104000e+04, 3.78315832e+02, 1.61084931e+07, 1.61084931e+07,
1.00000000e+00],
[1.70404560e+12, 4.26105000e+04, 4.27200000e+04, 4.25333000e+04,
4.26121000e+04, 3.48587937e+02, 1.48615666e+07, 1.48615666e+07,
1.00000000e+00],
[1.70405280e+12, 4.26158000e+04, 4.26808000e+04, 4.25058000e+04,
4.25144000e+04, 3.62747155e+02, 1.54495793e+07, 1.54495793e+07,
1.00000000e+00],
[1.70406000e+12, 4.25145000e+04, 4.25911000e+04, 4.20660000e+04,
4.22830000e+04, 8.69770762e+02, 3.67719985e+07, 3.67719985e+07,
1.00000000e+00],
[1.70406720e+12, 4.22840000e+04, 4.27777000e+04, 4.22597000e+04,
4.26139000e+04, 5.88295584e+02, 2.50402635e+07, 2.50402635e+07,
1.00000000e+00],
[1.70407440e+12, 4.26139000e+04, 4.26438000e+04, 4.22090000e+04,
4.23357000e+04, 5.61299281e+02, 2.38199641e+07, 2.38199641e+07,
1.00000000e+00],
[1.70408160e+12, 4.23357000e+04, 4.24023000e+04, 4.21820000e+04,
4.22410000e+04, 5.28343756e+02, 2.23519674e+07, 2.23519674e+07,
1.00000000e+00],
[1.70408880e+12, 4.22396000e+04, 4.25047000e+04, 4.22064000e+04,
4.24952000e+04, 5.04646095e+02, 2.14063019e+07, 2.14063019e+07,
1.00000000e+00],
[1.70409600e+12, 4.24953000e+04, 4.26950000e+04, 4.24541000e+04,
4.26550000e+04, 4.98716704e+02, 2.12273604e+07, 2.12273604e+07,
1.00000000e+00],
[1.70410320e+12, 4.26535000e+04, 4.27602000e+04, 4.26020000e+04,
4.26895000e+04, 4.48015722e+02, 1.91258758e+07, 1.91258758e+07,
1.00000000e+00],
[1.70411040e+12, 4.26895000e+04, 4.27740000e+04, 4.26102000e+04,
4.27181000e+04, 3.68393192e+02, 1.57314187e+07, 1.57314187e+07,
1.00000000e+00],
[1.70411760e+12, 4.27182000e+04, 4.28480000e+04, 4.25743000e+04,
4.27828000e+04, 7.57382673e+02, 3.23363389e+07, 3.23363389e+07,
1.00000000e+00]]),
'msg': ''}

可能需要注意的:

  1. 如果你要获取某一个天的全部数据,最好使用get_history_candle_by_date函数;
  2. OKX库中,任何获取K线数据的函数都会做3个验证:数据起始时间严格等于start、终止时间严格等于end、数据的时间间隔严格等于bar,所以如果您获取的bar为2H,则不存在以23:59:00秒终止的数据,应该换成22:00:00,或者00:00:00

@yangmeishu
Copy link
Author

感谢作者的耐心回复。我使用的是 https://github.com/pyted/okx/blob/master/examples/2.4%20APP%20%E7%8E%B0%E8%B4%A7%E8%A1%8C%E6%83%85-%E5%8E%86%E5%8F%B2K%E7%BA%BF.ipynb
这个链接的例子
2H 是因为示例1m太多数据

我示例里,第一次是能够得到okx返回的数据,在包处理组合时候,出现的错误情况。
我的具体代码
image
image
image
image
image

另外作者你推荐的用 proxy_host okx_resender 能docker就好啦

@pyted
Copy link
Owner

pyted commented Mar 1, 2024

更新一下底层:

pip3 install candlelite --upgrade
pip3 install paux --upgrade
pip3 install pandas --upgrade
pip3 install numpy --upgrade

Pandas版本过低,有BUG

@yangmeishu
Copy link
Author

作者帮忙给个正常运行的 pip list 看看版本 谢谢
image
这个是我的

@pyted
Copy link
Owner

pyted commented Mar 3, 2024

paux 1.0.13
candlelite 1.0.17
pandas 2.0.3
numpy 1.24.4
okx 2.1.1
binance_interface 2.0.5
urllib3 1.26.12
requests 2.31.0

@pyted
Copy link
Owner

pyted commented Mar 3, 2024

注意urllib3的版本不要过高,Pandas不要低于2

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

2 participants