|
| 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 | + |
| 17 | +from webull.data.request.create_comment_request import CreateCommentRequest |
| 18 | +from webull.data.request.create_post_request import CreatePostRequest |
| 19 | +from webull.data.request.get_post_request import GetPostRequest |
| 20 | +from webull.data.request.list_hot_stocks_request import ListHotStocksRequest |
| 21 | +from webull.data.request.list_my_posts_request import ListMyPostsRequest |
| 22 | +from webull.data.request.list_posts_by_symbol_request import ListPostsBySymbolRequest |
| 23 | + |
| 24 | + |
| 25 | +class Community: |
| 26 | + """Community API operations.""" |
| 27 | + |
| 28 | + def __init__(self, api_client): |
| 29 | + self.client = api_client |
| 30 | + |
| 31 | + def create_post(self, text, symbol=None, category=None): |
| 32 | + """ |
| 33 | + Create a plain-text community post. |
| 34 | +
|
| 35 | + :param text: Post content. |
| 36 | + :param symbol: Optional ticker symbol. Provide it with category. |
| 37 | + :param category: Optional ticker market category. Provide it with symbol. |
| 38 | + :return: Response containing the created post identifier. |
| 39 | + """ |
| 40 | + request = CreatePostRequest() |
| 41 | + request.set_text(text) |
| 42 | + request.set_symbol(symbol) |
| 43 | + request.set_category(category) |
| 44 | + return self.client.get_response(request) |
| 45 | + |
| 46 | + def create_comment(self, post_id, text): |
| 47 | + """ |
| 48 | + Create a plain-text comment on an existing community post. |
| 49 | +
|
| 50 | + :param post_id: Parent post identifier. |
| 51 | + :param text: Comment content. |
| 52 | + :return: Response containing the created comment identifier. |
| 53 | + """ |
| 54 | + request = CreateCommentRequest() |
| 55 | + request.set_post_id(post_id) |
| 56 | + request.set_text(text) |
| 57 | + return self.client.get_response(request) |
| 58 | + |
| 59 | + def list_hot_stocks(self): |
| 60 | + """ |
| 61 | + List stocks ranked by community activity. |
| 62 | +
|
| 63 | + :return: Response containing hot stock ranking entries. |
| 64 | + """ |
| 65 | + request = ListHotStocksRequest() |
| 66 | + return self.client.get_response(request) |
| 67 | + |
| 68 | + def list_posts_by_symbol(self, symbol, category, keyword=None, pagination_key=None): |
| 69 | + """ |
| 70 | + List community posts associated with a symbol. |
| 71 | +
|
| 72 | + :param symbol: Stock symbol. |
| 73 | + :param category: Market category. |
| 74 | + :param keyword: Optional search keyword. |
| 75 | + :param pagination_key: Optional key from the previous response. |
| 76 | + :return: Paginated post list response. |
| 77 | + """ |
| 78 | + request = ListPostsBySymbolRequest() |
| 79 | + request.set_symbol(symbol) |
| 80 | + request.set_category(category) |
| 81 | + request.set_keyword(keyword) |
| 82 | + request.set_pagination_key(pagination_key) |
| 83 | + return self.client.get_response(request) |
| 84 | + |
| 85 | + def get_post(self, post_id): |
| 86 | + """ |
| 87 | + Get detailed information for a community post. |
| 88 | +
|
| 89 | + :param post_id: Post identifier. |
| 90 | + :return: Post detail response. |
| 91 | + """ |
| 92 | + request = GetPostRequest() |
| 93 | + request.set_post_id(post_id) |
| 94 | + return self.client.get_response(request) |
| 95 | + |
| 96 | + def list_my_posts(self, pagination_key=None): |
| 97 | + """ |
| 98 | + List posts created by the current user. |
| 99 | +
|
| 100 | + :param pagination_key: Optional key from the previous response. |
| 101 | + :return: Paginated post list response. |
| 102 | + """ |
| 103 | + request = ListMyPostsRequest() |
| 104 | + request.set_pagination_key(pagination_key) |
| 105 | + return self.client.get_response(request) |
0 commit comments