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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
use chrono::NaiveDateTime;
use serde::{Deserialize, Serialize, Serializer};
use serde::ser::SerializeStruct;

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Accounts {
	pub accounts: Vec<Account>
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Account {
	pub account_alias: Option<String>,
	pub account_id: String,
	pub account_name: String,
	pub account_type: AccountType,
	pub balance: Balance,
	pub can_transfer_from: bool,
	pub can_transfer_to: bool,
	pub currency: String,
	pub preferred: bool,
	pub status: AccountStatus
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum AccountType {
	Cfd,
	Physical,
	Spreadbet
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Balance {
	pub available: f64,
	pub balance: f64,
	pub deposit: f64,
	pub profit_loss: f64
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum AccountStatus {
	Disabled,
	Enabled,
	SuspendedFromDealing
}

#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Preferences {
	pub trailing_stops_enabled: bool
}

#[derive(Debug, Default, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ActivityHistoryQuery {
	pub from: Option<NaiveDateTime>,
	pub to: Option<NaiveDateTime>,
	pub detailed: Option<bool>,
	pub deal_id: Option<String>,
	pub filter: Option<String>,
	pub page_size: Option<u32>
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ActivityHistory {
	pub activities: Vec<Activity>,
	pub metadata: ActivityMetadata
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Activity {
	pub channel: Channel,
	pub date: String,
	pub deal_id: String,
	pub description: String,
	pub details: Option<ActivityDetails>,
	pub epic: String,
	pub period: String,
	pub status: ActivityStatus,
	pub r#type: ActivityType
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum Channel {
	Dealer,
	Mobile,
	PublicFixApi,
	PublicWebApi,
	System,
	Web
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ActivityDetails {
	pub actions: Vec<ActivityAction>,
	pub currency: String,
	pub deal_reference: String,
	pub direction: Direction,
	pub good_till_date: String,
	pub guaranteed_stop: bool,
	pub level: f64,
	pub limit_distance: f64,
	pub limit_level: f64,
	pub market_name: String,
	pub size: f64,
	pub stop_distance: f64,
	pub stop_level: f64,
	pub trailing_step: f64,
	pub trailing_stop_distance: f64
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ActivityAction {
	pub action_type: ActivityActionType,
	pub affected_deal_id: String
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum ActivityActionType {
	LimitOrderAmended,
	LimitOrderDeleted,
	LimitOrderFilled,
	LimitOrderOpened,
	LimitOrderRolled,
	PositionClosed,
	PositionDeleted,
	PositionOpened,
	PositionPartiallyClosed,
	PositionRolled,
	StopLimitAmended,
	StopOrderAmended,
	StopOrderDeleted,
	StopOrderFilled,
	StopOrderOpened,
	StopOrderRolled,
	Unknown,
	WorkingOrderDeleted
}

#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum Direction {
	Buy,
	Sell
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum ActivityStatus {
	Accepted,
	Rejected,
	Unknown
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum ActivityType {
	EditStopAndLimit,
	Position,
	System,
	WorkingOrder
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ActivityMetadata {
	pub paging: ActivityPaging
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ActivityPaging {
	pub next: Option<String>,
	pub size: u32
}

#[derive(Debug, Default, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct TransactionHistoryQuery {
	pub r#type: Option<TransactionType>,
	pub from: Option<NaiveDateTime>,
	pub to: Option<NaiveDateTime>,
	pub max_span_seconds: Option<u64>,
	pub page_size: Option<u32>,
	pub page_number: Option<u32>
}

#[derive(Debug, Serialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum TransactionType {
	All,
	AllDeal,
	Deposit,
	Withdrawal
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TransactionHistory {
	pub metadata: TransactionMetadata,
	pub transactions: Vec<Transaction>
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TransactionMetadata {
	pub page_data: TransactionPaging,
	pub size: u32
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TransactionPaging {
	pub page_number: u32,
	pub page_size: u32,
	pub total_pages: u32
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Transaction {
	pub cash_transaction: bool,
	pub close_level: String,
	pub currency: String,
	pub date: String,
	pub date_utc: String,
	pub instrument_name: String,
	pub open_date_utc: String,
	pub open_level: String,
	pub period: String,
	pub profit_and_loss: String,
	pub reference: String,
	pub size: String,
	pub transaction_type: String
}

#[derive(Debug, Default)]
pub struct SentimentQuery {
    pub market_ids: Option<Vec<String>>,
}

impl Serialize for SentimentQuery {
    fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
        let mut state = serializer.serialize_struct("SentimentQuery", 1)?;

        match self.market_ids.as_ref() {
            Some(ids) => {
                state.serialize_field("marketIds", &ids.join(","))?;
            }
            None => {
                state.serialize_field("marketIds", &None::<()>)?;
            }
        }

        state.end()
    }
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Sentiments {
    pub client_sentiments: Vec<Sentiment>,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Sentiment {
    pub long_position_percentage: f64,
    pub market_id: String,
    pub short_position_percentage: f64,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct DealConfirmation {
	pub affected_deals: Vec<AffectedDeal>,
	pub date: String,
	pub deal_id: String,
	pub deal_reference: String,
	pub deal_status: DealStatus,
	pub direction: Direction,
	pub epic: String,
	pub expiry: String,
	pub guaranteed_stop: bool,
	pub level: f64,
	pub limit_distance: f64,
	pub limit_level: f64,
	pub profit: f64,
	pub profit_currency: String,
	pub reason: DealReason,
	pub size: f64,
	pub status: PositionStatus,
	pub stop_distance: f64,
	pub stop_level: f64,
	pub trailing_stop: bool
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct AffectedDeal {
	pub deal_id: String,
	pub status: AffectedDealStatus
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum AffectedDealStatus {
	Amended,
	Deleted,
	FullyClosed,
	Opened,
	PartiallyClosed
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum DealStatus {
	Accepted,
	Rejected
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum DealReason {
	AccountNotEnabledToTrading,
	AttachedOrderLevelError,
	AttachedOrderTrailingStopError,
	CannotChangeStopType,
	CannotRemoveStop,
	ClosingOnlyTradesAcceptedOnThisMarket,
	ClosingsOnlyAccount,
	ConflictingOrder,
	ContactSupportInstrumentError,
	CrSpacing,
	DuplicateOrderError,
	ExchangeManualOverride,
	ExpiryLessThanSprintMarketMinExpiry,
	FinanceRepeatDealing,
	ForceOpenOnSameMarketDifferentCurrency,
	GeneralError,
	GoodTillDateInThePast,
	InstrumentNotFound,
	InstrumentNotTradeableInThisCurrency,
	InsufficientFunds,
	LevelToleranceError,
	LimitOrderWrongSideOfMarket,
	ManualOrderTimeout,
	MarginError,
	MarketClosed,
	MarketClosedWithEdits,
	MarketClosing,
	MarketNotBorrowable,
	MarketOffline,
	MarketOrdersNotAllowedOnInstrument,
	MarketPhoneOnly,
	MarketRolled,
	MarketUnavailableToClient,
	MaxAutoSizeExceeded,
	MinimumOrderSizeError,
	MoveAwayOnlyLimit,
	MoveAwayOnlyStop,
	MoveAwayOnlyTriggerLevel,
	NcrPositionsOnCrAccount,
	OpposingDirectionOrdersNotAllowed,
	OpposingPositionsNotAllowed,
	OrderDeclined,
	OrderLocked,
	OrderNotFound,
	OrderSizeCannotBeFilled,
	OverNormalMarketSize,
	PartialyClosedPositionNotDeleted,
	PositionAlreadyExistsInOppositeDirection,
	PositionNotAvailableToCancel,
	PositionNotAvailableToClose,
	PositionNotFound,
	RejectCfdOrderOnSpreadbetAccount,
	RejectSpreadbetOrderOnCfdAccount,
	SizeIncrement,
	SprintMarketExpiryAfterMarketClose,
	StopOrLimitNotAllowed,
	StopRequiredError,
	StrikeLevelTolerance,
	Success,
	TrailingStopNotAllowed,
	Unknown,
	WrongSideOfMarket
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum PositionStatus {
	Amended,
	Closed,
	Deleted,
	Open,
	PartiallyClosed
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Positions {
	pub positions: Vec<Position>
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Position {
	pub market: MarketData,
	pub position: PositionData
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct MarketData {
	pub bid: Option<f64>,
	pub delay_time: f64,
	pub epic: String,
	pub exchange_id: Option<String>,
	pub expiry: String,
	pub high: Option<f64>,
	pub instrument_name: String,
	pub instrument_type: InstrumentType,
	pub lot_size: Option<f64>,
	pub low: Option<f64>,
	pub market_status: MarketStatus,
	pub net_change: f64,
	pub offer: Option<f64>,
	pub percentage_change: f64,
	pub scaling_factor: f64,
	pub streaming_prices_available: bool,
	pub update_time: String,
	#[serde(rename = "updateTimeUTC")]
	pub update_time_utc: String
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum InstrumentType {
	Binary,
	BungeeCapped,
	BungeeCommodities,
	BungeeCurrencies,
	BungeeIndices,
	Commodities,
	Currencies,
	Indices,
	KnockoutsCommodities,
	KnockoutsCurrencies,
	KnockoutsIndices,
	KnockoutsShares,
	OptCommodities,
	OptCurrencies,
	OptIndices,
	OptRates,
	OptShares,
	Rates,
	Sectors,
	Shares,
	SprintMarket,
	TestMarket,
	Unknown
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum MarketStatus {
	Closed,
	EditsOnly,
	Offline,
	OnAuction,
	OnAuctionNoEdits,
	Suspended,
	Tradeable
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct PositionData {
	pub contract_size: f64,
	pub controlled_risk: bool,
	pub created_date: String,
	pub created_date_utc: String,
	pub currency: String,
	pub deal_id: String,
	pub deal_reference: String,
	pub direction: Direction,
	pub level: f64,
	pub limit_level: f64,
	pub limited_risk_premium: f64,
	pub size: f64,
	pub stop_level: f64,
	pub trailing_step: f64,
	pub trailing_stop_distance: f64
}

#[derive(Debug, Default, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ClosePosition {
	pub deal_id: Option<String>,
	pub direction: Option<Direction>,
	pub epic: Option<String>,
	pub expiry: Option<String>,
	pub level: Option<f64>,
	pub order_type: Option<OrderType>,
	pub quote_id: Option<String>,
	pub size: Option<f64>,
	pub time_in_force: Option<TimeInForce>
}

#[derive(Debug, Serialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum OrderType {
	Limit,
	Market,
	Quote
}

#[derive(Debug, Serialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum TimeInForce {
	ExecuteAndEliminate,
	FillOrKill
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct DealRef {
	pub deal_reference: String
}

#[derive(Debug, Default, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct CreatePosition {
	pub currency_code: Option<String>,
	pub deal_reference: Option<String>,
	pub direction: Option<Direction>,
	pub epic: Option<String>,
	pub expiry: Option<String>,
	pub force_open: Option<bool>,
	pub guaranteed_stop: Option<bool>,
	pub level: Option<f64>,
	pub limit_distance: Option<f64>,
	pub limit_level: Option<f64>,
	pub order_type: Option<OrderType>,
	pub quote_id: Option<String>,
	pub size: Option<f64>,
	pub stop_distance: Option<f64>,
	pub stop_level: Option<f64>,
	pub time_in_force: Option<TimeInForce>,
	pub trailing_stop: Option<bool>,
	pub trailing_stop_increment: Option<f64>
}

#[derive(Debug, Default, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct UpdatePosition {
	pub guaranteed_stop: Option<bool>,
	pub limit_level: Option<f64>,
	pub stop_level: Option<f64>,
	pub trailing_stop: Option<bool>,
	pub trailing_stop_distance: Option<f64>,
	pub trailing_stop_increment: Option<f64>
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SprintMarketPositions {
	pub sprint_market_positions: Vec<SprintMarketPosition>
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SprintMarketPosition {
	pub created_date: String,
	pub currency: String,
	pub deal_id: String,
	pub description: String,
	pub direction: Direction,
	pub epic: String,
	pub expiry_time: String,
	pub instrument_name: String,
	pub market_status: MarketStatus,
	pub payout_amount: f64,
	pub size: f64,
	pub strike_level: f64
}

#[derive(Debug, Default, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct CreateSprintMarketPosition {
	pub deal_reference: Option<String>,
	pub direction: Option<Direction>,
	pub epic: Option<String>,
	pub expiry_period: Option<SprintMarketExpiryPeriod>,
	pub size: Option<f64>
}

#[derive(Debug, Serialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum SprintMarketExpiryPeriod {
	FiveMinutes,
	OneMinute,
	SixtyMinutes,
	TwentyMinutes,
	TwoMinutes
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct WorkingOrders {
	pub working_orders: Vec<WorkingOrder>
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct WorkingOrder {
	market_data: MarketData,
	working_order_data: WorkingOrderData
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct WorkingOrderData {
	pub created_date: String,
	#[serde(rename = "createdDateUTC")]
	pub created_date_utc: String,
	pub currency_code: String,
	pub deal_id: String,
	pub direction: Direction,
	pub dma: bool,
	pub epic: String,
	pub good_till_date: String,
	#[serde(rename = "goodTillDateISO")]
	pub good_till_date_iso: String,
	pub guaranteed_stop: bool,
	pub limit_distance: f64,
	pub limited_risk_premium: f64,
	pub order_level: f64,
	pub order_size: f64,
	pub order_type: WorkingOrderType,
	pub stop_distance: f64,
	pub time_in_force: WorkingOrderTimeInForce
}

#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum WorkingOrderType {
	Limit,
	Stop
}

#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum WorkingOrderTimeInForce {
	GoodTillCancelled,
	GoodTillDate
}

#[derive(Debug, Default, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct CreateWorkingOrder {
	pub currency_code: Option<String>,
	pub deal_reference: Option<String>,
	pub direction: Option<Direction>,
	pub epic: Option<String>,
	pub expiry: Option<String>,
	pub force_open: Option<bool>,
	pub good_till_date: Option<String>,
	pub guaranteed_stop: Option<bool>,
	pub level: Option<f64>,
	pub limit_distance: Option<f64>,
	pub limit_level: Option<f64>,
	pub size: Option<f64>,
	pub stop_distance: Option<f64>,
	pub stop_level: Option<f64>,
	pub time_in_force: Option<WorkingOrderTimeInForce>,
	pub r#type: Option<WorkingOrderType>
}

#[derive(Debug, Default, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct UpdateWorkingOrder {
	pub good_till_date: Option<String>,
	pub guaranteed_stop: Option<bool>,
	pub level: Option<f64>,
	pub limit_distance: Option<f64>,
	pub limit_level: Option<f64>,
	pub stop_distance: Option<f64>,
	pub stop_level: Option<f64>,
	pub time_in_force: Option<WorkingOrderTimeInForce>,
	pub r#type: Option<WorkingOrderType>
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct OkResponse {
	pub status: ResponseStatus
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum ResponseStatus {
	Success
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Application {
	pub allow_equities: bool,
	pub allow_quote_orders: bool,
	pub allowance_account_historical_data: f64,
	pub allowance_account_overall: f64,
	pub allowance_account_trading: f64,
	pub allowance_application_overall: f64,
	pub api_key: String,
	pub concurrent_subscriptions_limit: f64,
	pub created_date: String,
	pub name: String,
	pub status: ApplicationStatus
}

#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum ApplicationStatus {
	Disabled,
	Enabled,
	Revoked
}

#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct UpdateApplication {
	pub allowance_account_overall: f64,
	pub allowance_account_trading: f64,
	pub api_key: String,
	pub status: ApplicationStatus
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Session {
	pub account_id: String,
	pub client_id: String,
	pub currency: String,
	pub lightstreamer_endpoint: String,
	pub locale: String,
	pub timezone_offset: f64
}

#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct LoginReq {
	pub identifier: String,
	pub password: String,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct LoginRes {
	pub account_id: String,
	pub client_id: String,
	pub lightstreamer_endpoint: String,
	pub oauth_token: OauthToken,
	pub timezone_offset: f64
}

#[derive(Debug, Deserialize)]
pub struct OauthToken {
	pub access_token: String,
	pub expires_in: String,
	pub refresh_token: String,
	pub scope: String,
	pub token_type: String
}



#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct MarketCategory {
    pub markets: Option<Vec<MarketData3>>,
    pub nodes: Option<Vec<MarketNode>>,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct MarketData3 {
    pub bid: f64,
    pub delay_time: f64,
    pub epic: String,
    pub expiry: String,
    pub high: f64,
    pub instrument_name: String,
    pub instrument_type: InstrumentType,
    pub lot_size: f64,
    pub low: f64,
    pub market_status: MarketStatus,
    pub net_change: f64,
    pub offer: f64,
    pub otc_tradeable: bool,
    pub percentage_change: f64,
    pub scaling_factor: f64,
    pub streaming_prices_available: bool,
    pub update_time: String,
    pub update_time_utc: String,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct MarketNode {
    pub id: String,
    pub name: String,
}

#[derive(Debug, Default)]
pub struct MarketsQuery {
    pub epics: Vec<String>,
    pub filter: Option<MarketDetailsFilterType>,
}

impl Serialize for MarketsQuery {
    fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
        let mut state = serializer.serialize_struct("MarketsQuery", 2)?;

        state.serialize_field("epics", &self.epics.join(","))?;

        match self.filter.as_ref() {
            Some(filter) => {
                state.serialize_field("filter", filter)?;
            }
            None => {
                state.serialize_field("marketIds", &None::<()>)?;
            }
        }

        state.end()
    }
}

#[derive(Debug, Serialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum MarketDetailsFilterType {
    All,
    SnapshotOnly,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Markets {
    pub market_details: Vec<Market>,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Market {
    pub dealing_rules: DealingRules,
    pub instrument: InstrumentDetails,
    pub snapshot: MarketSnapshot,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct DealingRules {
    pub market_order_preference: MarketOrderPreference,
    pub max_stop_or_limit_distance: DealingRule,
    pub min_controlled_risk_stop_distance: DealingRule,
    pub min_deal_size: DealingRule,
    pub min_normal_stop_or_limit_distance: DealingRule,
    pub min_step_distance: DealingRule,
    pub trailing_stops_preference: TrailingStopsPreference,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum MarketOrderPreference {
    AvailableDefaultOff,
    AvailableDefaultOn,
    NotAvailable,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct DealingRule {
    pub unit: RuleUnit,
    pub value: f64,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum RuleUnit {
    Percentage,
    Points,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum TrailingStopsPreference {
    Available,
    NotAvailable,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct InstrumentDetails {
    pub chart_code: String,
    pub contract_size: String,
    pub controlled_risk_allowed: bool,
    pub country: Option<String>,
    pub currencies: Vec<Currency>,
    pub epic: String,
    pub expiry: String,
    pub expiry_details: Option<Expiry>,
    pub force_open_allowed: bool,
    pub limited_risk_premium: DealingRule,
    pub lot_size: f64,
    pub margin_deposit_bands: Vec<DepositBand>,
    pub margin_factor: f64,
    pub margin_factor_unit: RuleUnit,
    pub market_id: String,
    pub name: String,
    pub news_code: String,
    pub one_pip_means: String,
    pub opening_hours: Option<OpeningHours>,
    pub rollover_details: Option<Rollover>,
    pub slippage_factor: SlippageFactor,
    pub special_info: Vec<String>,
    pub sprint_markets_maximum_expiry_time: Option<f64>,
    pub sprint_markets_minimum_expiry_time: Option<f64>,
    pub stops_limits_allowed: bool,
    pub streaming_prices_available: bool,
    pub r#type: InstrumentType,
    pub unit: InstrumentUnit,
    pub value_of_one_pip: String,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Currency {
    pub base_exchange_rate: f64,
    pub code: String,
    pub exchange_rate: f64,
    pub is_default: bool,
    pub symbol: String,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Expiry {
    pub last_dealing_date: String,
    pub settlement_info: String,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct DepositBand {
    pub currency: String,
    pub margin: f64,
    pub max: Option<f64>,
    pub min: f64,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct OpeningHours {
    pub market_times: Vec<MarketTime>,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Rollover {
    pub last_rollover_time: String,
    pub rollover_info: String
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct MarketTime {
    pub close_time: String,
    pub open_time: String,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SlippageFactor {
    pub unit: String,
    pub value: f64,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum InstrumentUnit {
    Amount,
    Contracts,
    Shares,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct MarketSnapshot {
    pub bid: f64,
    pub binary_odds: Option<f64>,
    pub controlled_risk_extra_spread: f64,
    pub decimal_places_factor: f64,
    pub delay_time: f64,
    pub high: f64,
    pub low: f64,
    pub market_status: MarketStatus,
    pub net_change: f64,
    pub offer: f64,
    pub percentage_change: f64,
    pub scaling_factor: f64,
    pub update_time: String,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct MarketSearch {
    pub markets: Vec<MarketData>
}

#[derive(Debug, Default, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct PricesQuery {
    pub resolution: Option<Resolution>,
    pub from: Option<NaiveDateTime>,
    pub to: Option<NaiveDateTime>,
    pub max: Option<u32>,
    pub page_size: Option<u32>,
    pub page_number: Option<u32>
}

#[derive(Debug, Serialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum Resolution {
    Day,
    Hour,
    Hour2,
    Hour3,
    Hour4,
    Minute,
    Minute10,
    Minute15,
    Minute2,
    Minute3,
    Minute30,
    Minute5,
    Month,
    Second,
    Week
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Prices {
    pub instrument_type: InstrumentType,
    pub metadata: PriceMetadata,
    pub prices: Vec<Price>
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct PriceMetadata {
    pub page_data: PricePaging,
    pub size: f64,
    pub allowance: PriceAllowance
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct PricePaging {
    pub page_number: u32,
    pub page_size: u32,
    pub total_pages: u32
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct PriceAllowance {
    pub allowance_expiry: u32,
    pub remaining_allowance: u32,
    pub total_allowance: u32
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Price {
    pub close_price: AskBid,
    pub high_price: AskBid,
    pub last_traded_volume: f64,
    pub low_price: AskBid,
    pub open_price: AskBid,
    pub snapshot_time: String,
    #[serde(rename = "snapshotTimeUTC")]
    pub snapshot_time_utc: String
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct AskBid {
    pub ask: f64,
    pub bid: f64,
    pub last_traded: Option<f64>
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Watchlists {
	pub watchlists: Vec<Watchlist>
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Watchlist {
	pub default_system_watchlist: bool,
	pub deleteable: bool,
	pub editable: bool,
	pub id: String,
	pub name: String
}

#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct CreateWatchlist {
	pub epics: Vec<String>,
	pub name: String
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CreateWatchlistResult {
	pub status: CreateWatchlistStatus,
	pub watchlist_id: String
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum CreateWatchlistStatus {
	Success,
	SuccesNotAllInstrumentsAdded
}

#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct AddToWatchlist {
	pub epic: String
}