-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathproposal_open_contract_response_result.dart
1770 lines (1531 loc) · 54.7 KB
/
proposal_open_contract_response_result.dart
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
// ignore_for_file: prefer_single_quotes, unnecessary_import, unused_import
import 'package:equatable/equatable.dart';
import 'package:flutter_deriv_api/api/exceptions/exceptions.dart';
import 'package:flutter_deriv_api/api/models/base_exception_model.dart';
import 'package:flutter_deriv_api/api/models/enums.dart';
import 'package:flutter_deriv_api/api/response/cancel_response_result.dart';
import 'package:flutter_deriv_api/api/response/forget_all_response_result.dart';
import 'package:flutter_deriv_api/api/response/forget_response_result.dart';
import 'package:flutter_deriv_api/api/response/sell_response_result.dart';
import 'package:flutter_deriv_api/basic_api/generated/cancel_send.dart';
import 'package:flutter_deriv_api/basic_api/generated/forget_all_receive.dart';
import 'package:flutter_deriv_api/basic_api/generated/forget_receive.dart';
import 'package:flutter_deriv_api/basic_api/generated/proposal_open_contract_receive.dart';
import 'package:flutter_deriv_api/basic_api/generated/proposal_open_contract_send.dart';
import 'package:flutter_deriv_api/basic_api/generated/sell_send.dart';
import 'package:flutter_deriv_api/basic_api/response.dart';
import 'package:flutter_deriv_api/helpers/helpers.dart';
import 'package:flutter_deriv_api/services/connection/api_manager/base_api.dart';
import 'package:flutter_deriv_api/services/connection/call_manager/base_call_manager.dart';
import 'package:deriv_dependency_injector/dependency_injector.dart';
/// Proposal open contract response model class.
abstract class ProposalOpenContractResponseModel {
/// Initializes Proposal open contract response model class .
const ProposalOpenContractResponseModel({
this.proposalOpenContract,
this.subscription,
});
/// Latest price and other details for an open contract
final ProposalOpenContract? proposalOpenContract;
/// For subscription requests only.
final Subscription? subscription;
}
/// Proposal open contract response class.
class ProposalOpenContractResponse extends ProposalOpenContractResponseModel {
/// Initializes Proposal open contract response class.
const ProposalOpenContractResponse({
super.proposalOpenContract,
super.subscription,
});
/// Creates an instance from JSON.
factory ProposalOpenContractResponse.fromJson(
dynamic proposalOpenContractJson,
dynamic subscriptionJson,
) =>
ProposalOpenContractResponse(
proposalOpenContract: proposalOpenContractJson == null
? null
: ProposalOpenContract.fromJson(proposalOpenContractJson),
subscription: subscriptionJson == null
? null
: Subscription.fromJson(subscriptionJson),
);
/// Converts an instance to JSON.
Map<String, dynamic> toJson() {
final Map<String, dynamic> resultMap = <String, dynamic>{};
if (proposalOpenContract != null) {
resultMap['proposal_open_contract'] = proposalOpenContract!.toJson();
}
if (subscription != null) {
resultMap['subscription'] = subscription!.toJson();
}
return resultMap;
}
static final BaseAPI _api = Injector()<BaseAPI>();
/// Gets the current spot of the the bought contract specified in [ProposalOpenContractRequest]
///
/// Throws a [BaseAPIException] if API response contains any error
static Future<ProposalOpenContractResponse> fetchContractState(
ProposalOpenContractRequest request,
) async {
final ProposalOpenContractReceive response = await _api.call(
request: request,
);
checkException(
response: response,
exceptionCreator: ({BaseExceptionModel? baseExceptionModel}) =>
BaseAPIException(baseExceptionModel: baseExceptionModel),
);
return ProposalOpenContractResponse.fromJson(
response.proposalOpenContract, response.subscription);
}
/// Subscribes to the bought contract state specified in [ProposalOpenContractRequest]
///
/// Throws a [BaseAPIException] if API response contains an error
static Stream<ProposalOpenContractResponse?> subscribeContractState(
ProposalOpenContractRequest request, {
RequestCompareFunction? comparePredicate,
}) =>
_api
.subscribe(request: request, comparePredicate: comparePredicate)!
.map<ProposalOpenContractResponse?>(
(Response response) {
checkException(
response: response,
exceptionCreator: ({BaseExceptionModel? baseExceptionModel}) =>
BaseAPIException(baseExceptionModel: baseExceptionModel),
);
return response is ProposalOpenContractReceive
? ProposalOpenContractResponse.fromJson(
response.proposalOpenContract,
response.subscription,
)
: null;
},
);
/// Unsubscribes from open contract subscription.
///
/// Throws a [BaseAPIException] if API response contains an error
Future<ForgetResponse?> unsubscribeOpenContract() async {
if (subscription == null) {
return null;
}
final ForgetReceive response =
await _api.unsubscribe(subscriptionId: subscription!.id);
checkException(
response: response,
exceptionCreator: ({BaseExceptionModel? baseExceptionModel}) =>
BaseAPIException(baseExceptionModel: baseExceptionModel),
);
return ForgetResponse.fromJson(response.forget);
}
/// Unsubscribes all open contract subscriptions.
///
/// Throws a [BaseAPIException] if API response contains an error
static Future<ForgetAllResponse> unsubscribeAllOpenContract() async {
final ForgetAllReceive response = await _api.unsubscribeAll(
method: ForgetStreamType.proposalOpenContract,
);
checkException(
response: response,
exceptionCreator: ({BaseExceptionModel? baseExceptionModel}) =>
BaseAPIException(baseExceptionModel: baseExceptionModel),
);
return ForgetAllResponse.fromJson(response.forgetAll);
}
/// Sells this contract.
///
/// [price] is the Minimum price at which to sell the contract,
/// Default be 0 for 'sell at market'.
/// Throws a [BaseAPIException] if API response contains an error
static Future<SellResponse> sell(
{required int contractId, double price = 0, String? loginId}) =>
SellResponse.sellContract(SellRequest(
sell: contractId,
price: price,
loginid: loginId,
));
/// Cancels this contract
///
/// Throws a [BaseAPIException] if API response contains an error
static Future<CancelResponse> cancel(int contractId, {String? loginId}) =>
CancelResponse.cancelContract(CancelRequest(
cancel: contractId,
loginid: loginId,
));
/// Creates a copy of instance with given parameters.
ProposalOpenContractResponse copyWith({
ProposalOpenContract? proposalOpenContract,
Subscription? subscription,
}) =>
ProposalOpenContractResponse(
proposalOpenContract: proposalOpenContract ?? this.proposalOpenContract,
subscription: subscription ?? this.subscription,
);
}
/// StatusEnum mapper.
final Map<String, StatusEnum> statusEnumMapper = <String, StatusEnum>{
"open": StatusEnum.open,
"sold": StatusEnum.sold,
"won": StatusEnum.won,
"lost": StatusEnum.lost,
"cancelled": StatusEnum.cancelled,
"null": StatusEnum._null,
};
/// Status Enum.
enum StatusEnum {
/// open.
open,
/// sold.
sold,
/// won.
won,
/// lost.
lost,
/// cancelled.
cancelled,
/// null.
_null,
}
/// Proposal open contract model class.
abstract class ProposalOpenContractModel {
/// Initializes Proposal open contract model class .
const ProposalOpenContractModel({
this.accountId,
this.auditDetails,
this.barrier,
this.barrierCount,
this.barrierSpotDistance,
this.bidPrice,
this.buyPrice,
this.cancellation,
this.commision,
this.commission,
this.contractId,
this.contractType,
this.currency,
this.currentSpot,
this.currentSpotDisplayValue,
this.currentSpotHighBarrier,
this.currentSpotLowBarrier,
this.currentSpotTime,
this.dateExpiry,
this.dateSettlement,
this.dateStart,
this.displayName,
this.displayNumberOfContracts,
this.displayValue,
this.entrySpot,
this.entrySpotDisplayValue,
this.entryTick,
this.entryTickDisplayValue,
this.entryTickTime,
this.exitTick,
this.exitTickDisplayValue,
this.exitTickTime,
this.expiryTime,
this.growthRate,
this.highBarrier,
this.id,
this.isExpired,
this.isForwardStarting,
this.isIntraday,
this.isPathDependent,
this.isSettleable,
this.isSold,
this.isValidToCancel,
this.isValidToSell,
this.limitOrder,
this.longcode,
this.lowBarrier,
this.multiplier,
this.numberOfContracts,
this.payout,
this.profit,
this.profitPercentage,
this.purchaseTime,
this.resetBarrier,
this.resetTime,
this.selectedSpot,
this.selectedTick,
this.sellPrice,
this.sellSpot,
this.sellSpotDisplayValue,
this.sellSpotTime,
this.sellTime,
this.shortcode,
this.status,
this.tickCount,
this.tickPassed,
this.tickStream,
this.transactionIds,
this.underlying,
this.validationError,
this.validationErrorCode,
});
/// Account Id
final double? accountId;
/// Tick details around contract start and end time.
final AuditDetails? auditDetails;
/// Barrier of the contract (if any).
final String? barrier;
/// The number of barriers a contract has.
final double? barrierCount;
/// [Only for accumulator] Absolute difference between high/low barrier and spot
final String? barrierSpotDistance;
/// Price at which the contract could be sold back to the company.
final double? bidPrice;
/// Price at which contract was purchased
final double? buyPrice;
/// Contains information about contract cancellation option.
final Cancellation? cancellation;
/// Commission in payout currency amount.
final double? commision;
/// Commission in payout currency amount.
final double? commission;
/// The internal contract identifier
final int? contractId;
/// Contract type.
final String? contractType;
/// The currency code of the contract.
final String? currency;
/// Spot value if we have license to stream this symbol.
final double? currentSpot;
/// Spot value with the correct precision if we have license to stream this symbol.
final String? currentSpotDisplayValue;
/// [Applicable for accumulator] High barrier based on current spot.
final String? currentSpotHighBarrier;
/// [Applicable for accumulator] Low barrier based on current spot.
final String? currentSpotLowBarrier;
/// The corresponding time of the current spot.
final DateTime? currentSpotTime;
/// Expiry date (epoch) of the Contract. Please note that it is not applicable for tick trade contracts.
final DateTime? dateExpiry;
/// Settlement date (epoch) of the contract.
final DateTime? dateSettlement;
/// Start date (epoch) of the contract.
final DateTime? dateStart;
/// Display name of underlying
final String? displayName;
/// [Only for vanilla or turbos options] The implied number of contracts
final String? displayNumberOfContracts;
/// The `bid_price` with the correct precision
final String? displayValue;
/// Same as `entry_tick`. For backwards compatibility.
final double? entrySpot;
/// Same as `entry_tick_display_value`. For backwards compatibility.
final String? entrySpotDisplayValue;
/// This is the entry spot of the contract. For contracts starting immediately it is the next tick after the start time. For forward-starting contracts it is the spot at the start time.
final double? entryTick;
/// This is the entry spot with the correct precision of the contract. For contracts starting immediately it is the next tick after the start time. For forward-starting contracts it is the spot at the start time.
final String? entryTickDisplayValue;
/// This is the epoch time of the entry tick.
final DateTime? entryTickTime;
/// Exit tick can refer to the latest tick at the end time, the tick that fulfils the contract's winning or losing condition for path dependent contracts (Touch/No Touch and Stays Between/Goes Outside) or the tick at which the contract is sold before expiry.
final double? exitTick;
/// Exit tick can refer to the latest tick at the end time, the tick that fulfils the contract's winning or losing condition for path dependent contracts (Touch/No Touch and Stays Between/Goes Outside) or the tick at which the contract is sold before expiry.
final String? exitTickDisplayValue;
/// This is the epoch time of the exit tick. Note that since certain instruments don't tick every second, the exit tick time may be a few seconds before the end time.
final DateTime? exitTickTime;
/// This is the expiry time.
final DateTime? expiryTime;
/// [Only for accumulator] Growth rate of an accumulator contract.
final double? growthRate;
/// High barrier of the contract (if any).
final String? highBarrier;
/// A per-connection unique identifier. Can be passed to the `forget` API call to unsubscribe.
final String? id;
/// Whether the contract is expired or not.
final bool? isExpired;
/// Whether the contract is forward-starting or not.
final bool? isForwardStarting;
/// Whether the contract is an intraday contract.
final bool? isIntraday;
/// Whether the contract expiry price will depend on the path of the market (e.g. One Touch contract).
final bool? isPathDependent;
/// Whether the contract is settleable or not.
final bool? isSettleable;
/// Whether the contract is sold or not.
final bool? isSold;
/// Whether the contract can be cancelled.
final bool? isValidToCancel;
/// Whether the contract can be sold back to the company.
final bool? isValidToSell;
/// Orders are applicable to `MULTUP` and `MULTDOWN` contracts only.
final LimitOrder? limitOrder;
/// Text description of the contract purchased, Example: Win payout if Volatility 100 Index is strictly higher than entry spot at 10 minutes after contract start time.
final String? longcode;
/// Low barrier of the contract (if any).
final String? lowBarrier;
/// [Only for lookback trades] Multiplier applies when calculating the final payoff for each type of lookback. e.g. (Exit spot - Lowest historical price) * multiplier = Payout
final double? multiplier;
/// [Only for vanilla or turbos options] The implied number of contracts
final double? numberOfContracts;
/// Payout value of the contract.
final double? payout;
/// The latest bid price minus buy price.
final double? profit;
/// Profit in percentage.
final double? profitPercentage;
/// Epoch of purchase time, will be same as `date_start` for all contracts except forward starting contracts.
final DateTime? purchaseTime;
/// [Only for reset trades i.e. RESETCALL and RESETPUT] Reset barrier of the contract.
final String? resetBarrier;
/// [Only for reset trades i.e. RESETCALL and RESETPUT] The epoch time of a barrier reset.
final DateTime? resetTime;
/// Spot value at the selected tick for the contract.
final double? selectedSpot;
/// [Only for highlowticks trades i.e. TICKHIGH and TICKLOW] Selected tick for the contract.
final int? selectedTick;
/// Price at which contract was sold, only available when contract has been sold.
final double? sellPrice;
/// Latest spot value at the sell time. (only present for contracts already sold). Will no longer be supported in the next API release.
final double? sellSpot;
/// Latest spot value with the correct precision at the sell time. (only present for contracts already sold). Will no longer be supported in the next API release.
final String? sellSpotDisplayValue;
/// Epoch time of the sell spot. Note that since certain underlyings don't tick every second, the sell spot time may be a few seconds before the sell time. (only present for contracts already sold). Will no longer be supported in the next API release.
final DateTime? sellSpotTime;
/// Epoch time of when the contract was sold (only present for contracts already sold)
final DateTime? sellTime;
/// Coded description of the contract purchased.
final String? shortcode;
/// Contract status. Will be `sold` if the contract was sold back before expiry, `won` if won and `lost` if lost at expiry. Otherwise will be `open`
final StatusEnum? status;
/// Only for tick trades, number of ticks
final int? tickCount;
/// [Only for accumulator] Number of ticks passed since entry_tick
final int? tickPassed;
/// Tick stream from entry to end time.
final List<TickStreamItem>? tickStream;
/// Every contract has buy and sell transaction ids, i.e. when you purchase a contract we associate it with buy transaction id, and if contract is already sold we associate that with sell transaction id.
final TransactionIds? transactionIds;
/// The underlying symbol code.
final String? underlying;
/// Error message if validation fails
final String? validationError;
/// Error code if validation fails
final String? validationErrorCode;
}
/// Proposal open contract class.
class ProposalOpenContract extends ProposalOpenContractModel {
/// Initializes Proposal open contract class.
const ProposalOpenContract({
super.accountId,
super.auditDetails,
super.barrier,
super.barrierCount,
super.barrierSpotDistance,
super.bidPrice,
super.buyPrice,
super.cancellation,
super.commision,
super.commission,
super.contractId,
super.contractType,
super.currency,
super.currentSpot,
super.currentSpotDisplayValue,
super.currentSpotHighBarrier,
super.currentSpotLowBarrier,
super.currentSpotTime,
super.dateExpiry,
super.dateSettlement,
super.dateStart,
super.displayName,
super.displayNumberOfContracts,
super.displayValue,
super.entrySpot,
super.entrySpotDisplayValue,
super.entryTick,
super.entryTickDisplayValue,
super.entryTickTime,
super.exitTick,
super.exitTickDisplayValue,
super.exitTickTime,
super.expiryTime,
super.growthRate,
super.highBarrier,
super.id,
super.isExpired,
super.isForwardStarting,
super.isIntraday,
super.isPathDependent,
super.isSettleable,
super.isSold,
super.isValidToCancel,
super.isValidToSell,
super.limitOrder,
super.longcode,
super.lowBarrier,
super.multiplier,
super.numberOfContracts,
super.payout,
super.profit,
super.profitPercentage,
super.purchaseTime,
super.resetBarrier,
super.resetTime,
super.selectedSpot,
super.selectedTick,
super.sellPrice,
super.sellSpot,
super.sellSpotDisplayValue,
super.sellSpotTime,
super.sellTime,
super.shortcode,
super.status,
super.tickCount,
super.tickPassed,
super.tickStream,
super.transactionIds,
super.underlying,
super.validationError,
super.validationErrorCode,
});
/// Creates an instance from JSON.
factory ProposalOpenContract.fromJson(Map<String, dynamic> json) =>
ProposalOpenContract(
accountId: getDouble(json['account_id']),
auditDetails: json['audit_details'] == null
? null
: AuditDetails.fromJson(json['audit_details']),
barrier: json['barrier'],
barrierCount: getDouble(json['barrier_count']),
barrierSpotDistance: json['barrier_spot_distance'],
bidPrice: getDouble(json['bid_price']),
buyPrice: getDouble(json['buy_price']),
cancellation: json['cancellation'] == null
? null
: Cancellation.fromJson(json['cancellation']),
commision: getDouble(json['commision']),
commission: getDouble(json['commission']),
contractId: json['contract_id'],
contractType: json['contract_type'],
currency: json['currency'],
currentSpot: getDouble(json['current_spot']),
currentSpotDisplayValue: json['current_spot_display_value'],
currentSpotHighBarrier: json['current_spot_high_barrier'],
currentSpotLowBarrier: json['current_spot_low_barrier'],
currentSpotTime: getDateTime(json['current_spot_time']),
dateExpiry: getDateTime(json['date_expiry']),
dateSettlement: getDateTime(json['date_settlement']),
dateStart: getDateTime(json['date_start']),
displayName: json['display_name'],
displayNumberOfContracts: json['display_number_of_contracts'],
displayValue: json['display_value'],
entrySpot: getDouble(json['entry_spot']),
entrySpotDisplayValue: json['entry_spot_display_value'],
entryTick: getDouble(json['entry_tick']),
entryTickDisplayValue: json['entry_tick_display_value'],
entryTickTime: getDateTime(json['entry_tick_time']),
exitTick: getDouble(json['exit_tick']),
exitTickDisplayValue: json['exit_tick_display_value'],
exitTickTime: getDateTime(json['exit_tick_time']),
expiryTime: getDateTime(json['expiry_time']),
growthRate: getDouble(json['growth_rate']),
highBarrier: json['high_barrier'],
id: json['id'],
isExpired: getBool(json['is_expired']),
isForwardStarting: getBool(json['is_forward_starting']),
isIntraday: getBool(json['is_intraday']),
isPathDependent: getBool(json['is_path_dependent']),
isSettleable: getBool(json['is_settleable']),
isSold: getBool(json['is_sold']),
isValidToCancel: getBool(json['is_valid_to_cancel']),
isValidToSell: getBool(json['is_valid_to_sell']),
limitOrder: json['limit_order'] == null
? null
: LimitOrder.fromJson(json['limit_order']),
longcode: json['longcode'],
lowBarrier: json['low_barrier'],
multiplier: getDouble(json['multiplier']),
numberOfContracts: getDouble(json['number_of_contracts']),
payout: getDouble(json['payout']),
profit: getDouble(json['profit']),
profitPercentage: getDouble(json['profit_percentage']),
purchaseTime: getDateTime(json['purchase_time']),
resetBarrier: json['reset_barrier'],
resetTime: getDateTime(json['reset_time']),
selectedSpot: getDouble(json['selected_spot']),
selectedTick: json['selected_tick'],
sellPrice: getDouble(json['sell_price']),
sellSpot: getDouble(json['sell_spot']),
sellSpotDisplayValue: json['sell_spot_display_value'],
sellSpotTime: getDateTime(json['sell_spot_time']),
sellTime: getDateTime(json['sell_time']),
shortcode: json['shortcode'],
status:
json['status'] == null ? null : statusEnumMapper[json['status']],
tickCount: json['tick_count'],
tickPassed: json['tick_passed'],
tickStream: json['tick_stream'] == null
? null
: List<TickStreamItem>.from(
json['tick_stream']?.map(
(dynamic item) => TickStreamItem.fromJson(item),
),
),
transactionIds: json['transaction_ids'] == null
? null
: TransactionIds.fromJson(json['transaction_ids']),
underlying: json['underlying'],
validationError: json['validation_error'],
validationErrorCode: json['validation_error_code'],
);
/// Converts an instance to JSON.
Map<String, dynamic> toJson() {
final Map<String, dynamic> resultMap = <String, dynamic>{};
resultMap['account_id'] = accountId;
if (auditDetails != null) {
resultMap['audit_details'] = auditDetails!.toJson();
}
resultMap['barrier'] = barrier;
resultMap['barrier_count'] = barrierCount;
resultMap['barrier_spot_distance'] = barrierSpotDistance;
resultMap['bid_price'] = bidPrice;
resultMap['buy_price'] = buyPrice;
if (cancellation != null) {
resultMap['cancellation'] = cancellation!.toJson();
}
resultMap['commision'] = commision;
resultMap['commission'] = commission;
resultMap['contract_id'] = contractId;
resultMap['contract_type'] = contractType;
resultMap['currency'] = currency;
resultMap['current_spot'] = currentSpot;
resultMap['current_spot_display_value'] = currentSpotDisplayValue;
resultMap['current_spot_high_barrier'] = currentSpotHighBarrier;
resultMap['current_spot_low_barrier'] = currentSpotLowBarrier;
resultMap['current_spot_time'] =
getSecondsSinceEpochDateTime(currentSpotTime);
resultMap['date_expiry'] = getSecondsSinceEpochDateTime(dateExpiry);
resultMap['date_settlement'] = getSecondsSinceEpochDateTime(dateSettlement);
resultMap['date_start'] = getSecondsSinceEpochDateTime(dateStart);
resultMap['display_name'] = displayName;
resultMap['display_number_of_contracts'] = displayNumberOfContracts;
resultMap['display_value'] = displayValue;
resultMap['entry_spot'] = entrySpot;
resultMap['entry_spot_display_value'] = entrySpotDisplayValue;
resultMap['entry_tick'] = entryTick;
resultMap['entry_tick_display_value'] = entryTickDisplayValue;
resultMap['entry_tick_time'] = getSecondsSinceEpochDateTime(entryTickTime);
resultMap['exit_tick'] = exitTick;
resultMap['exit_tick_display_value'] = exitTickDisplayValue;
resultMap['exit_tick_time'] = getSecondsSinceEpochDateTime(exitTickTime);
resultMap['expiry_time'] = getSecondsSinceEpochDateTime(expiryTime);
resultMap['growth_rate'] = growthRate;
resultMap['high_barrier'] = highBarrier;
resultMap['id'] = id;
resultMap['is_expired'] = isExpired;
resultMap['is_forward_starting'] = isForwardStarting;
resultMap['is_intraday'] = isIntraday;
resultMap['is_path_dependent'] = isPathDependent;
resultMap['is_settleable'] = isSettleable;
resultMap['is_sold'] = isSold;
resultMap['is_valid_to_cancel'] = isValidToCancel;
resultMap['is_valid_to_sell'] = isValidToSell;
if (limitOrder != null) {
resultMap['limit_order'] = limitOrder!.toJson();
}
resultMap['longcode'] = longcode;
resultMap['low_barrier'] = lowBarrier;
resultMap['multiplier'] = multiplier;
resultMap['number_of_contracts'] = numberOfContracts;
resultMap['payout'] = payout;
resultMap['profit'] = profit;
resultMap['profit_percentage'] = profitPercentage;
resultMap['purchase_time'] = getSecondsSinceEpochDateTime(purchaseTime);
resultMap['reset_barrier'] = resetBarrier;
resultMap['reset_time'] = getSecondsSinceEpochDateTime(resetTime);
resultMap['selected_spot'] = selectedSpot;
resultMap['selected_tick'] = selectedTick;
resultMap['sell_price'] = sellPrice;
resultMap['sell_spot'] = sellSpot;
resultMap['sell_spot_display_value'] = sellSpotDisplayValue;
resultMap['sell_spot_time'] = getSecondsSinceEpochDateTime(sellSpotTime);
resultMap['sell_time'] = getSecondsSinceEpochDateTime(sellTime);
resultMap['shortcode'] = shortcode;
resultMap['status'] = statusEnumMapper.entries
.firstWhere(
(MapEntry<String, StatusEnum> entry) => entry.value == status)
.key;
resultMap['tick_count'] = tickCount;
resultMap['tick_passed'] = tickPassed;
if (tickStream != null) {
resultMap['tick_stream'] = tickStream!
.map<dynamic>(
(TickStreamItem item) => item.toJson(),
)
.toList();
}
if (transactionIds != null) {
resultMap['transaction_ids'] = transactionIds!.toJson();
}
resultMap['underlying'] = underlying;
resultMap['validation_error'] = validationError;
resultMap['validation_error_code'] = validationErrorCode;
return resultMap;
}
/// Creates a copy of instance with given parameters.
ProposalOpenContract copyWith({
double? accountId,
AuditDetails? auditDetails,
String? barrier,
double? barrierCount,
String? barrierSpotDistance,
double? bidPrice,
double? buyPrice,
Cancellation? cancellation,
double? commision,
double? commission,
int? contractId,
String? contractType,
String? currency,
double? currentSpot,
String? currentSpotDisplayValue,
String? currentSpotHighBarrier,
String? currentSpotLowBarrier,
DateTime? currentSpotTime,
DateTime? dateExpiry,
DateTime? dateSettlement,
DateTime? dateStart,
String? displayName,
String? displayNumberOfContracts,
String? displayValue,
double? entrySpot,
String? entrySpotDisplayValue,
double? entryTick,
String? entryTickDisplayValue,
DateTime? entryTickTime,
double? exitTick,
String? exitTickDisplayValue,
DateTime? exitTickTime,
DateTime? expiryTime,
double? growthRate,
String? highBarrier,
String? id,
bool? isExpired,
bool? isForwardStarting,
bool? isIntraday,
bool? isPathDependent,
bool? isSettleable,
bool? isSold,
bool? isValidToCancel,
bool? isValidToSell,
LimitOrder? limitOrder,
String? longcode,
String? lowBarrier,
double? multiplier,
double? numberOfContracts,
double? payout,
double? profit,
double? profitPercentage,
DateTime? purchaseTime,
String? resetBarrier,
DateTime? resetTime,
double? selectedSpot,
int? selectedTick,
double? sellPrice,
double? sellSpot,
String? sellSpotDisplayValue,
DateTime? sellSpotTime,
DateTime? sellTime,
String? shortcode,
StatusEnum? status,
int? tickCount,
int? tickPassed,
List<TickStreamItem>? tickStream,
TransactionIds? transactionIds,
String? underlying,
String? validationError,
String? validationErrorCode,
}) =>
ProposalOpenContract(
accountId: accountId ?? this.accountId,
auditDetails: auditDetails ?? this.auditDetails,
barrier: barrier ?? this.barrier,
barrierCount: barrierCount ?? this.barrierCount,
barrierSpotDistance: barrierSpotDistance ?? this.barrierSpotDistance,
bidPrice: bidPrice ?? this.bidPrice,
buyPrice: buyPrice ?? this.buyPrice,
cancellation: cancellation ?? this.cancellation,
commision: commision ?? this.commision,
commission: commission ?? this.commission,
contractId: contractId ?? this.contractId,
contractType: contractType ?? this.contractType,
currency: currency ?? this.currency,
currentSpot: currentSpot ?? this.currentSpot,
currentSpotDisplayValue:
currentSpotDisplayValue ?? this.currentSpotDisplayValue,
currentSpotHighBarrier:
currentSpotHighBarrier ?? this.currentSpotHighBarrier,
currentSpotLowBarrier:
currentSpotLowBarrier ?? this.currentSpotLowBarrier,
currentSpotTime: currentSpotTime ?? this.currentSpotTime,
dateExpiry: dateExpiry ?? this.dateExpiry,
dateSettlement: dateSettlement ?? this.dateSettlement,
dateStart: dateStart ?? this.dateStart,
displayName: displayName ?? this.displayName,
displayNumberOfContracts:
displayNumberOfContracts ?? this.displayNumberOfContracts,
displayValue: displayValue ?? this.displayValue,
entrySpot: entrySpot ?? this.entrySpot,
entrySpotDisplayValue:
entrySpotDisplayValue ?? this.entrySpotDisplayValue,
entryTick: entryTick ?? this.entryTick,
entryTickDisplayValue:
entryTickDisplayValue ?? this.entryTickDisplayValue,
entryTickTime: entryTickTime ?? this.entryTickTime,
exitTick: exitTick ?? this.exitTick,
exitTickDisplayValue: exitTickDisplayValue ?? this.exitTickDisplayValue,
exitTickTime: exitTickTime ?? this.exitTickTime,
expiryTime: expiryTime ?? this.expiryTime,
growthRate: growthRate ?? this.growthRate,
highBarrier: highBarrier ?? this.highBarrier,
id: id ?? this.id,
isExpired: isExpired ?? this.isExpired,
isForwardStarting: isForwardStarting ?? this.isForwardStarting,
isIntraday: isIntraday ?? this.isIntraday,
isPathDependent: isPathDependent ?? this.isPathDependent,
isSettleable: isSettleable ?? this.isSettleable,
isSold: isSold ?? this.isSold,
isValidToCancel: isValidToCancel ?? this.isValidToCancel,
isValidToSell: isValidToSell ?? this.isValidToSell,
limitOrder: limitOrder ?? this.limitOrder,
longcode: longcode ?? this.longcode,
lowBarrier: lowBarrier ?? this.lowBarrier,
multiplier: multiplier ?? this.multiplier,
numberOfContracts: numberOfContracts ?? this.numberOfContracts,
payout: payout ?? this.payout,
profit: profit ?? this.profit,
profitPercentage: profitPercentage ?? this.profitPercentage,
purchaseTime: purchaseTime ?? this.purchaseTime,
resetBarrier: resetBarrier ?? this.resetBarrier,
resetTime: resetTime ?? this.resetTime,
selectedSpot: selectedSpot ?? this.selectedSpot,
selectedTick: selectedTick ?? this.selectedTick,
sellPrice: sellPrice ?? this.sellPrice,
sellSpot: sellSpot ?? this.sellSpot,
sellSpotDisplayValue: sellSpotDisplayValue ?? this.sellSpotDisplayValue,
sellSpotTime: sellSpotTime ?? this.sellSpotTime,
sellTime: sellTime ?? this.sellTime,
shortcode: shortcode ?? this.shortcode,
status: status ?? this.status,
tickCount: tickCount ?? this.tickCount,
tickPassed: tickPassed ?? this.tickPassed,
tickStream: tickStream ?? this.tickStream,
transactionIds: transactionIds ?? this.transactionIds,
underlying: underlying ?? this.underlying,
validationError: validationError ?? this.validationError,
validationErrorCode: validationErrorCode ?? this.validationErrorCode,
);
}
/// Audit details model class.
abstract class AuditDetailsModel {
/// Initializes Audit details model class .
const AuditDetailsModel({
this.allTicks,
this.contractEnd,
this.contractStart,
});
/// Ticks for tick expiry contract from start time till expiry.
final List<AllTicksItem>? allTicks;
/// Ticks around contract end time.
final List<ContractEndItem>? contractEnd;
/// Ticks around contract start time.
final List<ContractStartItem>? contractStart;
}
/// Audit details class.
class AuditDetails extends AuditDetailsModel {
/// Initializes Audit details class.
const AuditDetails({
super.allTicks,
super.contractEnd,
super.contractStart,
});
/// Creates an instance from JSON.
factory AuditDetails.fromJson(Map<String, dynamic> json) => AuditDetails(
allTicks: json['all_ticks'] == null
? null
: List<AllTicksItem>.from(
json['all_ticks']?.map(
(dynamic item) => AllTicksItem.fromJson(item),
),
),
contractEnd: json['contract_end'] == null
? null
: List<ContractEndItem>.from(
json['contract_end']?.map(
(dynamic item) => ContractEndItem.fromJson(item),
),
),
contractStart: json['contract_start'] == null
? null
: List<ContractStartItem>.from(
json['contract_start']?.map(
(dynamic item) => ContractStartItem.fromJson(item),
),
),
);
/// Converts an instance to JSON.
Map<String, dynamic> toJson() {
final Map<String, dynamic> resultMap = <String, dynamic>{};
if (allTicks != null) {
resultMap['all_ticks'] = allTicks!
.map<dynamic>(
(AllTicksItem item) => item.toJson(),
)
.toList();
}
if (contractEnd != null) {
resultMap['contract_end'] = contractEnd!
.map<dynamic>(
(ContractEndItem item) => item.toJson(),