Sinotrade / Shioaji

Shioaji all new cross platform api for trading ( 跨平台證券交易API )
https://sinotrade.github.io/
157 stars 9 forks source link

Always get TimeoutError while invoking place_order in Google Cloud Functions #149

Open AugTH opened 1 year ago

AugTH commented 1 year ago

shioaji version: 1.1.11

Hi there, I found that I always get TimeoutError while invoking place_order() in Google Cloud Functions, after checking the logs, looks like it dues to the timezone in the cloud instance is UTC, which is 8 hours later than Taipei (CST timezone), I guess this is the reason of TimeoutError.

Since I didn't find an easy way to change the time zone of the cloud instance, guessing the simplest fix is to always convert the time with the CST timezone before sending the request, could you please take a look at this issue?

Your API is such a great work, it would be better if it works fine in the cloud :)

AugTH commented 1 year ago

BTW, it works fine in my local development laptop, I just simply deploy it to Google Cloud and the region of the cloud instance is asia-east1 which is supposed to be located in Changhua.

Pofatoezil commented 1 year ago

@AugThWu Hello, I've deployed the function in the asia-east1 region. However, I keep encountering a TimeoutError when I execute the logout function. Have you ever encountered a similar issue? Thank you.

Traceback (most recent call last): File "/layers/google.python.pip/pip/lib/python3.8/site-packages/flask/app.py", line 2190, in wsgi_app response = self.full_dispatch_request() File "/layers/google.python.pip/pip/lib/python3.8/site-packages/flask/app.py", line 1486, in full_dispatch_request rv = self.handle_user_exception(e) File "/layers/google.python.pip/pip/lib/python3.8/site-packages/flask/app.py", line 1484, in full_dispatch_request rv = self.dispatch_request() File "/layers/google.python.pip/pip/lib/python3.8/site-packages/flask/app.py", line 1469, in dispatch_request return self.ensure_sync(self.view_functions[rule.endpoint])(*view_args) File "/layers/google.python.pip/pip/lib/python3.8/site-packages/functions_framework/init.py", line 130, in view_func return function(request._get_current_object()) File "/layers/google.python.pip/pip/lib/python3.8/site-packages/functions_framework/init.py", line 110, in wrapper return func(args, **kwargs) File "/workspace/main.py", line 78, in hello_http api.logout() File "/layers/google.python.pip/pip/lib/python3.8/site-packages/shioaji/shioaji.py", line 343, in logout res = self._solace.logout() File "shioaji/backend/solace/api.pyx", line 573, in shioaji.backend.solace.api.SolaceAPI.logout File "/layers/google.python.pip/pip/lib/python3.8/site-packages/pysolace/init.py", line 278, in request raise TimeoutError(

AugTH commented 1 year ago

Hi @Pofatoezil

If I remember correctly, I got TimeoutError while invoking place_order thus hadn't invoked logout yet, so I have no idea if logout has the same problem. I could paste the call stack here as well if necessary :)

Pofatoezil commented 1 year ago

Hi @AugThWu My English isn't very good, so to make sure I use the right words, I'll reply to you in Chinese.

最近我為了將TradingView 交易策略的webhook alerts 串接到自動下單,所以研究將shioaji api放到google cloud function中 目前測試place_order,沒有遇到問題。 我使用python 3.8 requirement.txt:

functions-framework==3.*
requests
google-cloud-storage
shioaji==1.1.12
pydantic==1.10.11

但仍然有許多狀況: 1.有時候api.login()會出現Timeout error, 發生這個問題之後,一定要重新部署才會恢復正常

  1. api.logout()則是必定會出現Timeout error。 但我從本地端使用api.usage()觀察連線情況,連線是有登出的。 所以我用下面的方式來避免一直出現Timeour error
    try:
    api.logout()
    except TimeoutError:
    pass

希望以上資訊能幫助你排除狀況

cow5566bad commented 7 months ago

Any follow up on this issue? I am using shioaji==1.2.2 and I have TimeoutError occasionally when calling api.login function on GCP Cloud Functions. I have no issue on my laptop.

a0911802160 commented 7 months ago

Any follow up on this issue? I am using shioaji==1.2.2 and I have TimeoutError occasionally when calling api.login function on GCP Cloud Functions. I have no issue on my laptop.

I got the same issue, any update on it?

JinanWu commented 6 months ago

我的狀況是在 login 就出現這樣的問題。

jasonlin0189impv commented 5 months ago

想請問有解決方法了嗎?因為 gcp serveless 服務沒辦法修改系統時間,python 使用 pytz 改時區也沒辦法解決

Pofatoezil commented 5 months ago

@jasonlin0189impv 選擇台灣區域的Server (Asia east 1)來部屬,但不是每次都可以的