Skip to content

Commit 009980d

Browse files
committed
feat: Added trading calendar interfaces
1 parent 03aaade commit 009980d

File tree

16 files changed

+176
-13
lines changed

16 files changed

+176
-13
lines changed

webull-python-sdk-core/webullsdkcore/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "0.1.4"
1+
__version__ = "0.1.5"
22

33
import logging
44

webull-python-sdk-demos/setup.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
LONG_DESCRIPTION = fp.read()
1616

1717
requires = [
18-
"webull-python-sdk-mdata==0.1.4",
19-
"webull-python-sdk-trade==0.1.4"
18+
"webull-python-sdk-mdata==0.1.5",
19+
"webull-python-sdk-trade==0.1.5"
2020
]
2121

2222
setup_args = {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Copyright 2022 Webull
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import unittest
16+
17+
from webullsdkcore.client import ApiClient
18+
from webullsdkcore.exception.exceptions import ServerException
19+
from webullsdktrade.api import API
20+
from webullsdktrade.common.markets import Markets
21+
22+
optional_api_endpoint = "</optional_api_endpoint>"
23+
your_app_key = "</your_app_key>"
24+
your_app_secret = "</your_app_secret>"
25+
26+
# 'hk' or 'us'
27+
region_id = "<region_id>"
28+
api_client = ApiClient(your_app_key, your_app_secret, region_id)
29+
api_client.add_endpoint(region_id, optional_api_endpoint)
30+
31+
32+
class TestTradeCalendar(unittest.TestCase):
33+
34+
def test_trade_calendar(self):
35+
api = API(api_client)
36+
try:
37+
response = api.trade_calendar.get_trade_calendar(Markets.US.name, "2023-01-20", "2023-02-03")
38+
print(response.json())
39+
except ServerException as se:
40+
print(se)
41+
42+
try:
43+
response = api.trade_calendar.get_trade_calendar(Markets.HK.name, "2023-01-20", "2023-02-03")
44+
print(response.json())
45+
except ServerException as se:
46+
print(se)

webull-python-sdk-mdata/setup.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
LONG_DESCRIPTION = fp.read()
1616

1717
requires = [
18-
"webull-python-sdk-core==0.1.4",
19-
"webull-python-sdk-quotes-core==0.1.4"
18+
"webull-python-sdk-core==0.1.5",
19+
"webull-python-sdk-quotes-core==0.1.5"
2020
]
2121

2222
setup_args = {
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# coding=utf-8
22

3-
__version__ = '0.1.4'
3+
__version__ = '0.1.5'

webull-python-sdk-quotes-core/setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"grpcio==1.51.1",
2525
"grpcio-tools==1.51.1",
2626
"protobuf==4.21.12",
27-
"webull-python-sdk-core==0.1.4"
27+
"webull-python-sdk-core==0.1.5"
2828
]
2929

3030
setup_args = {
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.1.4"
1+
__version__ = "0.1.5"

webull-python-sdk-trade-events-core/setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"grpcio==1.51.1",
2424
"grpcio-tools==1.51.1",
2525
"protobuf==4.21.12",
26-
"webull-python-sdk-core==0.1.4"
26+
"webull-python-sdk-core==0.1.5"
2727
]
2828

2929
setup_args = {
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.1.4"
1+
__version__ = "0.1.5"

webull-python-sdk-trade/setup.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
LONG_DESCRIPTION = fp.read()
1616

1717
requires = [
18-
"webull-python-sdk-trade-events-core==0.1.4",
19-
"webull-python-sdk-core==0.1.4"
18+
"webull-python-sdk-trade-events-core==0.1.5",
19+
"webull-python-sdk-core==0.1.5"
2020
]
2121

2222
setup_args = {
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
__version__ = "0.1.4"
1+
__version__ = "0.1.5"
22

webull-python-sdk-trade/webullsdktrade/api.py

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from webullsdkmdata.quotes.instrument import Instrument
1818
from webullsdkmdata.quotes.market_data import MarketData
1919
from webullsdktrade.trade.trade_instrument import TradeInstrument
20+
from webullsdktrade.trade.trade_calendar import TradeCalendar
2021

2122

2223
class API:
@@ -26,3 +27,4 @@ def __init__(self, api_client):
2627
self.account = Account(api_client)
2728
self.order = OrderOperation(api_client)
2829
self.trade_instrument = TradeInstrument(api_client)
30+
self.trade_calendar = TradeCalendar(api_client)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright 2022 Webull
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from webullsdkcore.common.easy_enum import EasyEnum
16+
17+
18+
class Markets(EasyEnum):
19+
20+
# US market
21+
US = (1, "US")
22+
23+
# HK market
24+
HK = (2, "HK")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright 2022 Webull
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from webullsdkcore.common.easy_enum import EasyEnum
16+
17+
18+
class TradingDateType(EasyEnum):
19+
20+
# Full day
21+
FULL_DAY = (1, "FULL_DAY")
22+
23+
# Half day
24+
HALF_DAY = (2, "HALF_DAY")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Copyright 2022 Webull
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# coding=utf-8
16+
from webullsdkcore.request import ApiRequest
17+
18+
19+
class TradeCalendarRequest(ApiRequest):
20+
def __init__(self):
21+
ApiRequest.__init__(self, "/trade/calendar", version='v1', method="GET", query_params={})
22+
23+
def set_market(self, market):
24+
self.add_query_param("market", market)
25+
26+
def set_start(self, start):
27+
self.add_query_param("start", start)
28+
29+
def set_end(self, end):
30+
self.add_query_param("end", end)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Copyright 2022 Webull
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
from webullsdktrade.request.get_trade_calendar_request import TradeCalendarRequest
15+
16+
17+
class TradeCalendar:
18+
19+
def __init__(self, api_client):
20+
self.client = api_client
21+
22+
def get_trade_calendar(self, market, start, end):
23+
"""
24+
Get the trading calendar for the specified market.
25+
Trading days are obtained by excluding weekends and holidays, and the dates of temporary market closures are
26+
not excluded.
27+
28+
:param market: Markets, enumeration
29+
:param start: Start date
30+
:param end: End date
31+
"""
32+
trade_calendar_request = TradeCalendarRequest()
33+
trade_calendar_request.set_market(market)
34+
trade_calendar_request.set_start(start)
35+
trade_calendar_request.set_end(end)
36+
response = self.client.get_response(trade_calendar_request)
37+
return response

0 commit comments

Comments
 (0)