/// <summary> /// Create request for join two existing entry orders into a new contingency group /// </summary> private static O2GRequest JoinToNewGroupRequest(O2GSession session, string sAccountID, string sPrimaryID, string sSecondaryID, int iContingencyType) { O2GRequest request = null; O2GRequestFactory requestFactory = session.getRequestFactory(); if (requestFactory == null) { throw new Exception("Cannot create request factory"); } O2GValueMap valuemapMain = requestFactory.createValueMap(); valuemapMain.setString(O2GRequestParamsEnum.Command, Constants.Commands.JoinToNewContingencyGroup); valuemapMain.setInt(O2GRequestParamsEnum.ContingencyGroupType, iContingencyType); O2GValueMap valuemapChild; valuemapChild = requestFactory.createValueMap(); valuemapChild.setString(O2GRequestParamsEnum.OrderID, sPrimaryID); valuemapChild.setString(O2GRequestParamsEnum.AccountID, sAccountID); valuemapMain.appendChild(valuemapChild); valuemapChild = requestFactory.createValueMap(); valuemapChild.setString(O2GRequestParamsEnum.OrderID, sSecondaryID); valuemapChild.setString(O2GRequestParamsEnum.AccountID, sAccountID); valuemapMain.appendChild(valuemapChild); request = requestFactory.createOrderRequest(valuemapMain); if (request == null) { Console.WriteLine(requestFactory.getLastError()); } return(request); }
/// <summary> /// Create OTO request /// </summary> private static O2GRequest CreateOTO_ELSRequest(O2GSession session, string sOfferID, string sAccountID, int iAmount, double dRateOTO, double dRateELS, double dRateELS_stop, double dRateELS_limit) { O2GRequest request = null; O2GRequestFactory requestFactory = session.getRequestFactory(); if (requestFactory == null) { throw new Exception("Cannot create request factory"); } // Create OTO command O2GValueMap valuemapMain = requestFactory.createValueMap(); valuemapMain.setString(O2GRequestParamsEnum.Command, Constants.Commands.CreateOTO); // ValueMap for if-then O2GValueMap valuemapIf = requestFactory.createValueMap(); valuemapIf.setString(O2GRequestParamsEnum.Command, Constants.Commands.CreateOrder); valuemapIf.setString(O2GRequestParamsEnum.OrderType, Constants.Orders.LimitEntry); valuemapIf.setString(O2GRequestParamsEnum.AccountID, sAccountID); valuemapIf.setString(O2GRequestParamsEnum.OfferID, sOfferID); valuemapIf.setString(O2GRequestParamsEnum.BuySell, Constants.Sell); valuemapIf.setInt(O2GRequestParamsEnum.Amount, 0); valuemapIf.setDouble(O2GRequestParamsEnum.Rate, dRateOTO); valuemapIf.setString(O2GRequestParamsEnum.CustomID, "if-then-order"); valuemapMain.appendChild(valuemapIf); //valuemapELS for ELS order O2GValueMap valuemapELS = requestFactory.createValueMap(); valuemapELS.setString(O2GRequestParamsEnum.Command, Constants.Commands.CreateOrder); valuemapELS.setString(O2GRequestParamsEnum.OrderType, "LE"); valuemapELS.setString(O2GRequestParamsEnum.AccountID, sAccountID); valuemapELS.setString(O2GRequestParamsEnum.OfferID, sOfferID); valuemapELS.setString(O2GRequestParamsEnum.BuySell, "B"); valuemapELS.setInt(O2GRequestParamsEnum.Amount, iAmount); valuemapELS.setDouble(O2GRequestParamsEnum.Rate, dRateELS); valuemapELS.setDouble(O2GRequestParamsEnum.RateLimit, dRateELS_limit); valuemapELS.setDouble(O2GRequestParamsEnum.RateStop, dRateELS_stop); valuemapELS.setString(O2GRequestParamsEnum.CustomID, "ELS-order"); valuemapMain.appendChild(valuemapELS); request = requestFactory.createOrderRequest(valuemapMain); if (request == null) { Console.WriteLine(requestFactory.getLastError()); } return(request); }
/// <summary> /// Create request for removing order from existing contingency group /// </summary> private static O2GRequest RemoveOrderFromGroupRequest(O2GSession session, string sAccountID, string sOrderID) { O2GRequest request = null; O2GRequestFactory requestFactory = session.getRequestFactory(); if (requestFactory == null) { throw new Exception("Cannot create request factory"); } O2GValueMap valuemapMain = requestFactory.createValueMap(); valuemapMain.setString(O2GRequestParamsEnum.Command, Constants.Commands.RemoveFromContingencyGroup); O2GValueMap valuemapChild = requestFactory.createValueMap(); valuemapChild.setString(O2GRequestParamsEnum.Command, Constants.Commands.RemoveFromContingencyGroup); valuemapChild.setString(O2GRequestParamsEnum.OrderID, sOrderID); valuemapChild.setString(O2GRequestParamsEnum.AccountID, sAccountID); valuemapMain.appendChild(valuemapChild); request = requestFactory.createOrderRequest(valuemapMain); if (request == null) { Console.WriteLine(requestFactory.getLastError()); } return(request); }
/// <summary> /// Create OTO request /// </summary> private static O2GRequest CreateOTORequest(O2GSession session, string sOfferID, string sAccountID, int iAmount, double dRatePrimary, double dRateSecondary) { O2GRequest request = null; O2GRequestFactory requestFactory = session.getRequestFactory(); if (requestFactory == null) { throw new Exception("Cannot create request factory"); } O2GValueMap valuemapMain = requestFactory.createValueMap(); valuemapMain.setString(O2GRequestParamsEnum.Command, Constants.Commands.CreateOTO); // ValueMap for primary order O2GValueMap valuemapPrimary = requestFactory.createValueMap(); valuemapPrimary.setString(O2GRequestParamsEnum.Command, Constants.Commands.CreateOrder); valuemapPrimary.setString(O2GRequestParamsEnum.OrderType, Constants.Orders.StopEntry); valuemapPrimary.setString(O2GRequestParamsEnum.AccountID, sAccountID); valuemapPrimary.setString(O2GRequestParamsEnum.OfferID, sOfferID); valuemapPrimary.setString(O2GRequestParamsEnum.BuySell, Constants.Sell); valuemapPrimary.setInt(O2GRequestParamsEnum.Amount, iAmount); valuemapPrimary.setDouble(O2GRequestParamsEnum.Rate, dRatePrimary); valuemapMain.appendChild(valuemapPrimary); // ValueMap for secondary order O2GValueMap valuemapSecondary = requestFactory.createValueMap(); valuemapSecondary.setString(O2GRequestParamsEnum.Command, Constants.Commands.CreateOrder); valuemapSecondary.setString(O2GRequestParamsEnum.OrderType, Constants.Orders.StopEntry); valuemapSecondary.setString(O2GRequestParamsEnum.AccountID, sAccountID); valuemapSecondary.setString(O2GRequestParamsEnum.OfferID, sOfferID); valuemapSecondary.setString(O2GRequestParamsEnum.BuySell, Constants.Buy); valuemapSecondary.setInt(O2GRequestParamsEnum.Amount, iAmount); valuemapSecondary.setDouble(O2GRequestParamsEnum.Rate, dRateSecondary); valuemapMain.appendChild(valuemapSecondary); request = requestFactory.createOrderRequest(valuemapMain); if (request == null) { Console.WriteLine(requestFactory.getLastError()); } return(request); }
/// <summary> /// Create close all order request /// </summary> private static O2GRequest CreateCloseAllRequest(O2GSession session, Dictionary <string, CloseOrdersData> closeOrdersData) { O2GRequest request = null; O2GRequestFactory requestFactory = session.getRequestFactory(); if (requestFactory == null) { throw new Exception("Cannot create request factory"); } O2GValueMap batchValuemap = requestFactory.createValueMap(); batchValuemap.setString(O2GRequestParamsEnum.Command, Constants.Commands.CreateOrder); Dictionary <string, CloseOrdersData> .Enumerator enumerator = closeOrdersData.GetEnumerator(); while (enumerator.MoveNext()) { string sOfferID = enumerator.Current.Key; string sAccountID = enumerator.Current.Value.AccountID; OrderSide side = enumerator.Current.Value.Side; O2GValueMap childValuemap; switch (side) { case OrderSide.Buy: childValuemap = requestFactory.createValueMap(); childValuemap.setString(O2GRequestParamsEnum.Command, Constants.Commands.CreateOrder); childValuemap.setString(O2GRequestParamsEnum.NetQuantity, "Y"); childValuemap.setString(O2GRequestParamsEnum.OrderType, Constants.Orders.TrueMarketClose); childValuemap.setString(O2GRequestParamsEnum.AccountID, sAccountID); childValuemap.setString(O2GRequestParamsEnum.OfferID, sOfferID); childValuemap.setString(O2GRequestParamsEnum.BuySell, Constants.Buy); batchValuemap.appendChild(childValuemap); break; case OrderSide.Sell: childValuemap = requestFactory.createValueMap(); childValuemap.setString(O2GRequestParamsEnum.Command, Constants.Commands.CreateOrder); childValuemap.setString(O2GRequestParamsEnum.NetQuantity, "Y"); childValuemap.setString(O2GRequestParamsEnum.OrderType, Constants.Orders.TrueMarketClose); childValuemap.setString(O2GRequestParamsEnum.AccountID, sAccountID); childValuemap.setString(O2GRequestParamsEnum.OfferID, sOfferID); childValuemap.setString(O2GRequestParamsEnum.BuySell, Constants.Sell); batchValuemap.appendChild(childValuemap); break; case OrderSide.Both: childValuemap = requestFactory.createValueMap(); childValuemap.setString(O2GRequestParamsEnum.Command, Constants.Commands.CreateOrder); childValuemap.setString(O2GRequestParamsEnum.NetQuantity, "Y"); childValuemap.setString(O2GRequestParamsEnum.OrderType, Constants.Orders.TrueMarketClose); childValuemap.setString(O2GRequestParamsEnum.AccountID, sAccountID); childValuemap.setString(O2GRequestParamsEnum.OfferID, sOfferID); childValuemap.setString(O2GRequestParamsEnum.BuySell, Constants.Buy); batchValuemap.appendChild(childValuemap); childValuemap = requestFactory.createValueMap(); childValuemap.setString(O2GRequestParamsEnum.Command, Constants.Commands.CreateOrder); childValuemap.setString(O2GRequestParamsEnum.NetQuantity, "Y"); childValuemap.setString(O2GRequestParamsEnum.OrderType, Constants.Orders.TrueMarketClose); childValuemap.setString(O2GRequestParamsEnum.AccountID, sAccountID); childValuemap.setString(O2GRequestParamsEnum.OfferID, sOfferID); childValuemap.setString(O2GRequestParamsEnum.BuySell, Constants.Sell); batchValuemap.appendChild(childValuemap); break; } } request = requestFactory.createOrderRequest(batchValuemap); if (request == null) { Console.WriteLine(requestFactory.getLastError()); } return(request); }
/// <summary> /// Create OTO request /// </summary> private static O2GRequest CreateOTOCORequest(O2GSession session, string sOfferID, string sAccountID, int iAmount, double dRatePrimary, double dRateOcoFirst, double dRateOcoSecond) { O2GRequest request = null; O2GRequestFactory requestFactory = session.getRequestFactory(); if (requestFactory == null) { throw new Exception("Cannot create request factory"); } // Create OTO command O2GValueMap valuemapMain = requestFactory.createValueMap(); valuemapMain.setString(O2GRequestParamsEnum.Command, Constants.Commands.CreateOTO); // Create Entry order O2GValueMap valuemapPrimary = requestFactory.createValueMap(); valuemapPrimary.setString(O2GRequestParamsEnum.Command, Constants.Commands.CreateOrder); valuemapPrimary.setString(O2GRequestParamsEnum.OrderType, Constants.Orders.StopEntry); valuemapPrimary.setString(O2GRequestParamsEnum.AccountID, sAccountID); valuemapPrimary.setString(O2GRequestParamsEnum.OfferID, sOfferID); valuemapPrimary.setString(O2GRequestParamsEnum.BuySell, Constants.Sell); valuemapPrimary.setInt(O2GRequestParamsEnum.Amount, iAmount); valuemapPrimary.setDouble(O2GRequestParamsEnum.Rate, dRatePrimary); // Create OCO group of orders O2GValueMap valuemapOCO = requestFactory.createValueMap(); valuemapOCO.setString(O2GRequestParamsEnum.Command, Constants.Commands.CreateOCO); // Create Entry order to OCO O2GValueMap valuemapOCOFirst = requestFactory.createValueMap(); valuemapOCOFirst.setString(O2GRequestParamsEnum.Command, Constants.Commands.CreateOrder); valuemapOCOFirst.setString(O2GRequestParamsEnum.OrderType, Constants.Orders.StopEntry); valuemapOCOFirst.setString(O2GRequestParamsEnum.AccountID, sAccountID); valuemapOCOFirst.setString(O2GRequestParamsEnum.OfferID, sOfferID); valuemapOCOFirst.setString(O2GRequestParamsEnum.BuySell, Constants.Buy); valuemapOCOFirst.setInt(O2GRequestParamsEnum.Amount, iAmount); valuemapOCOFirst.setDouble(O2GRequestParamsEnum.Rate, dRateOcoFirst); O2GValueMap valuemapOCOSecond = requestFactory.createValueMap(); valuemapOCOSecond.setString(O2GRequestParamsEnum.Command, Constants.Commands.CreateOrder); valuemapOCOSecond.setString(O2GRequestParamsEnum.OrderType, Constants.Orders.StopEntry); valuemapOCOSecond.setString(O2GRequestParamsEnum.AccountID, sAccountID); valuemapOCOSecond.setString(O2GRequestParamsEnum.OfferID, sOfferID); valuemapOCOSecond.setString(O2GRequestParamsEnum.BuySell, Constants.Sell); valuemapOCOSecond.setInt(O2GRequestParamsEnum.Amount, iAmount); valuemapOCOSecond.setDouble(O2GRequestParamsEnum.Rate, dRateOcoSecond); // Fill the created groups. Please note, first you should add an entry order to OTO order and then OCO group of orders valuemapMain.appendChild(valuemapPrimary); valuemapOCO.appendChild(valuemapOCOFirst); valuemapOCO.appendChild(valuemapOCOSecond); valuemapMain.appendChild(valuemapOCO); request = requestFactory.createOrderRequest(valuemapMain); if (request == null) { Console.WriteLine(requestFactory.getLastError()); } return(request); }