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

[SPIKE]: [DRGO-1289] Ramin/add isolate #348

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/api/manually/tick.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:flutter_deriv_api/basic_api/generated/api.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/api_manager/binary_api.dart';
import 'package:flutter_deriv_api/services/connection/call_manager/base_call_manager.dart';
import 'package:deriv_dependency_injector/dependency_injector.dart';

Expand Down
19 changes: 5 additions & 14 deletions lib/api/response/active_symbols_response_result.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:flutter_deriv_api/basic_api/generated/active_symbols_send.dart';
import 'package:flutter_deriv_api/helpers/helpers.dart';
import 'package:flutter_deriv_api/services/connection/api_manager/base_api.dart';
import 'package:deriv_dependency_injector/dependency_injector.dart';
import 'package:flutter_deriv_api/services/connection/api_manager/binary_api.dart';

/// Active symbols response model class.
abstract class ActiveSymbolsResponseModel {
Expand Down Expand Up @@ -56,27 +57,17 @@ class ActiveSymbolsResponse extends ActiveSymbolsResponseModel {
return resultMap;
}

static final BaseAPI _api = Injector()<BaseAPI>();
static final IsolateWrappingAPI _api =
Injector()<BaseAPI>() as IsolateWrappingAPI;

/// Gets the list of active symbols.
///
/// For parameters information refer to [ActiveSymbolsRequest].
/// Throws an [BaseAPIException] if API response contains an error
static Future<ActiveSymbolsResponse> fetchActiveSymbols(
ActiveSymbolsRequest request,
) async {
final ActiveSymbolsReceive response = await _api.call(
request: request,
);

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

return ActiveSymbolsResponse.fromJson(response.activeSymbols);
}
) async =>
_api.fetchActiveSymbols(request);

/// Creates a copy of instance with given parameters.
ActiveSymbolsResponse copyWith({
Expand Down
19 changes: 5 additions & 14 deletions lib/api/response/authorize_response_result.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:flutter_deriv_api/basic_api/generated/authorize_send.dart';
import 'package:flutter_deriv_api/helpers/helpers.dart';
import 'package:flutter_deriv_api/services/connection/api_manager/base_api.dart';
import 'package:deriv_dependency_injector/dependency_injector.dart';
import 'package:flutter_deriv_api/services/connection/api_manager/binary_api.dart';

/// Authorize response model class.
abstract class AuthorizeResponseModel {
Expand Down Expand Up @@ -48,27 +49,17 @@ class AuthorizeResponse extends AuthorizeResponseModel {
return resultMap;
}

static final BaseAPI _api = Injector()<BaseAPI>();
static final IsolateWrappingAPI _api =
Injector()<BaseAPI>() as IsolateWrappingAPI;

/// Authorizes current WebSocket session to act on behalf of the owner of a given token.
///
/// For parameters information refer to [AuthorizeRequest].
/// Throws an [BaseAPIException] if API response contains an error.
static Future<AuthorizeReceive> authorizeMethodRaw(
AuthorizeRequest request,
) async {
final AuthorizeReceive response = await _api.call(
request: request,
);

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

return response;
}
) async =>
_api.authorize(request);

/// Authorizes current WebSocket session to act on behalf of the owner of a given token.
///
Expand Down
23 changes: 4 additions & 19 deletions lib/api/response/proposal_response_result.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import 'package:flutter_deriv_api/basic_api/generated/proposal_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/api_manager/binary_api.dart';
import 'package:flutter_deriv_api/services/connection/call_manager/base_call_manager.dart';
import 'package:deriv_dependency_injector/dependency_injector.dart';

Expand Down Expand Up @@ -69,7 +70,8 @@ class ProposalResponse extends ProposalResponseModel {
return resultMap;
}

static final BaseAPI _api = Injector()<BaseAPI>();
static final IsolateWrappingAPI _api =
Injector()<BaseAPI>() as IsolateWrappingAPI;

/// Gets the price proposal for contract
///
Expand Down Expand Up @@ -97,24 +99,7 @@ class ProposalResponse extends ProposalResponseModel {
ProposalRequest request, {
RequestCompareFunction? comparePredicate,
}) =>
_api
.subscribe(request: request, comparePredicate: comparePredicate)!
.map<ProposalResponse?>(
(Response response) {
checkException(
response: response,
exceptionCreator: ({BaseExceptionModel? baseExceptionModel}) =>
BaseAPIException(baseExceptionModel: baseExceptionModel),
);

return response is ProposalReceive
? ProposalResponse.fromJson(
response.proposal,
response.subscription,
)
: null;
},
);
_api.subscribePriceForContract(request);

/// Unsubscribes from price proposal subscription.
///
Expand Down
45 changes: 4 additions & 41 deletions lib/api/response/ticks_history_response_result.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import 'package:flutter_deriv_api/basic_api/generated/ticks_receive.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/api_manager/binary_api.dart';
import 'package:flutter_deriv_api/services/connection/call_manager/base_call_manager.dart';
import 'package:deriv_dependency_injector/dependency_injector.dart';

Expand Down Expand Up @@ -95,7 +96,8 @@ class TicksHistoryResponse extends TicksHistoryResponseModel {
return resultMap;
}

static final BaseAPI _api = Injector()<BaseAPI>();
static final IsolateWrappingAPI _api =
Injector()<BaseAPI>() as IsolateWrappingAPI;

/// Gets the [TickHistory] for the given [symbol] in [request]
///
Expand Down Expand Up @@ -124,46 +126,7 @@ class TicksHistoryResponse extends TicksHistoryResponseModel {
bool subscribe = true,
}) async {
if (subscribe) {
final Stream<Response>? responseStream =
_api.subscribe(request: request, comparePredicate: comparePredicate);
final Response? firstResponse = await responseStream?.first;

checkException(
response: firstResponse,
exceptionCreator: ({BaseExceptionModel? baseExceptionModel}) =>
BaseAPIException(baseExceptionModel: baseExceptionModel),
);
if (firstResponse is TicksHistoryReceive) {
return TickHistorySubscription(
tickHistory: TicksHistoryResponse.fromJson(
firstResponse.candles,
firstResponse.history,
firstResponse.pipSize,
firstResponse.subscription),
tickStream: responseStream?.map<TickBase?>(
(Response response) {
checkException(
response: response,
exceptionCreator: ({BaseExceptionModel? baseExceptionModel}) =>
BaseAPIException(baseExceptionModel: baseExceptionModel),
);

return response is TicksReceive
? Tick.fromJson(
response.tick!,
subscriptionJson: response.subscription,
)
: response is OHLCResponse
? OHLC.fromJson(
response.ohlc!,
subscriptionJson: response.subscription,
)
: null;
},
),
);
}
return null;
return _api.subscribeTickHistory(request);
} else {
return TickHistorySubscription(
tickHistory: await fetchTickHistory(request),
Expand Down
25 changes: 5 additions & 20 deletions lib/api/response/ticks_response_result.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:flutter_deriv_api/basic_api/generated/ticks_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/api_manager/binary_api.dart';
import 'package:flutter_deriv_api/services/connection/call_manager/base_call_manager.dart';
import 'package:deriv_dependency_injector/dependency_injector.dart';

Expand Down Expand Up @@ -64,33 +65,17 @@ class TicksResponse extends TicksResponseModel {
return resultMap;
}

static final BaseAPI _api = Injector()<BaseAPI>();
static final IsolateWrappingAPI _api =
Injector()<BaseAPI>() as IsolateWrappingAPI;

/// Subscribes to a tick for given [TickRequest]
///
/// Throws [BaseAPIException] if API response contains an error
static Stream<TicksResponse?> subscribeTick(
static Stream<TicksResponse> subscribeTick(
TicksRequest tickRequest, {
RequestCompareFunction? comparePredicate,
}) =>
_api
.subscribe(request: tickRequest, comparePredicate: comparePredicate)!
.map<TicksResponse?>(
(Response response) {
checkException(
response: response,
exceptionCreator: ({BaseExceptionModel? baseExceptionModel}) =>
BaseAPIException(baseExceptionModel: baseExceptionModel),
);

return response is TicksReceive
? TicksResponse.fromJson(
response.tick,
response.subscription,
)
: null;
},
);
_api.subscribeTick(tickRequest);

/// Unsubscribes all ticks.
///
Expand Down
Loading
Loading