-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathtypes.hpp
More file actions
3739 lines (3463 loc) · 75.8 KB
/
Copy pathtypes.hpp
File metadata and controls
3739 lines (3463 loc) · 75.8 KB
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
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#pragma once
#include "decimal.hpp"
#include <cstdint>
#include <map>
#include <optional>
#include <string>
#include <vector>
namespace longbridge {
struct Date
{
int32_t year;
uint8_t month;
uint8_t day;
};
struct Time
{
uint8_t hour;
uint8_t minute;
uint8_t second;
};
struct DateTime
{
Date date;
Time time;
};
/// Language identifer
enum class Language
{
/// zh-CN
ZH_CN,
/// zh-HK
ZH_HK,
/// en
EN,
};
/// Push candlestick mode
enum class PushCandlestickMode
{
/// Real-time
Realtime,
/// Confirmed
Confirmed,
};
/// Market
enum class Market
{
/// Unknown
Unknown,
/// US market
US,
/// HK market
HK,
/// CN market
CN,
/// SG market
SG,
/// Crypto market
Crypto,
};
namespace quote {
enum class TradeStatus;
/// Subscription flags
class SubFlags
{
private:
uint8_t value_;
public:
inline SubFlags(uint8_t value) { value_ = value; }
inline operator uint8_t() const { return value_; }
inline SubFlags operator|(const SubFlags& other) const
{
return SubFlags(value_ | other.value_);
}
inline SubFlags& operator|=(const SubFlags& other)
{
value_ |= other.value_;
return *this;
}
inline SubFlags operator&(const SubFlags& other) const
{
return SubFlags(value_ & other.value_);
}
inline SubFlags& operator&=(const SubFlags& other)
{
value_ &= other.value_;
return *this;
}
inline bool operator==(const SubFlags& other) const
{
return value_ == other.value_;
}
inline bool contains(const SubFlags& other) const
{
return (value_ & other.value_) > 0;
}
static SubFlags QUOTE();
static SubFlags DEPTH();
static SubFlags BROKER();
static SubFlags TRADE();
};
/// Derivative type
struct DerivativeType
{
uint8_t value;
bool has_option();
bool has_warrant();
};
/// Candlestick period
enum class Period
{
/// Unknown
Unknown,
/// One Minute
Min1,
/// Two Minutes
Min2,
/// Three Minutes
Min3,
/// Five Minutes
Min5,
/// Ten Minutes
Min10,
/// Fifteen Minutes
Min15,
/// Twenty Minutes
Min20,
/// Thirty Minutes
Min30,
/// Forty-Five Minutes
Min45,
/// One Hour
Min60,
/// Two Hours
Min120,
/// Three Hours
Min180,
/// Four Hours
Min240,
/// Daily
Day,
/// Weekly
Week,
/// Monthly
Month,
/// Quarterly
Quarter,
/// Yearly
Year,
};
/// Subscription
struct Subscription
{
/// Security code
std::string symbol;
/// Subscription flags
SubFlags sub_types;
/// Candlesticks
std::vector<Period> candlesticks;
};
/// Trade session
enum class TradeSession
{
/// Intraday
Intraday,
/// Pre-Market
Pre,
/// Post-Market
Post,
/// Overnight
Overnight,
};
/// Quote message
struct PushQuote
{
/// Security code
std::string symbol;
/// Latest price
Decimal last_done;
/// Open
Decimal open;
/// High
Decimal high;
/// Low
Decimal low;
/// Time of latest price
int64_t timestamp;
/// Volume
int64_t volume;
/// Turnover
Decimal turnover;
/// Security trading status
TradeStatus trade_status;
/// Trade session
TradeSession trade_session;
/// Increase volume between pushes
int64_t current_volume;
/// Increase turnover between pushes
Decimal urrent_turnover;
};
struct Depth
{
/// Position
int32_t position;
/// Price
std::optional<Decimal> price;
/// Volume
int64_t volume;
/// Number of orders
int64_t order_num;
};
/// Depth message
struct PushDepth
{
/// Security code
std::string symbol;
/// Ask depth
std::vector<Depth> asks;
/// Bid depth
std::vector<Depth> bids;
};
/// Brokers
struct Brokers
{
/// Position
int32_t position;
/// Broker IDs
std::vector<int32_t> broker_ids;
};
/// Brokers message
struct PushBrokers
{
/// Security code
std::string symbol;
/// Ask brokers
std::vector<Brokers> ask_brokers;
/// Bid brokers
std::vector<Brokers> bid_brokers;
};
/// Security board
enum class SecurityBoard
{
/// Unknown
Unknown,
/// US Main Board
USMain,
/// US Pink Board
USPink,
/// Dow Jones Industrial Average
USDJI,
/// Nasdsaq Index
USNSDQ,
/// US Industry Board
USSector,
/// US Option
USOption,
/// US Sepecial Option
USOptionS,
/// Hong Kong Equity Securities
HKEquity,
/// HK PreIPO Security
HKPreIPO,
/// HK Warrant
HKWarrant,
/// Hang Seng Index
HKHS,
/// HK Industry Board
HKSector,
/// SH Main Board(Connect)
SHMainConnect,
/// SH Main Board(Non Connect)
SHMainNonConnect,
/// SH Science and Technology Innovation Board
SHSTAR,
/// CN Index
CNIX,
/// CN Industry Board
CNSector,
/// SZ Main Board(Connect)
SZMainConnect,
/// SZ Main Board(Non Connect)
SZMainNonConnect,
/// SZ Gem Board(Connect)
SZGEMConnect,
/// SZ Gem Board(Non Connect)
SZGEMNonConnect,
/// SG Main Board
SGMain,
/// Singapore Straits Index
STI,
/// SG Industry Board
SGSector,
/// S&P 500 Index
SPXIndex,
/// CBOE Volatility Index
VIXIndex,
};
/// Security
struct Security
{
/// Security code
std::string symbol;
/// Security name (zh-CN)
std::string name_cn;
/// Security name (en)
std::string name_en;
/// Security name (zh-HK)
std::string name_hk;
};
/// The basic information of securities
struct SecurityStaticInfo
{
/// Security code
std::string symbol;
/// Security name (zh-CN)
std::string name_cn;
/// Security name (en)
std::string name_en;
/// Security name (zh-HK)
std::string name_hk;
/// Exchange which the security belongs to
std::string exchange;
/// Trading currency
std::string currency;
/// Lot size
int32_t lot_size;
/// Total shares
int64_t total_shares;
/// Circulating shares
int64_t circulating_shares;
/// HK shares (only HK stocks)
int64_t hk_shares;
/// Earnings per share
Decimal eps;
/// Earnings per share (TTM)
Decimal eps_ttm;
/// Net assets per share
Decimal bps;
/// Dividend (per share), **not** the dividend yield (ratio).
Decimal dividend_yield;
/// Types of supported derivatives
DerivativeType stock_derivatives;
/// Board
SecurityBoard board;
};
/// Trade status
enum class TradeStatus
{
/// Normal
Normal,
/// Suspension
Halted,
/// Delisted
Delisted,
/// Fuse
Fuse,
/// Papare List
PrepareList,
/// Code Moved
CodeMoved,
/// To Be Opened
ToBeOpened,
/// Split Stock Halts
SplitStockHalts,
/// Expired
Expired,
/// Warrant To BeListed
WarrantPrepareList,
/// Suspend
SuspendTrade,
};
/// Quote of US pre/post market
struct PrePostQuote
{
/// Latest price
Decimal last_done;
/// Time of latest price
int64_t timestamp;
/// Volume
int64_t volume;
/// Turnover
Decimal turnover;
/// High
Decimal high;
/// Low
Decimal low;
/// Close of the last trade session
Decimal prev_close;
};
/// Quote of securitity
struct SecurityQuote
{
/// Security code
std::string symbol;
/// Latest price
Decimal last_done;
/// Yesterday's close
Decimal prev_close;
/// Open
Decimal open;
/// High
Decimal high;
/// Low
Decimal low;
/// Time of latest price
int64_t timestamp;
/// Volume
int64_t volume;
/// Turnover
Decimal turnover;
/// Security trading status
TradeStatus trade_status;
/// Quote of US pre market
std::optional<PrePostQuote> pre_market_quote;
/// Quote of US post market
std::optional<PrePostQuote> post_market_quote;
/// Quote of US overnight market
std::optional<PrePostQuote> overnight_quote;
};
/// Option type
enum class OptionType
{
/// Unknown
Unknown,
/// American
American,
/// Europe
Europe,
};
/// Option direction
enum class OptionDirection
{
/// Unknown
Unknown,
/// Put
Put,
/// Call
Call,
};
/// Quote of option
struct OptionQuote
{ /// Security code
std::string symbol;
/// Latest price
Decimal last_done;
/// Yesterday's close
Decimal prev_close;
/// Open
Decimal open;
/// High
Decimal high;
/// Low
Decimal low;
/// Time of latest price
int64_t timestamp;
/// Volume
int64_t volume;
/// Turnover
Decimal turnover;
/// Security trading status
TradeStatus trade_status;
/// Implied volatility
Decimal implied_volatility;
/// Number of open positions
int64_t open_interest;
/// Exprity date
Date expiry_date;
/// Strike price
Decimal strike_price;
/// Contract multiplier
Decimal contract_multiplier;
/// Option type
OptionType contract_type;
/// Contract size
Decimal contract_size;
/// Option direction
OptionDirection direction;
/// Underlying security historical volatility of the option
Decimal historical_volatility;
/// Underlying security symbol of the option
std::string underlying_symbol;
};
/// Trade direction
enum class TradeDirection
{
/// Neutral
Neutral,
/// Down
Down,
/// Up
Up
};
/// Trade
struct Trade
{
Decimal price;
int64_t volume;
int64_t timestamp;
std::string trade_type;
TradeDirection direction;
TradeSession trade_session;
};
/// Trades message
struct PushTrades
{
/// Security code
std::string symbol;
/// Trades data
std::vector<Trade> trades;
};
/// Candlestick
struct Candlestick
{
/// Close price
Decimal close;
/// Open price
Decimal open;
/// Low price
Decimal low;
/// High price
Decimal high;
/// Volume
int64_t volume;
/// Turnover
Decimal turnover;
/// Timestamp
int64_t timestamp;
/// Trade session
TradeSession trade_session;
};
/// Candlestick updated message
struct PushCandlestick
{
/// Security code
std::string symbol;
/// Period type
Period period;
/// Candlestick
Candlestick candlestick;
/// Is confirmed
bool is_confirmed;
};
/// Warrant type
enum class WarrantType
{
/// Unknown
Unknown,
/// Call
Call,
/// Put
Put,
/// Bull
Bull,
/// Bear
Bear,
/// Inline
Inline
};
/// Quote of warrant
struct WarrantQuote
{ /// Security code
std::string symbol;
/// Latest price
Decimal last_done;
/// Yesterday's close
Decimal prev_close;
/// Open
Decimal open;
/// High
Decimal high;
/// Low
Decimal low;
/// Time of latest price
int64_t timestamp;
/// Volume
int64_t volume;
/// Turnover
Decimal turnover;
/// Security trading status
TradeStatus trade_status;
/// Implied volatility
Decimal implied_volatility;
/// Exprity date
Date expiry_date;
/// Last tradalbe date
Date last_trade_date;
/// Outstanding ratio
Decimal outstanding_ratio;
/// Outstanding quantity
int64_t outstanding_quantity;
/// Conversion ratio
Decimal conversion_ratio;
/// Warrant type
WarrantType category;
/// Strike price
Decimal strike_price;
/// Upper bound price
Decimal upper_strike_price;
/// Lower bound price
Decimal lower_strike_price;
/// Call price
Decimal call_price;
/// Underlying security symbol of the warrant
std::string underlying_symbol;
};
/// Security depth
struct SecurityDepth
{
/// Ask depth
std::vector<Depth> asks;
/// Bid depth
std::vector<Depth> bids;
};
/// Security brokers
struct SecurityBrokers
{
/// Ask brokers
std::vector<Brokers> ask_brokers;
/// Bid brokers
std::vector<Brokers> bid_brokers;
};
struct ParticipantInfo
{
/// Broker IDs
std::vector<int32_t> broker_ids;
/// Participant name (zh-CN)
std::string name_cn;
/// Participant name (en)
std::string name_en;
/// Participant name (zh-HK)
std::string name_hk;
};
/// Intraday line
struct IntradayLine
{
Decimal price;
int64_t timestamp;
int64_t volume;
Decimal turnover;
Decimal avg_price;
};
/// Adjust type
enum class AdjustType
{
NoAdjust,
ForwardAdjust
};
/// Strike price info
struct StrikePriceInfo
{
/// Strike price
Decimal price;
/// Security code of call option
std::string call_symbol;
/// Security code of put option
std::string put_symbol;
/// Is standard
bool standard;
};
/// Issuer info
struct IssuerInfo
{
/// Issuer ID
int32_t issuer_id;
/// Issuer name (zh-CN)
std::string name_cn;
/// Issuer name (en)
std::string name_en;
/// Issuer name (zh-HK)
std::string name_hk;
};
struct TradingSessionInfo
{
/// Being trading time
Time begin_time;
/// End trading time
Time end_time;
/// Trading session
TradeSession trade_session;
};
/// Market trading session
struct MarketTradingSession
{
/// Market
Market market;
/// Trading session
std::vector<TradingSessionInfo> trade_session;
};
/// Market trading days
struct MarketTradingDays
{
/// Trading days
std::vector<Date> trading_days;
/// Half trading days
std::vector<Date> half_trading_days;
};
/// Capital flow line
struct CapitalFlowLine
{
/// Inflow capital data
Decimal inflow;
/// Time
int64_t timestamp;
};
/// Capital distribution
struct CapitalDistribution
{
/// Large order
Decimal large;
/// Medium order
Decimal medium;
/// Small order
Decimal small;
};
/// Capital distribution response
struct CapitalDistributionResponse
{
/// Time
int64_t timestamp;
/// Inflow capital data
CapitalDistribution capital_in;
/// Outflow capital data
CapitalDistribution capital_out;
};
/// Watchlist security
struct WatchlistSecurity
{
/// Security symbol
std::string symbol;
/// Market
Market market;
/// Security name
std::string name;
/// Watched price
std::optional<Decimal> watched_price;
/// Watched time
int64_t watched_at;
};
/// Watchlist group
struct WatchlistGroup
{
/// Group id
int64_t id;
/// Group name
std::string name;
/// Securities
std::vector<WatchlistSecurity> securities;
};
/// Securities update mode
enum class SecuritiesUpdateMode
{
/// Add
Add,
/// Remove
Remove,
/// Replace
Replace,
};
/// An request for create watchlist group
struct CreateWatchlistGroup
{
/// Group name
std::string name;
/// Securities
std::vector<std::string> securities;
};
/// An request for update watchlist group
struct UpdateWatchlistGroup
{
/// Group id
int64_t id;
/// Group name
std::optional<std::string> name;
/// Securities
std::optional<std::vector<std::string>> securities;
/// Securities Update Mode
SecuritiesUpdateMode mode;
};
/// Real-time quote
struct RealtimeQuote
{
/// Security code
std::string symbol;
/// Latest price
Decimal last_done;
/// Open
Decimal open;
/// High
Decimal high;
/// Low
Decimal low;
/// Time of latest price
int64_t timestamp;
/// Volume
int64_t volume;
/// Turnover
Decimal turnover;
/// Security trading status
TradeStatus trade_status;
};
/// Calc index
enum class CalcIndex
{
/// Latest price
LastDone,
/// Change value
ChangeValue,
/// Change rate
ChangeRate,
/// Volume
Volume,
/// Turnover
Turnover,
/// Year-to-date change ratio
YtdChangeRate,
/// Turnover rate
TurnoverRate,
/// Total market value
TotalMarketValue,
/// Capital flow
CapitalFlow,
/// Amplitude
Amplitude,
/// Volume ratio
VolumeRatio,
/// PE (TTM)
PeTtmRatio,
/// PB
PbRatio,
/// Dividend ratio (TTM)
DividendRatioTtm,
/// Five days change ratio
FiveDayChangeRate,
/// Ten days change ratio
TenDayChangeRate,
/// Half year change ratio
HalfYearChangeRate,
/// Five minutes change ratio
FiveMinutesChangeRate,
/// Expiry date
ExpiryDate,
/// Strike price
StrikePrice,
/// Upper bound price
UpperStrikePrice,
/// Lower bound price
LowerStrikePrice,
/// Outstanding quantity
OutstandingQty,
/// Outstanding ratio
OutstandingRatio,
/// Premium
Premium,
/// In/out of the bound
ItmOtm,
/// Implied volatility
ImpliedVolatility,
/// Warrant delta
WarrantDelta,
/// Call price
CallPrice,
/// Price interval from the call price
ToCallPrice,
/// Effective leverage
EffectiveLeverage,
/// Leverage ratio
LeverageRatio,
/// Conversion ratio
ConversionRatio,
/// Breakeven point
BalancePoint,
/// Open interest
OpenInterest,
/// Delta
Delta,
/// Gamma
Gamma,
/// Theta
Theta,
/// Vega
Vega,
/// Rho
Rho,
};
/// Security calc index response
struct SecurityCalcIndex
{
/// Security code
std::string symbol;
/// Latest price
std::optional<Decimal> last_done;
/// Change value
std::optional<Decimal> change_value;
/// Change ratio
std::optional<Decimal> change_rate;
/// Volume
std::optional<int64_t> volume;
/// Turnover
std::optional<Decimal> turnover;
/// Year-to-date change ratio
std::optional<Decimal> ytd_change_rate;
/// Turnover rate
std::optional<Decimal> turnover_rate;
/// Total market value
std::optional<Decimal> total_market_value;
/// Capital flow
std::optional<Decimal> capital_flow;
/// Amplitude
std::optional<Decimal> amplitude;
/// Volume ratio
std::optional<Decimal> volume_ratio;
/// PE (TTM)
std::optional<Decimal> pe_ttm_ratio;
/// PB
std::optional<Decimal> pb_ratio;
/// Dividend ratio (TTM)
std::optional<Decimal> dividend_ratio_ttm;
/// Five days change ratio
std::optional<Decimal> five_day_change_rate;
/// Ten days change ratio
std::optional<Decimal> ten_day_change_rate;
/// Half year change ratio
std::optional<Decimal> half_year_change_rate;
/// Five minutes change ratio
std::optional<Decimal> five_minutes_change_rate;
/// Expiry date
std::optional<Date> expiry_date;
/// Strike price
std::optional<Decimal> strike_price;
/// Upper bound price
std::optional<Decimal> upper_strike_price;
/// Lower bound price
std::optional<Decimal> lower_strike_price;
/// Outstanding quantity