webull_unofficial 1.1.1

The unofficial Rust interface for the WeBull API
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
#[derive(Debug, Clone)]
pub struct Endpoints {
    pub base_info_url: String,
    pub base_options_url: String,
    pub base_options_gw_url: String,
    pub base_paper_url: String,
    pub base_quote_url: String,
    pub base_securities_url: String,
    pub base_trade_url: String,
    pub base_user_url: String,
    pub base_userbroker_url: String,
    pub base_ustrade_url: String,
    pub base_paperfintech_url: String,
    pub base_fintech_gw_url: String,
    pub base_userfintech_url: String,
    pub base_new_trade_url: String,
    pub base_ustradebroker_url: String,
    pub base_securitiesfintech_url: String,
}

impl Default for Endpoints {
    fn default() -> Self {
        Self {
            base_info_url: "https://infoapi.webull.com/api".to_string(),
            base_options_url: "https://quoteapi.webullbroker.com/api".to_string(),
            base_options_gw_url: "https://quotes-gw.webullbroker.com/api".to_string(),
            base_paper_url: "https://act.webullbroker.com/webull-paper-center/api".to_string(),
            base_quote_url: "https://quoteapi.webullbroker.com/api".to_string(),
            base_securities_url: "https://securitiesapi.webullbroker.com/api".to_string(),
            base_trade_url: "https://tradeapi.webullbroker.com/api/trade".to_string(),
            base_user_url: "https://userapi.webull.com/api".to_string(),
            base_userbroker_url: "https://userapi.webullbroker.com/api".to_string(),
            base_ustrade_url: "https://ustrade.webullfinance.com/api".to_string(),
            base_paperfintech_url: "https://act.webullfintech.com/webull-paper-center/api"
                .to_string(),
            base_fintech_gw_url: "https://quotes-gw.webullfintech.com/api".to_string(),
            base_userfintech_url: "https://u1suser.webullfintech.com/api".to_string(),
            base_new_trade_url: "https://trade.webullfintech.com/api".to_string(),
            base_ustradebroker_url: "https://ustrade.webullbroker.com/api".to_string(),
            base_securitiesfintech_url: "https://securitiesapi.webullfintech.com/api".to_string(),
        }
    }
}

impl Endpoints {
    pub fn new() -> Self {
        Self::default()
    }

    pub fn account(&self, account_id: &str) -> String {
        format!("{}/v3/home/{}", self.base_trade_url, account_id)
    }

    pub fn account_id(&self) -> String {
        format!("{}/account/getSecAccountList/v5", self.base_trade_url)
    }

    pub fn account_activities(&self, account_id: &str) -> String {
        format!(
            "{}/trade/v2/funds/{}/activities",
            self.base_ustrade_url, account_id
        )
    }

    pub fn active_gainers_losers(
        &self,
        direction: &str,
        region_code: i32,
        rank_type: &str,
        num: i32,
    ) -> String {
        let url = match direction {
            "gainer" => "topGainers",
            "loser" => "dropGainers",
            _ => "topActive",
        };
        format!(
            "{}/wlas/ranking/{}?regionId={}&rankType={}&pageIndex=1&pageSize={}",
            self.base_fintech_gw_url, url, region_code, rank_type, num
        )
    }

    pub fn add_alert(&self) -> String {
        format!(
            "{}/user/warning/v2/manage/overlap",
            self.base_userbroker_url
        )
    }

    pub fn analysis(&self, stock: &str) -> String {
        format!(
            "{}/securities/ticker/v5/analysis/{}",
            self.base_securities_url, stock
        )
    }

    pub fn analysis_shortinterest(&self, stock: &str) -> String {
        format!(
            "{}/securities/stock/{}/shortInterest",
            self.base_securities_url, stock
        )
    }

    pub fn analysis_institutional_holding(&self, stock: &str) -> String {
        format!(
            "{}/securities/stock/v5/{}/institutionalHolding",
            self.base_securities_url, stock
        )
    }

    pub fn analysis_etf_holding(&self, stock: &str, has_num: i32, page_size: i32) -> String {
        format!(
            "{}/securities/stock/v5/{}/belongEtf?hasNum={}&pageSize={}",
            self.base_securities_url, stock, has_num, page_size
        )
    }

    pub fn analysis_capital_flow(&self, stock: &str, show_hist: bool) -> String {
        format!(
            "{}/wlas/capitalflow/ticker?tickerId={}&showHis={}",
            self.base_securities_url, stock, show_hist
        )
    }

    pub fn bars(&self, stock: &str, interval: &str, count: i32, timestamp: Option<i64>) -> String {
        let ts = timestamp
            .map(|t| format!("&timestamp={}", t))
            .unwrap_or_default();
        format!(
            "{}/quote/charts/query?tickerIds={}&type={}&count={}{}",
            self.base_fintech_gw_url, stock, interval, count, ts
        )
    }

    pub fn bars_crypto(&self, stock: &str) -> String {
        format!(
            "{}/crypto/charts/query?tickerIds={}",
            self.base_fintech_gw_url, stock
        )
    }

    pub fn cancel_order(&self, account_id: &str) -> String {
        format!(
            "{}/trade/order/{}/cancelStockOrder/",
            self.base_ustrade_url, account_id
        )
    }

    pub fn modify_otoco_orders(&self, account_id: &str) -> String {
        format!(
            "{}/trade/v2/corder/stock/modify/{}",
            self.base_ustrade_url, account_id
        )
    }

    pub fn cancel_otoco_orders(&self, account_id: &str, combo_id: &str) -> String {
        format!(
            "{}/trade/v2/corder/stock/cancel/{}/{}",
            self.base_ustrade_url, account_id, combo_id
        )
    }

    pub fn check_otoco_orders(&self, account_id: &str) -> String {
        format!(
            "{}/trade/v2/corder/stock/check/{}",
            self.base_ustrade_url, account_id
        )
    }

    pub fn place_otoco_orders(&self, account_id: &str) -> String {
        format!(
            "{}/trade/v2/corder/stock/place/{}",
            self.base_ustrade_url, account_id
        )
    }

    pub fn dividends(&self, account_id: &str) -> String {
        format!(
            "{}/v2/account/{}/dividends?direct=in",
            self.base_trade_url, account_id
        )
    }

    pub fn fundamentals(&self, stock: &str) -> String {
        format!(
            "{}/securities/financial/index/{}",
            self.base_securities_url, stock
        )
    }

    pub fn is_tradable(&self, stock: &str) -> String {
        format!(
            "{}/ticker/broker/permissionV2?tickerId={}",
            self.base_trade_url, stock
        )
    }

    pub fn list_alerts(&self) -> String {
        format!("{}/user/warning/v2/query/tickers", self.base_userbroker_url)
    }

    pub fn login(&self) -> String {
        format!("{}/user/v1/login/account/v2", self.base_userfintech_url)
    }

    pub fn get_mfa(&self) -> String {
        format!("{}/user/v1/verificationCode/send/v2", self.base_user_url)
    }

    pub fn check_mfa(&self) -> String {
        format!(
            "{}/user/v1/verificationCode/checkCode",
            self.base_userfintech_url
        )
    }

    pub fn get_security(
        &self,
        username: &str,
        account_type: i32,
        region_code: i32,
        event: &str,
        time: i64,
        url_type: i32,
    ) -> String {
        let url = if url_type == 1 {
            "getPrivacyQuestion"
        } else {
            "getSecurityQuestion"
        };
        format!(
            "{}/user/risk/{}?account={}&accountType={}&regionId={}&event={}&v={}",
            self.base_user_url, url, username, account_type, region_code, event, time
        )
    }

    pub fn next_security(
        &self,
        username: &str,
        account_type: i32,
        region_code: i32,
        event: &str,
        time: i64,
        url_type: i32,
    ) -> String {
        let url = if url_type == 1 {
            "nextPrivacyQuestion"
        } else {
            "nextSecurityQuestion"
        };
        format!(
            "{}/user/risk/{}?account={}&accountType={}&regionId={}&event={}&v={}",
            self.base_user_url, url, username, account_type, region_code, event, time
        )
    }

    pub fn check_security(&self) -> String {
        format!("{}/user/risk/checkAnswer", self.base_user_url)
    }

    pub fn logout(&self) -> String {
        format!("{}/user/v1/logout", self.base_userfintech_url)
    }

    pub fn news(&self, stock: &str, id: i64, items: i32) -> String {
        format!(
            "{}/information/news/tickerNews?tickerId={}&currentNewsId={}&pageSize={}",
            self.base_fintech_gw_url, stock, id, items
        )
    }

    pub fn option_quotes(&self) -> String {
        format!("{}/quote/option/query/list", self.base_options_gw_url)
    }

    pub fn options(&self, stock: &str) -> String {
        format!("{}/quote/option/{}/list", self.base_options_url, stock)
    }

    pub fn options_exp_date(&self, stock: &str) -> String {
        format!("{}/quote/option/{}/list", self.base_options_url, stock)
    }

    pub fn options_exp_date_new(&self) -> String {
        format!("{}/quote/option/strategy/list", self.base_fintech_gw_url)
    }

    pub fn options_bars(&self, derivative_id: &str) -> String {
        format!(
            "{}/quote/option/chart/query?derivativeId={}",
            self.base_options_gw_url, derivative_id
        )
    }

    pub fn orders(&self, account_id: &str, page_size: i32) -> String {
        format!(
            "{}/trade/v2/option/list?secAccountId={}&startTime=1970-01-01&dateType=ORDER&pageSize={}&status=",
            self.base_ustradebroker_url, account_id, page_size
        )
    }

    pub fn history(&self, account_id: &str) -> String {
        format!(
            "{}/trading/v1/webull/order/list?secAccountId={}",
            self.base_ustrade_url, account_id
        )
    }

    pub fn paper_orders(&self, paper_account_id: &str, page_size: i32) -> String {
        format!(
            "{}/paper/1/acc/{}/order?&startTime=1970-01-01&dateType=ORDER&pageSize={}&status=",
            self.base_paper_url, paper_account_id, page_size
        )
    }

    pub fn paper_account(&self, paper_account_id: &str) -> String {
        format!(
            "{}/paper/1/acc/{}",
            self.base_paperfintech_url, paper_account_id
        )
    }

    pub fn paper_account_id(&self) -> String {
        format!("{}/myaccounts/true", self.base_paperfintech_url)
    }

    pub fn paper_cancel_order(&self, paper_account_id: &str, order_id: &str) -> String {
        format!(
            "{}/paper/1/acc/{}/orderop/cancel/{}",
            self.base_paper_url, paper_account_id, order_id
        )
    }

    pub fn paper_modify_order(&self, paper_account_id: &str, order_id: &str) -> String {
        format!(
            "{}/paper/1/acc/{}/orderop/modify/{}",
            self.base_paper_url, paper_account_id, order_id
        )
    }

    pub fn paper_place_order(&self, paper_account_id: &str, stock: &str) -> String {
        format!(
            "{}/paper/1/acc/{}/orderop/place/{}",
            self.base_paper_url, paper_account_id, stock
        )
    }

    pub fn place_option_orders(&self, account_id: &str) -> String {
        format!(
            "{}/trade/v2/option/placeOrder/{}",
            self.base_ustrade_url, account_id
        )
    }

    pub fn place_orders(&self, account_id: &str) -> String {
        format!(
            "{}/trade/order/{}/placeStockOrder",
            self.base_ustrade_url, account_id
        )
    }

    pub fn modify_order(&self, account_id: &str, _order_id: &str) -> String {
        format!(
            "{}/trading/v1/webull/order/stockOrderModify?secAccountId={}",
            self.base_ustrade_url, account_id
        )
    }

    pub fn quotes(&self, stock: &str) -> String {
        format!(
            "{}/quotes/ticker/getTickerRealTime?tickerId={}&includeSecu=1&includeQuote=1",
            self.base_options_gw_url, stock
        )
    }

    pub fn rankings(&self) -> String {
        format!("{}/securities/market/v5/6/portal", self.base_securities_url)
    }

    pub fn refresh_login(&self, refresh_token: &str) -> String {
        format!(
            "{}/passport/refreshToken?refreshToken={}",
            self.base_user_url, refresh_token
        )
    }

    pub fn remove_alert(&self) -> String {
        format!(
            "{}/user/warning/v2/manage/overlap",
            self.base_userbroker_url
        )
    }

    pub fn replace_option_orders(&self, account_id: &str) -> String {
        format!(
            "{}/v2/option/replaceOrder/{}",
            self.base_trade_url, account_id
        )
    }

    pub fn stock_detail(&self, stock: &str) -> String {
        format!(
            "{}/stock/tickerRealTime/getQuote?tickerId={}&includeSecu=1&includeQuote=1&more=1",
            self.base_fintech_gw_url, stock
        )
    }

    pub fn stock_id(&self, stock: &str, region_code: i32) -> String {
        format!(
            "{}/search/pc/tickers?keyword={}&pageIndex=1&pageSize=20&regionId={}",
            self.base_options_gw_url, stock, region_code
        )
    }

    pub fn trade_token(&self) -> String {
        format!("{}/trading/v1/global/trade/login", self.base_new_trade_url)
    }

    pub fn user(&self) -> String {
        format!("{}/user", self.base_user_url)
    }

    pub fn screener(&self) -> String {
        format!("{}/wlas/screener/ng/query", self.base_userbroker_url)
    }

    pub fn social_posts(&self, topic: &str, num: i32) -> String {
        format!(
            "{}/social/feed/topic/{}/posts?size={}",
            self.base_user_url, topic, num
        )
    }

    pub fn social_home(&self, topic: &str, num: i32) -> String {
        format!(
            "{}/social/feed/topic/{}/home?size={}",
            self.base_user_url, topic, num
        )
    }

    pub fn portfolio_lists(&self) -> String {
        format!("{}/personal/portfolio/v2/check", self.base_options_gw_url)
    }

    pub fn press_releases(&self, stock: &str, type_ids: Option<&str>, num: i32) -> String {
        let type_ids_string = type_ids
            .map(|t| format!("&typeIds={}", t))
            .unwrap_or_default();
        format!(
            "{}/securities/announcement/{}/list?lastAnnouncementId=0&limit={}{}&options=2",
            self.base_securitiesfintech_url, stock, num, type_ids_string
        )
    }

    pub fn calendar_events(
        &self,
        event: &str,
        region_code: i32,
        start_date: &str,
        page: i32,
        num: i32,
    ) -> String {
        format!(
            "{}/bgw/explore/calendar/{}?regionId={}&pageIndex={}&pageSize={}&startDate={}",
            self.base_fintech_gw_url, event, region_code, page, num, start_date
        )
    }

    pub fn get_all_tickers(&self, region_code: i32, user_region_code: i32) -> String {
        format!(
            "{}/securities/market/v5/card/stockActivityPc.advanced/list?regionId={}&userRegionId={}&hasNum=0&pageSize=9999",
            self.base_securitiesfintech_url, region_code, user_region_code
        )
    }
}