Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [DRGO-1581] Raslan/Update endpoints required for MT5 native account creation #361

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
101 changes: 101 additions & 0 deletions lib/api/response/mt5_new_account_response_result.dart
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ final Map<String, Mt5AccountCategoryEnum> mt5AccountCategoryEnumMapper =
<String, Mt5AccountCategoryEnum>{
"conventional": Mt5AccountCategoryEnum.conventional,
"swap_free": Mt5AccountCategoryEnum.swapFree,
"gold": Mt5AccountCategoryEnum.gold,
};

/// Mt5AccountCategory Enum.
Expand All @@ -215,6 +216,9 @@ enum Mt5AccountCategoryEnum {

/// swap_free.
swapFree,

/// gold.
gold,
}

/// Mt5AccountTypeEnum mapper.
Expand All @@ -223,6 +227,7 @@ final Map<String, Mt5AccountTypeEnum> mt5AccountTypeEnumMapper =
"financial": Mt5AccountTypeEnum.financial,
"financial_stp": Mt5AccountTypeEnum.financialStp,
"standard": Mt5AccountTypeEnum.standard,
"gold": Mt5AccountTypeEnum.gold,
};

/// Mt5AccountType Enum.
Expand All @@ -235,8 +240,77 @@ enum Mt5AccountTypeEnum {

/// standard.
standard,

/// gold.
gold,
}

/// ProductEnum mapper.
final Map<String, ProductEnum> productEnumMapper = <String, ProductEnum>{
"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<String, SubAccountTypeEnum> subAccountTypeEnumMapper =
<String, SubAccountTypeEnum>{
"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 .
Expand All @@ -249,6 +323,8 @@ abstract class Mt5NewAccountModel {
this.login,
this.mt5AccountCategory,
this.mt5AccountType,
this.product,
this.subAccountType,
});

/// Account type.
Expand All @@ -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.
Expand All @@ -288,6 +370,8 @@ class Mt5NewAccount extends Mt5NewAccountModel {
super.login,
super.mt5AccountCategory,
super.mt5AccountType,
super.product,
super.subAccountType,
});

/// Creates an instance from JSON.
Expand All @@ -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.
Expand All @@ -329,6 +418,14 @@ class Mt5NewAccount extends Mt5NewAccountModel {
.firstWhere((MapEntry<String, Mt5AccountTypeEnum> entry) =>
entry.value == mt5AccountType)
.key;
resultMap['product'] = productEnumMapper.entries
.firstWhere(
(MapEntry<String, ProductEnum> entry) => entry.value == product)
.key;
resultMap['sub_account_type'] = subAccountTypeEnumMapper.entries
.firstWhere((MapEntry<String, SubAccountTypeEnum> entry) =>
entry.value == subAccountType)
.key;

return resultMap;
}
Expand All @@ -343,6 +440,8 @@ class Mt5NewAccount extends Mt5NewAccountModel {
String? login,
Mt5AccountCategoryEnum? mt5AccountCategory,
Mt5AccountTypeEnum? mt5AccountType,
ProductEnum? product,
SubAccountTypeEnum? subAccountType,
}) =>
Mt5NewAccount(
accountType: accountType ?? this.accountType,
Expand All @@ -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,
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ final Map<String, SubAccountTypeEnum> subAccountTypeEnumMapper =
<String, SubAccountTypeEnum>{
"financial": SubAccountTypeEnum.financial,
"financial_stp": SubAccountTypeEnum.financialStp,
"standard": SubAccountTypeEnum.standard,
"swap_free": SubAccountTypeEnum.swapFree,
};

Expand All @@ -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 .
Expand Down Expand Up @@ -448,7 +451,6 @@ class TradingPlatformAccountsItem extends TradingPlatformAccountsItemModel {
subAccountType: subAccountType ?? this.subAccountType,
);
}

/// Server info model class.
abstract class ServerInfoModel {
/// Initializes Server info model class .
Expand Down Expand Up @@ -516,7 +518,6 @@ class ServerInfo extends ServerInfoModel {
id: id ?? this.id,
);
}

/// Geolocation model class.
abstract class GeolocationModel {
/// Initializes Geolocation model class .
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
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 TradingPlatformAvailableAccountsResponseExtended
extends TradingPlatformAvailableAccountsResponse {
static final BaseAPI _api = Injector()<BaseAPI>();

/// Fetch available platform accounts, this would include all records regardless
/// of already registered products and account types.
static Future<TradingPlatformAvailableAccountsResponse>
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());
}

/// 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<TradingPlatformAvailableAccountsReceive>
fetchAvailableAccountsRaw(
{required TradingPlatformAvailableAccountsRequest request}) async {
final TradingPlatformAvailableAccountsReceive response =
await _api.call(request: request);

checkException(
response: response,
exceptionCreator: ({BaseExceptionModel? baseExceptionModel}) =>
BaseAPIException(baseExceptionModel: baseExceptionModel),
);

return response;
}
}
20 changes: 18 additions & 2 deletions lib/basic_api/generated/mt5_new_account_send.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<String, dynamic>?,
reqId: json['req_id'] as int?,
Expand Down Expand Up @@ -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.
Expand All @@ -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;

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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<String, dynamic>? passthrough,
int? reqId,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion lib/helpers/boolean_helper.dart
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Loading
Loading