Skip to content

Commit

Permalink
Removed exposure check, since it was fixed by Dukascopy with 3.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
juxeii authored and juxeii committed Jun 3, 2017
1 parent 8658794 commit 384e875
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 348 deletions.
63 changes: 0 additions & 63 deletions src/main/java/com/jforex/programming/misc/Exposure.java

This file was deleted.

36 changes: 3 additions & 33 deletions src/main/java/com/jforex/programming/order/OrderUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@
import java.util.function.Function;
import java.util.stream.Collectors;

import com.dukascopy.api.IOrder;
import com.dukascopy.api.Instrument;
import com.dukascopy.api.JFException;
import com.google.common.collect.ImmutableMap;
import com.jforex.programming.misc.Exposure;
import com.jforex.programming.order.event.OrderEvent;
import com.jforex.programming.order.task.BasicTask;
import com.jforex.programming.order.task.ClosePositionTask;
Expand Down Expand Up @@ -44,27 +41,24 @@ public class OrderUtil {
private final BasicTask basicTask;
private final PositionUtil positionUtil;
private final TaskParamsUtil taskParamsUtil;
private final Exposure exposure;
private final Map<TaskParamsType, Function<TaskParams, Observable<OrderEvent>>> taskParamsMapper;

public OrderUtil(final BasicTask basicTask,
final MergePositionTask mergePositionTask,
final ClosePositionTask closePositionTask,
final PositionUtil positionUtil,
final TaskParamsUtil taskParamsUtil,
final Exposure exposure) {
final TaskParamsUtil taskParamsUtil) {
this.basicTask = basicTask;
this.positionUtil = positionUtil;
this.taskParamsUtil = taskParamsUtil;
this.exposure = exposure;

taskParamsMapper = ImmutableMap.<TaskParamsType, Function<TaskParams, Observable<OrderEvent>>> builder()
.put(TaskParamsType.SUBMIT,
params -> submitWithExposureCheck((SubmitParams) params))
.put(TaskParamsType.MERGE,
params -> basicTask.mergeOrders((MergeParams) params))
.put(TaskParamsType.CLOSE,
params -> closeWithExposureCheck((CloseParams) params))
params -> basicTask.close((CloseParams) params))
.put(TaskParamsType.SETLABEL,
params -> basicTask.setLabel((SetLabelParams) params))
.put(TaskParamsType.SETGTT,
Expand All @@ -90,33 +84,9 @@ public OrderUtil(final BasicTask basicTask,

private Observable<OrderEvent> submitWithExposureCheck(final SubmitParams submitParams) {
final OrderParams orderParams = submitParams.orderParams();
final double signedAmount = OrderStaticUtil.signedAmount(orderParams);
final Instrument instrument = orderParams.instrument();
positionUtil.create(instrument);

final boolean wouldExceedAmount = exposure.wouldExceed(instrument, signedAmount);
return wouldExceedAmount
? Observable.error(maxExposureException(instrument))
: basicTask.submitOrder(submitParams);
}

private Observable<OrderEvent> closeWithExposureCheck(final CloseParams closeParams) {
final IOrder order = closeParams.order();
final double orderAmount = order.getAmount();
final double partialCloseAmount = closeParams.partialCloseAmount();
final double signedAmount = partialCloseAmount > 0
? -OrderStaticUtil.signedAmount(partialCloseAmount, order.getOrderCommand())
: -OrderStaticUtil.signedAmount(orderAmount, order.getOrderCommand());
final Instrument instrument = order.getInstrument();

final boolean wouldExceedAmount = exposure.wouldExceed(instrument, signedAmount);
return wouldExceedAmount
? Observable.error(maxExposureException(instrument))
: basicTask.close(closeParams);
}

private JFException maxExposureException(final Instrument instrument) {
return new JFException("Maximum exposure reached on " + instrument);
return basicTask.submitOrder(submitParams);
}

public Observable<OrderEvent> paramsToObservable(final TaskParams taskParams) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.dukascopy.api.IEngine;
import com.dukascopy.api.IMessage;
import com.jforex.programming.math.CalculationUtil;
import com.jforex.programming.misc.Exposure;
import com.jforex.programming.misc.StrategyThreadRunner;
import com.jforex.programming.order.OrderUtil;
import com.jforex.programming.order.OrderUtilHandler;
Expand Down Expand Up @@ -56,7 +55,6 @@ public class OrderInitUtil {
private final BatchCancelSLTask cancelSLTask;
private final BatchCancelTPTask cancelTPTask;
private final CancelSLTPTask cancelSLTPTask;
private final Exposure exposure;
private final OrderUtil orderUtil;
private final OrderEventFactory orderEventFactory;
private final OrderEventTypeDataFactory orderEventTypeDataFactory = new OrderEventTypeDataFactory();
Expand Down Expand Up @@ -93,13 +91,11 @@ public OrderInitUtil(final ContextUtil contextUtil,
batchChangeTask,
ordersForPositionClose);
orderCloseTask = new ClosePositionTask(mergeAndClosePositionTask, positionUtil);
exposure = new Exposure(engine);
orderUtil = new OrderUtil(orderBasicTask,
orderMergeTask,
orderCloseTask,
positionUtil,
taskParamsUtil,
exposure);
taskParamsUtil);
}

public OrderUtil orderUtil() {
Expand Down
111 changes: 0 additions & 111 deletions src/test/java/com/jforex/programming/misc/test/ExposureTest.java

This file was deleted.

Loading

0 comments on commit 384e875

Please sign in to comment.