示例#1
0
        public void ShiftPositionLimitsReceived(ShiftPositionLimitsData shiftPositionLimitsData)
        {
            Task task = new Task(() =>
            {
                Log(LogEntryImportance.Info, "Shifting Position limits...", true);
                ShiftPositionLimits(shiftPositionLimitsData);
            });

            task.Start();
        }
示例#2
0
        private void ShiftPositionLimits(ShiftPositionLimitsData shiftPositionLimitsData)
        {
            Log(LogEntryImportance.Info, "In ShiftPositionLimits", true);

            try
            {
                //Cancel current stoploss order
                bool cancelClosingOrderRes = CancelClosingOrder();

                if (cancelClosingOrderRes)
                {
                    //create new stop loss order
                    Order newStopLossOrder = _orderFactory.CreateStopLossOrder(BrokerPosition.OpeningOrder, shiftPositionLimitsData.NewLimitPrice, shiftPositionLimitsData.ValidateOnly);
                    UpdateClosingOrder(newStopLossOrder);
                    //place order and wait
                    Log(LogEntryImportance.Info, "Placing new closing order...", true);
                    PlaceOrderResult placeOrderResult = _client.PlaceOrder(newStopLossOrder, true);
                    newStopLossOrder = placeOrderResult.Order;
                    UpdateClosingOrder(newStopLossOrder);

                    #region Handle place-order result

                    switch (placeOrderResult.ResultType)
                    {
                    case PlaceOrderResultType.error:
                        _client.HandleErrors(placeOrderResult.Errors);
                        break;

                    case PlaceOrderResultType.success:
                        Log(LogEntryImportance.Info, "Closing order filled", true);
                        UpdateEmergencyOrder(null);
                        break;

                    case PlaceOrderResultType.partial:
                        Log(LogEntryImportance.Info, string.Format("Closing order partially filled: {0}/{1}", newStopLossOrder.VolumeExecuted, newStopLossOrder.Volume), true);
                        break;

                    case PlaceOrderResultType.txid_null:
                        Log(LogEntryImportance.Error, "An error occured while attempting to place a closing order: txid is null (unknown reason. Maybe the ValidateOnly argument was set to true)", true);
                        break;

                    case PlaceOrderResultType.canceled_not_partial:
                        Log(LogEntryImportance.Info, string.Format("The closing order was canceled: {0}", newStopLossOrder.Reason), true);
                        break;

                    case PlaceOrderResultType.exception:
                        Log(LogEntryImportance.Error, string.Format("An error occured while attempting to place a closing order: {0}", placeOrderResult.Exception.Message), true);
                        break;

                    default:
                        Log(LogEntryImportance.Error, string.Format("Unknown PlaceOrderResultType {0}", placeOrderResult.ResultType), true);
                        break;
                    }

                    #endregion
                }
                else
                {
                    Log(LogEntryImportance.Error, "Unable to cancel current closing order. Cannot shift limits", true);
                }
            }
            catch (Exception ex)
            {
                Log(LogEntryImportance.Error, string.Format("An exception occured in ShiftPositionLimits at line {0}. {1} {2}", ex.LineNumber(), ex.Message, ((ex.InnerException != null) ? ex.InnerException.Message : "")), true);
            }
        }