chrisli-kw / AutoTradingPlatform

A stock/futures auto trading framework using Shioaji API
Apache License 2.0
30 stars 9 forks source link

single positional indexer is out-of-bounds when init the futures #3

Closed q10242 closed 1 month ago

q10242 commented 4 months ago

i get these messages when i run the auto_trader

2024-04-24 11:07:15.391 | WARNING  | importlib._bootstrap:_call_with_frames_removed:241 - Optional: pip install shioaji[speed] for better performance.
WARNING:root:Run trader without holiday data.
WARNING:root:Cannot import test scripts from package.
2024-04-24 Wed 11:07:16.459|INFO: ————————————————————————————————————————————————————————————————————————————————————————————————————
2024-04-24 Wed 11:07:16.460|INFO: Current trader version is 1.12.23
FileNotFoundError: ./lib/ckey/sinopac_private.pem. Texts will not be decrypted.
2024-04-24 Wed 11:07:16.480|DEBUG: Starting new HTTPS connection (1): ws.api.cnyes.com:443
2024-04-24 Wed 11:07:16.529|DEBUG: https://ws.api.cnyes.com:443 "GET /ws/api/v1/charting/history?resolution=D&symbol=GI:DJI:INDEX&from=1713916800&to=1711324800 HTTP/1.1" 200 None
2024-04-24 Wed 11:07:16.531|WARNING: ==========put_call_ratio.csv不存在,無前一交易日的Put/Call Ratio==========
Response Code: 0 | Event Code: 0 | Info: host '210.59.255.161:80', hostname '210.59.255.161:80' IP 210.59.255.161:80 (host 1 of 1) (host connection attempt 1 of 1) (total connection attempt 1 of 1) | Event: Session up
2024-04-24 Wed 11:07:16.645|DEBUG: Attempting to acquire lock 5024424208 on /Users/kyjita/.shioaji/contracts-1.2.3.pkl.lock
2024-04-24 Wed 11:07:16.646|DEBUG: Lock 5024424208 acquired on /Users/kyjita/.shioaji/contracts-1.2.3.pkl.lock
2024-04-24 Wed 11:07:16.975|DEBUG: Attempting to release lock 5024424208 on /Users/kyjita/.shioaji/contracts-1.2.3.pkl.lock
2024-04-24 Wed 11:07:16.975|DEBUG: Lock 5024424208 released on /Users/kyjita/.shioaji/contracts-1.2.3.pkl.lock
2024-04-24 Wed 11:07:17.030|INFO: 【kyjita_1】log-in successful!
2024-04-24 Wed 11:07:17.030|INFO: Stock account ID: 0326483
2024-04-24 Wed 11:07:17.030|DEBUG: Set Futures_Code_List
2024-04-24 Wed 11:07:17.032|INFO: Futures account ID: 1262319
Empty DataFrame
Columns: [name, Time, Open, High, Low, Close, Volume, Amount]
Index: []
2024-04-24 Wed 11:07:17.042|INFO: 權益總值: xxxx
2024-04-24 Wed 11:07:17.042|INFO: Margin available = 50000 (limit: 50000)
2024-04-24 Wed 11:07:17.043|ERROR: Catch an exception:
Traceback (most recent call last):
  File "/Users/kyjita/codebase/AutoTradingPlatform/trader/tasker.py", line 97, in runAutoTrader
    se.run()
  File "/Users/kyjita/codebase/AutoTradingPlatform/trader/executor.py", line 1353, in run
    all_futures = self.init_futures()
  File "/Users/kyjita/codebase/AutoTradingPlatform/trader/executor.py", line 582, in init_futures
    self.margin_table = self.get_margin_table().原始保證金.to_dict()
  File "/Users/kyjita/codebase/AutoTradingPlatform/trader/executor.py", line 1023, in get_margin_table
    df.columns = list(df.iloc[0, :])
  File "/Users/kyjita/.pyenv/versions/3.10.0/lib/python3.10/site-packages/pandas/core/indexing.py", line 1147, in __getitem__
    return self._getitem_tuple(key)
  File "/Users/kyjita/.pyenv/versions/3.10.0/lib/python3.10/site-packages/pandas/core/indexing.py", line 1652, in _getitem_tuple
    tup = self._validate_tuple_indexer(tup)
  File "/Users/kyjita/.pyenv/versions/3.10.0/lib/python3.10/site-packages/pandas/core/indexing.py", line 940, in _validate_tuple_indexer
    self._validate_key(k, i)
  File "/Users/kyjita/.pyenv/versions/3.10.0/lib/python3.10/site-packages/pandas/core/indexing.py", line 1554, in _validate_key
    self._validate_integer(key, axis)
  File "/Users/kyjita/.pyenv/versions/3.10.0/lib/python3.10/site-packages/pandas/core/indexing.py", line 1647, in _validate_integer
    raise IndexError("single positional indexer is out-of-bounds")
IndexError: single positional indexer is out-of-bounds
2024-04-24 Wed 11:07:17.046|DEBUG: futures_to_monitor: {}
2024-04-24 Wed 11:07:18.064|INFO: 登出系統: True
2024-04-24 Wed 11:07:18.064|DEBUG: End of tasker

how do i solve these

chrisli-kw commented 1 month ago

It looks like you don't have the 'indexMarging.csv' in your ./lib I have solved this issue recently. You have to pull the latest version and execute the runCrawlIndexMargin() which is in the following file: https://github.com/chrisli-kw/AutoTradingPlatform/blob/e508f900cffb5632150ee185a9ffafd347e60cdc/trader/tasker.py#L227

Then there should be a indexMarging.csv file in your lib folder.

chrisli-kw commented 1 month ago

It looks like you don't have the 'indexMarging.csv' in your ./lib I have solved this issue recently. You have to pull the latest version and execute the runCrawlIndexMargin() which is in the following file: https://github.com/chrisli-kw/AutoTradingPlatform/blob/e508f900cffb5632150ee185a9ffafd347e60cdc/trader/tasker.py#L227

Then there should be a indexMarging.csv file in your lib folder.

You can also execute python run.py -TASK crawl_index_margin