From e01bcf674e090fda5d5beb8d976e5d8abe2ac9fa Mon Sep 17 00:00:00 2001 From: raslan-deriv Date: Tue, 24 Dec 2024 16:49:54 +0400 Subject: [PATCH 1/8] Update endpoints required for mt5 native account creation --- .../mt5_new_account_response_result.dart | 101 ++++++++++++++++++ .../generated/mt5_new_account_send.dart | 20 +++- ...trading_platform_password_change_send.dart | 4 +- 3 files changed, 121 insertions(+), 4 deletions(-) diff --git a/lib/api/response/mt5_new_account_response_result.dart b/lib/api/response/mt5_new_account_response_result.dart index 85be682226..4e25b24c86 100644 --- a/lib/api/response/mt5_new_account_response_result.dart +++ b/lib/api/response/mt5_new_account_response_result.dart @@ -206,6 +206,7 @@ final Map mt5AccountCategoryEnumMapper = { "conventional": Mt5AccountCategoryEnum.conventional, "swap_free": Mt5AccountCategoryEnum.swapFree, + "gold": Mt5AccountCategoryEnum.gold, }; /// Mt5AccountCategory Enum. @@ -215,6 +216,9 @@ enum Mt5AccountCategoryEnum { /// swap_free. swapFree, + + /// gold. + gold, } /// Mt5AccountTypeEnum mapper. @@ -223,6 +227,7 @@ final Map mt5AccountTypeEnumMapper = "financial": Mt5AccountTypeEnum.financial, "financial_stp": Mt5AccountTypeEnum.financialStp, "standard": Mt5AccountTypeEnum.standard, + "gold": Mt5AccountTypeEnum.gold, }; /// Mt5AccountType Enum. @@ -235,8 +240,77 @@ enum Mt5AccountTypeEnum { /// standard. standard, + + /// gold. + gold, +} + +/// ProductEnum mapper. +final Map productEnumMapper = { + "synthetic": ProductEnum.synthetic, + "financial": ProductEnum.financial, + "swap_free": ProductEnum.swapFree, + "zero_spread": ProductEnum.zeroSpread, + "standard": ProductEnum.standard, + "stp": ProductEnum.stp, + "gold": ProductEnum.gold, +}; + +/// Product Enum. +enum ProductEnum { + /// synthetic. + synthetic, + + /// financial. + financial, + + /// swap_free. + swapFree, + + /// zero_spread. + zeroSpread, + + /// standard. + standard, + + /// stp. + stp, + + /// gold. + gold, } +/// SubAccountTypeEnum mapper. +final Map subAccountTypeEnumMapper = + { + "standard": SubAccountTypeEnum.standard, + "stp": SubAccountTypeEnum.stp, + "ibt": SubAccountTypeEnum.ibt, + "swap_free": SubAccountTypeEnum.swapFree, + "zero_spread": SubAccountTypeEnum.zeroSpread, + "gold": SubAccountTypeEnum.gold, +}; + +/// SubAccountType Enum. +enum SubAccountTypeEnum { + /// standard. + standard, + + /// stp. + stp, + + /// ibt. + ibt, + + /// swap_free. + swapFree, + + /// zero_spread. + zeroSpread, + + /// gold. + gold, +} /// Mt5 new account model class. abstract class Mt5NewAccountModel { /// Initializes Mt5 new account model class . @@ -249,6 +323,8 @@ abstract class Mt5NewAccountModel { this.login, this.mt5AccountCategory, this.mt5AccountType, + this.product, + this.subAccountType, }); /// Account type. @@ -274,6 +350,12 @@ abstract class Mt5NewAccountModel { /// Sub account type for classic MT5 account. final Mt5AccountTypeEnum? mt5AccountType; + + /// Product name that Deriv offer + final ProductEnum? product; + + /// Indicate the different offerings for mt5 account. + final SubAccountTypeEnum? subAccountType; } /// Mt5 new account class. @@ -288,6 +370,8 @@ class Mt5NewAccount extends Mt5NewAccountModel { super.login, super.mt5AccountCategory, super.mt5AccountType, + super.product, + super.subAccountType, }); /// Creates an instance from JSON. @@ -306,6 +390,11 @@ class Mt5NewAccount extends Mt5NewAccountModel { mt5AccountType: json['mt5_account_type'] == null ? null : mt5AccountTypeEnumMapper[json['mt5_account_type']], + product: + json['product'] == null ? null : productEnumMapper[json['product']], + subAccountType: json['sub_account_type'] == null + ? null + : subAccountTypeEnumMapper[json['sub_account_type']], ); /// Converts an instance to JSON. @@ -329,6 +418,14 @@ class Mt5NewAccount extends Mt5NewAccountModel { .firstWhere((MapEntry entry) => entry.value == mt5AccountType) .key; + resultMap['product'] = productEnumMapper.entries + .firstWhere( + (MapEntry entry) => entry.value == product) + .key; + resultMap['sub_account_type'] = subAccountTypeEnumMapper.entries + .firstWhere((MapEntry entry) => + entry.value == subAccountType) + .key; return resultMap; } @@ -343,6 +440,8 @@ class Mt5NewAccount extends Mt5NewAccountModel { String? login, Mt5AccountCategoryEnum? mt5AccountCategory, Mt5AccountTypeEnum? mt5AccountType, + ProductEnum? product, + SubAccountTypeEnum? subAccountType, }) => Mt5NewAccount( accountType: accountType ?? this.accountType, @@ -353,5 +452,7 @@ class Mt5NewAccount extends Mt5NewAccountModel { login: login ?? this.login, mt5AccountCategory: mt5AccountCategory ?? this.mt5AccountCategory, mt5AccountType: mt5AccountType ?? this.mt5AccountType, + product: product ?? this.product, + subAccountType: subAccountType ?? this.subAccountType, ); } diff --git a/lib/basic_api/generated/mt5_new_account_send.dart b/lib/basic_api/generated/mt5_new_account_send.dart index ebd4bbb2ab..b10bd5ca83 100644 --- a/lib/basic_api/generated/mt5_new_account_send.dart +++ b/lib/basic_api/generated/mt5_new_account_send.dart @@ -27,9 +27,11 @@ class Mt5NewAccountRequest extends Request { required this.name, this.phone, this.phonePassword, + required this.product, this.server, this.state, this.subAccountCategory, + this.subAccountType, this.zipCode, super.msgType = 'mt5_new_account', super.passthrough, @@ -60,9 +62,11 @@ class Mt5NewAccountRequest extends Request { name: json['name'] as String?, phone: json['phone'] as String?, phonePassword: json['phonePassword'] as String?, + product: json['product'] as String?, server: json['server'] as String?, state: json['state'] as String?, subAccountCategory: json['sub_account_category'] as String?, + subAccountType: json['sub_account_type'] as String?, zipCode: json['zipCode'] as String?, passthrough: json['passthrough'] as Map?, reqId: json['req_id'] as int?, @@ -98,7 +102,7 @@ class Mt5NewAccountRequest extends Request { /// Client leverage (from 1 to 1000). final num? leverage; - /// [Optional] The login id of the user. If left unspecified, it defaults to the initial authorized token's login id. + /// [Optional] The login id of the user. Mandatory when multiple tokens were provided during authorize. final String? loginid; /// The master password of the account. For validation (Accepts any printable ASCII character. Must be within 8-25 characters, and include numbers, lowercase and uppercase letters. Must not be the same as the user's email address). This field is required. @@ -125,15 +129,21 @@ class Mt5NewAccountRequest extends Request { /// [Optional] The user's phone password. final String? phonePassword; + /// Product name that Deriv offer + final String? product; + /// [Optional] Trade server. final String? server; /// [Optional] User's state (region) of residence. final String? state; - /// [Optional] Indicate the sub account category that we have in the cfd group naming convention. + /// [Optional] Indicate the additional risk management for each account final String? subAccountCategory; + /// [Optional] Indicate the different offerings for mt5 account + final String? subAccountType; + /// [Optional] User's zip code. final String? zipCode; @@ -167,9 +177,11 @@ class Mt5NewAccountRequest extends Request { 'name': name, 'phone': phone, 'phonePassword': phonePassword, + 'product': product, 'server': server, 'state': state, 'sub_account_category': subAccountCategory, + 'sub_account_type': subAccountType, 'zipCode': zipCode, 'passthrough': passthrough, 'req_id': reqId, @@ -197,9 +209,11 @@ class Mt5NewAccountRequest extends Request { String? name, String? phone, String? phonePassword, + String? product, String? server, String? state, String? subAccountCategory, + String? subAccountType, String? zipCode, Map? passthrough, int? reqId, @@ -224,9 +238,11 @@ class Mt5NewAccountRequest extends Request { name: name ?? this.name, phone: phone ?? this.phone, phonePassword: phonePassword ?? this.phonePassword, + product: product ?? this.product, server: server ?? this.server, state: state ?? this.state, subAccountCategory: subAccountCategory ?? this.subAccountCategory, + subAccountType: subAccountType ?? this.subAccountType, zipCode: zipCode ?? this.zipCode, passthrough: passthrough ?? this.passthrough, reqId: reqId ?? this.reqId, diff --git a/lib/basic_api/generated/trading_platform_password_change_send.dart b/lib/basic_api/generated/trading_platform_password_change_send.dart index 03ce516295..f03adb44ef 100644 --- a/lib/basic_api/generated/trading_platform_password_change_send.dart +++ b/lib/basic_api/generated/trading_platform_password_change_send.dart @@ -34,10 +34,10 @@ class TradingPlatformPasswordChangeRequest extends Request { reqId: json['req_id'] as int?, ); - /// [Optional] The login id of the user. If left unspecified, it defaults to the initial authorized token's login id. + /// [Optional] The login id of the user. Mandatory when multiple tokens were provided during authorize. final String? loginid; - /// New trading password. Accepts any printable ASCII character. Must be within 8-25 characters, and include numbers, lowercase and uppercase letters. Must not be the same as the user's email address. + /// New password of the account. For validation (Accepts any printable ASCII character. DerivX: Must be within 8-25 characters, include numbers, lowercase, uppercase letters. Must not be the same as the user's email address). Accepts any printable ASCII character. MT5: Must be within 8-16 characters, include numbers, lowercase, uppercase letters and special characters. Must not be the same as the user's email address. final String? newPassword; /// Old password for validation. Must be empty if a password has not been set yet. From ddaa45aca1ec2c7df95d942b6dc0b59d6bed2e64 Mon Sep 17 00:00:00 2001 From: raslan-deriv Date: Thu, 26 Dec 2024 11:55:11 +0400 Subject: [PATCH 2/8] Added updated TradingPlatformAvailableAccountsExtended --- ..._platform_available_accounts_extended.dart | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 lib/api/response/trading_platform_available_accounts_extended.dart diff --git a/lib/api/response/trading_platform_available_accounts_extended.dart b/lib/api/response/trading_platform_available_accounts_extended.dart new file mode 100644 index 0000000000..c3f6f7ae5d --- /dev/null +++ b/lib/api/response/trading_platform_available_accounts_extended.dart @@ -0,0 +1,30 @@ +import 'package:deriv_dependency_injector/dependency_injector.dart'; +import 'package:flutter_deriv_api/api/exceptions/exceptions.dart'; +import 'package:flutter_deriv_api/api/response/trading_platform_available_accounts_response_result.dart'; +import 'package:flutter_deriv_api/basic_api/generated/trading_platform_available_accounts_receive.dart'; +import 'package:flutter_deriv_api/basic_api/generated/trading_platform_available_accounts_send.dart'; +import 'package:flutter_deriv_api/helpers/miscellaneous_helper.dart'; +import 'package:flutter_deriv_api/services/connection/api_manager/base_api.dart'; + +/// Extended functionality for [TradingPlatformAvailableAccountsResponse] class. +class TradingPlatformAvailableAccountsExtended + extends TradingPlatformAvailableAccountsResponse { + static final BaseAPI _api = Injector()(); + + /// Fetch available platform accounts, this would include all records regardless + /// of already registered products and account types. + static Future + fetchAvailableAccounts( + {required TradingPlatformAvailableAccountsRequest request}) async { + final TradingPlatformAvailableAccountsReceive response = + await _api.call(request: request); + + checkException( + response: response, + exceptionCreator: ({BaseExceptionModel? baseExceptionModel}) => + BaseAPIException(baseExceptionModel: baseExceptionModel), + ); + + return TradingPlatformAvailableAccountsResponse.fromJson(response.toJson()); + } +} From e25fd322399347b98fd3a9a6ee4eddcb6b0e919c Mon Sep 17 00:00:00 2001 From: raslan-deriv Date: Thu, 26 Dec 2024 11:57:29 +0400 Subject: [PATCH 3/8] updated TradingPlatformAccountsResponse related models --- .../trading_platform_accounts_response_result.dart | 7 ++++--- .../generated/trading_platform_accounts_send.dart | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/api/response/trading_platform_accounts_response_result.dart b/lib/api/response/trading_platform_accounts_response_result.dart index 94fec6ea3a..e45aad7046 100644 --- a/lib/api/response/trading_platform_accounts_response_result.dart +++ b/lib/api/response/trading_platform_accounts_response_result.dart @@ -210,6 +210,7 @@ final Map subAccountTypeEnumMapper = { "financial": SubAccountTypeEnum.financial, "financial_stp": SubAccountTypeEnum.financialStp, + "standard": SubAccountTypeEnum.standard, "swap_free": SubAccountTypeEnum.swapFree, }; @@ -221,10 +222,12 @@ enum SubAccountTypeEnum { /// financial_stp. financialStp, + /// standard. + standard, + /// swap_free. swapFree, } - /// Trading platform accounts item model class. abstract class TradingPlatformAccountsItemModel { /// Initializes Trading platform accounts item model class . @@ -448,7 +451,6 @@ class TradingPlatformAccountsItem extends TradingPlatformAccountsItemModel { subAccountType: subAccountType ?? this.subAccountType, ); } - /// Server info model class. abstract class ServerInfoModel { /// Initializes Server info model class . @@ -516,7 +518,6 @@ class ServerInfo extends ServerInfoModel { id: id ?? this.id, ); } - /// Geolocation model class. abstract class GeolocationModel { /// Initializes Geolocation model class . diff --git a/lib/basic_api/generated/trading_platform_accounts_send.dart b/lib/basic_api/generated/trading_platform_accounts_send.dart index 78b3330b9d..76dccedc62 100644 --- a/lib/basic_api/generated/trading_platform_accounts_send.dart +++ b/lib/basic_api/generated/trading_platform_accounts_send.dart @@ -28,7 +28,7 @@ class TradingPlatformAccountsRequest extends Request { reqId: json['req_id'] as int?, ); - /// [Optional] The login id of the user. If left unspecified, it defaults to the initial authorized token's login id. + /// [Optional] The login id of the user. Mandatory when multiple tokens were provided during authorize. final String? loginid; /// Trading platform name From afc3d02749f222a460e68c6180d0cec3f3bef2a3 Mon Sep 17 00:00:00 2001 From: raslan-deriv Date: Thu, 26 Dec 2024 12:10:09 +0400 Subject: [PATCH 4/8] updated mt5_account_test --- test/api/mt5/mt5_account_test.dart | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/api/mt5/mt5_account_test.dart b/test/api/mt5/mt5_account_test.dart index 6e10a79ccc..c7bc3f64b4 100644 --- a/test/api/mt5/mt5_account_test.dart +++ b/test/api/mt5/mt5_account_test.dart @@ -24,7 +24,7 @@ void main() { test('Create New MT5 Account Test', () async { final new_account.Mt5NewAccountResponse mt5Account = await new_account.Mt5NewAccountResponse.createNewAccount( - const Mt5NewAccountRequest( + Mt5NewAccountRequest( accountType: 'demo', address: 'Dummy address', city: 'Valletta', @@ -40,6 +40,7 @@ void main() { phonePassword: 'AbcDv1234', state: 'Valleta', zipCode: 'VLT 1117', + product: new_account.ProductEnum.standard.toString(), ), ); @@ -51,6 +52,8 @@ void main() { expect(mt5Account.mt5NewAccount?.login, 'MT346525'); expect(mt5Account.mt5NewAccount?.mt5AccountType, new_account.Mt5AccountTypeEnum.financial); + expect(mt5Account.mt5NewAccount?.product, + new_account.ProductEnum.standard.toString()); }); test('MT5 Login List Test', () async { From 05a171665d97107d3ba6fc2d91b9bb43bcc3666a Mon Sep 17 00:00:00 2001 From: raslan-deriv Date: Thu, 26 Dec 2024 12:25:43 +0400 Subject: [PATCH 5/8] mt5_account_test unit test data update --- test/api/mt5/mt5_account_test.dart | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/test/api/mt5/mt5_account_test.dart b/test/api/mt5/mt5_account_test.dart index c7bc3f64b4..0ffeef7ed0 100644 --- a/test/api/mt5/mt5_account_test.dart +++ b/test/api/mt5/mt5_account_test.dart @@ -24,7 +24,7 @@ void main() { test('Create New MT5 Account Test', () async { final new_account.Mt5NewAccountResponse mt5Account = await new_account.Mt5NewAccountResponse.createNewAccount( - Mt5NewAccountRequest( + const Mt5NewAccountRequest( accountType: 'demo', address: 'Dummy address', city: 'Valletta', @@ -40,7 +40,7 @@ void main() { phonePassword: 'AbcDv1234', state: 'Valleta', zipCode: 'VLT 1117', - product: new_account.ProductEnum.standard.toString(), + product: null, ), ); @@ -52,8 +52,7 @@ void main() { expect(mt5Account.mt5NewAccount?.login, 'MT346525'); expect(mt5Account.mt5NewAccount?.mt5AccountType, new_account.Mt5AccountTypeEnum.financial); - expect(mt5Account.mt5NewAccount?.product, - new_account.ProductEnum.standard.toString()); + expect(mt5Account.mt5NewAccount?.product, null); }); test('MT5 Login List Test', () async { From 17ff41c7c3af5015e5970a6ab4efdf25104386e0 Mon Sep 17 00:00:00 2001 From: raslan-deriv Date: Thu, 26 Dec 2024 13:28:59 +0400 Subject: [PATCH 6/8] trading platform available accounts response extended rename --- ... trading_platform_available_accounts_response_extended.dart} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename lib/api/response/{trading_platform_available_accounts_extended.dart => trading_platform_available_accounts_response_extended.dart} (96%) diff --git a/lib/api/response/trading_platform_available_accounts_extended.dart b/lib/api/response/trading_platform_available_accounts_response_extended.dart similarity index 96% rename from lib/api/response/trading_platform_available_accounts_extended.dart rename to lib/api/response/trading_platform_available_accounts_response_extended.dart index c3f6f7ae5d..7faefd4e8a 100644 --- a/lib/api/response/trading_platform_available_accounts_extended.dart +++ b/lib/api/response/trading_platform_available_accounts_response_extended.dart @@ -7,7 +7,7 @@ import 'package:flutter_deriv_api/helpers/miscellaneous_helper.dart'; import 'package:flutter_deriv_api/services/connection/api_manager/base_api.dart'; /// Extended functionality for [TradingPlatformAvailableAccountsResponse] class. -class TradingPlatformAvailableAccountsExtended +class TradingPlatformAvailableAccountsResponseExtended extends TradingPlatformAvailableAccountsResponse { static final BaseAPI _api = Injector()(); From b8d01239613b5116984b2cec9b209430eabbbd4c Mon Sep 17 00:00:00 2001 From: raslan-deriv Date: Fri, 27 Dec 2024 09:56:12 +0400 Subject: [PATCH 7/8] added raw fetch method on TradingPlatformAvailableAccountsResponseExtended --- ..._available_accounts_response_extended.dart | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/api/response/trading_platform_available_accounts_response_extended.dart b/lib/api/response/trading_platform_available_accounts_response_extended.dart index 7faefd4e8a..98e63176dc 100644 --- a/lib/api/response/trading_platform_available_accounts_response_extended.dart +++ b/lib/api/response/trading_platform_available_accounts_response_extended.dart @@ -27,4 +27,23 @@ class TradingPlatformAvailableAccountsResponseExtended return TradingPlatformAvailableAccountsResponse.fromJson(response.toJson()); } + + /// Fetch available platform accounts in raw format. + /// This method returns the raw response from the API call, which includes + /// all records regardless of already registered products and account types. + /// Returns a [TradingPlatformAvailableAccountsReceive] object containing the raw response. + static Future + fetchAvailableAccountsRaw( + {required TradingPlatformAvailableAccountsRequest request}) async { + final TradingPlatformAvailableAccountsReceive response = + await _api.call(request: request); + + checkException( + response: response, + exceptionCreator: ({BaseExceptionModel? baseExceptionModel}) => + BaseAPIException(baseExceptionModel: baseExceptionModel), + ); + + return response; + } } From f0fdb8f216ddfd5aaabfca62890fb66b2599c509 Mon Sep 17 00:00:00 2001 From: raslan-deriv Date: Fri, 27 Dec 2024 11:06:12 +0400 Subject: [PATCH 8/8] updated boolean comparision condition --- lib/helpers/boolean_helper.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/helpers/boolean_helper.dart b/lib/helpers/boolean_helper.dart index dfccc36493..ee560645a7 100644 --- a/lib/helpers/boolean_helper.dart +++ b/lib/helpers/boolean_helper.dart @@ -1,6 +1,6 @@ /// Converts int to boolean bool? getBool(dynamic value) => - value == null ? null : value == 1 || value == true; + value == null ? null : value == 1 || value == true || value == 'true'; /// Converts boolean to int int? getInt({bool? value}) => value == null