|
| 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 uuid |
| 16 | +from webull.core.client import ApiClient |
| 17 | +from webull.trade.trade_client import TradeClient |
| 18 | + |
| 19 | +optional_api_endpoint = "<api_endpoint>" |
| 20 | +your_app_key = "<your_app_key>" |
| 21 | +your_app_secret = "<your_app_secret>" |
| 22 | +region_id = "<region_id>" # hk or us |
| 23 | +account_id = "<your_account_id>" |
| 24 | +api_client = ApiClient(your_app_key, your_app_secret, region_id) |
| 25 | +api_client.add_endpoint(region_id, optional_api_endpoint) |
| 26 | + |
| 27 | + |
| 28 | +if __name__ == '__main__': |
| 29 | + trade_client = TradeClient(api_client) |
| 30 | + |
| 31 | + |
| 32 | + # simple order |
| 33 | + client_order_id = uuid.uuid4().hex |
| 34 | + print('client order id:', client_order_id) |
| 35 | + new_simple_orders = [ |
| 36 | + { |
| 37 | + "client_order_id": client_order_id, |
| 38 | + "symbol": "BULL", |
| 39 | + "instrument_type": "EQUITY", |
| 40 | + "market": "US", |
| 41 | + "order_type": "LIMIT", |
| 42 | + "limit_price": "26", |
| 43 | + "quantity": "1", |
| 44 | + "support_trading_session": "CORE", |
| 45 | + "side": "BUY", |
| 46 | + "time_in_force": "DAY", |
| 47 | + "entrust_type": "QTY" |
| 48 | + } |
| 49 | + ] |
| 50 | + new_hk_stock_simple_orders = [ |
| 51 | + { |
| 52 | + "client_order_id": client_order_id, |
| 53 | + "symbol": "00700", |
| 54 | + "instrument_type": "EQUITY", |
| 55 | + "market": "HK", |
| 56 | + "order_type": "ENHANCED_LIMIT", |
| 57 | + "limit_price": "612", |
| 58 | + "quantity": "100", |
| 59 | + "side": "BUY", |
| 60 | + "time_in_force": "DAY", |
| 61 | + "entrust_type": "QTY" |
| 62 | + } |
| 63 | + ] |
| 64 | + res = trade_client.order_v2.preview_order(account_id, new_simple_orders) |
| 65 | + if res.status_code == 200: |
| 66 | + print('preview order res:', res.json()) |
| 67 | + |
| 68 | + res = trade_client.order_v2.place_order(account_id, new_simple_orders) |
| 69 | + if res.status_code == 200: |
| 70 | + print('place order res:', res.json()) |
| 71 | + |
| 72 | + modify_simple_orders = [ |
| 73 | + { |
| 74 | + "client_order_id": client_order_id, |
| 75 | + "quantity": "2", |
| 76 | + "limit_price": "25" |
| 77 | + } |
| 78 | + ] |
| 79 | + res = trade_client.order_v2.replace_order(account_id, modify_simple_orders) |
| 80 | + if res.status_code == 200: |
| 81 | + print('replace order res:', res.json()) |
| 82 | + |
| 83 | + res = trade_client.order_v2.cancel_order(account_id, client_order_id) |
| 84 | + if res.status_code == 200: |
| 85 | + print('cancel order res:', res.json()) |
| 86 | + |
| 87 | + res = trade_client.order_v2.get_order_detail(account_id, client_order_id) |
| 88 | + if res.status_code == 200: |
| 89 | + print('order detail:', res.json()) |
0 commit comments