// Change subscription status public void CreateSetSubscriptionStatusRequest(string sOfferID, string sStatus) { O2GRequestFactory factory = Session.getRequestFactory(); O2GValueMap valuemap = factory.createValueMap(); valuemap.setString(O2GRequestParamsEnum.Command, Constants.Commands.SetSubscriptionStatus); valuemap.setString(O2GRequestParamsEnum.OfferID, sOfferID); valuemap.setString(O2GRequestParamsEnum.SubscriptionStatus, sStatus); O2GRequest request = factory.createOrderRequest(valuemap); if (request != null) { try { mRequestID = request.RequestID; Session.sendRequest(request); } catch (Exception subErr) { Console.WriteLine(subErr); } } else { Console.WriteLine("Cannot create request; probably some arguments are missing or incorrect"); } }
/// <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 entry order request /// </summary> private static O2GRequest CreateEntryOrderRequest(O2GSession session, string sOfferID, string sAccountID, int iAmount, double dRate, string sBuySell, string sOrderType, string sExpireDate) { O2GRequest request = null; O2GRequestFactory requestFactory = session.getRequestFactory(); if (requestFactory == null) { throw new Exception("Cannot create request factory"); } O2GValueMap valuemap = requestFactory.createValueMap(); valuemap.setString(O2GRequestParamsEnum.Command, Constants.Commands.CreateOrder); valuemap.setString(O2GRequestParamsEnum.OrderType, sOrderType); valuemap.setString(O2GRequestParamsEnum.AccountID, sAccountID); valuemap.setString(O2GRequestParamsEnum.OfferID, sOfferID); valuemap.setString(O2GRequestParamsEnum.BuySell, sBuySell); valuemap.setInt(O2GRequestParamsEnum.Amount, iAmount); valuemap.setDouble(O2GRequestParamsEnum.Rate, dRate); valuemap.setString(O2GRequestParamsEnum.CustomID, "EntryOrder"); if (!string.IsNullOrEmpty(sExpireDate)) { valuemap.setString(O2GRequestParamsEnum.TimeInForce, Constants.TIF.GTD); valuemap.setString(O2GRequestParamsEnum.ExpireDayTime, sExpireDate); // UTCTimestamp format: "yyyyMMdd-HH:mm:ss.SSS" (milliseconds are optional) } request = requestFactory.createOrderRequest(valuemap); if (request == null) { Console.WriteLine(requestFactory.getLastError()); } return(request); }
/***************************************************************************************************************/ /***** TRUE MARKET ORDERS *****/ /***************************************************************************************************************/ /* True Market Order */ public void CreateTrueMarketOrder(string sOfferID, string sAccountID, int iAmount, string sBuySell) { try { O2GRequestFactory factory = m_o2gsession.getRequestFactory(); if (factory == null) { return; } O2GValueMap valuemap = factory.createValueMap(); valuemap.setString(O2GRequestParamsEnum.Command, Constants.Commands.CreateOrder); valuemap.setString(O2GRequestParamsEnum.OrderType, Constants.Orders.TrueMarketOpen); valuemap.setString(O2GRequestParamsEnum.AccountID, sAccountID); // The identifier of the account the order should be placed for. valuemap.setString(O2GRequestParamsEnum.OfferID, sOfferID); // The identifier of the instrument the order should be placed for. valuemap.setString(O2GRequestParamsEnum.BuySell, sBuySell); // The order direction: Constants.Sell for "Sell", Constants.Buy for "Buy". valuemap.setInt(O2GRequestParamsEnum.Amount, iAmount); // The quantity of the instrument to be bought or sold. valuemap.setString(O2GRequestParamsEnum.CustomID, "TrueMarketOrder"); // The custom identifier of the order. if (sBuySell == "Buy") { valuemap.setString(O2GRequestParamsEnum.BuySell, Constants.Buy); } else { valuemap.setString(O2GRequestParamsEnum.BuySell, Constants.Sell); } O2GRequest request = factory.createOrderRequest(valuemap); m_o2gsession.sendRequest(request); } catch { } }
/// <summary> /// Update margin requirements /// </summary> /// <param name="session"></param> /// <param name="responseListener"></param> private static void UpdateMargins(O2GSession session, ResponseListener responseListener) { O2GRequest request = null; O2GRequestFactory requestFactory = session.getRequestFactory(); if (requestFactory == null) { throw new Exception("Cannot create request factory"); } O2GValueMap valueMap = requestFactory.createValueMap(); valueMap.setString(O2GRequestParamsEnum.Command, Constants.Commands.UpdateMarginRequirements); request = requestFactory.createOrderRequest(valueMap); responseListener.SetRequestID(request.RequestID); session.sendRequest(request); if (!responseListener.WaitEvents()) { throw new Exception("Response waiting timeout expired"); } O2GResponse response = responseListener.GetResponse(); if (response != null && response.Type == O2GResponseType.MarginRequirementsResponse) { O2GResponseReaderFactory responseFactory = session.getResponseReaderFactory(); if (responseFactory != null) { responseFactory.processMarginRequirementsResponse(response); Console.WriteLine("Margin requirements have been updated"); } } }
/// <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> /// Attach L or S order to existing entry order /// </summary> private static O2GRequest AddOrderForEntryRequest(O2GSession session, O2GTradeRow trade, string sOrderType, double dRate) { if (!sOrderType.Equals("L") && !sOrderType.Equals("S")) { throw new Exception("Incorrect order type"); } O2GRequest request = null; O2GRequestFactory requestFactory = session.getRequestFactory(); if (requestFactory == null) { throw new Exception("Cannot create request factory"); } O2GValueMap valuemap = requestFactory.createValueMap(); valuemap.setString(O2GRequestParamsEnum.Command, Constants.Commands.CreateOrder); valuemap.setString(O2GRequestParamsEnum.OrderType, sOrderType); // Must be L or S valuemap.setString(O2GRequestParamsEnum.AccountID, trade.AccountID); valuemap.setString(O2GRequestParamsEnum.OfferID, trade.OfferID); valuemap.setString(O2GRequestParamsEnum.TradeID, trade.TradeID); // TradeID from existing Entry order string sOppositeDirection = trade.BuySell == Constants.Buy ? Constants.Sell : Constants.Buy; valuemap.setString(O2GRequestParamsEnum.BuySell, sOppositeDirection); // The order direction must be opposite to the direction of the order which was used to create the position valuemap.setInt(O2GRequestParamsEnum.Amount, trade.Amount); valuemap.setDouble(O2GRequestParamsEnum.Rate, dRate); valuemap.setString(O2GRequestParamsEnum.CustomID, "AttachedEntryOrder"); request = requestFactory.createOrderRequest(valuemap); if (request == null) { Console.WriteLine(requestFactory.getLastError()); } return(request); }
/// <summary> /// Create entry order request /// </summary> private static O2GRequest CreateNetEntryOrderRequest(O2GSession session, string sOfferID, string sAccountID, double dRate, string sBuySell, string sOrderType) { O2GRequest request = null; O2GRequestFactory requestFactory = session.getRequestFactory(); if (requestFactory == null) { throw new Exception("Cannot create request factory"); } O2GValueMap valuemap = requestFactory.createValueMap(); valuemap.setString(O2GRequestParamsEnum.Command, Constants.Commands.CreateOrder); valuemap.setString(O2GRequestParamsEnum.OrderType, sOrderType); valuemap.setString(O2GRequestParamsEnum.AccountID, sAccountID); valuemap.setString(O2GRequestParamsEnum.OfferID, sOfferID); valuemap.setString(O2GRequestParamsEnum.BuySell, sBuySell); valuemap.setString(O2GRequestParamsEnum.NetQuantity, "Y"); valuemap.setDouble(O2GRequestParamsEnum.Rate, dRate); valuemap.setString(O2GRequestParamsEnum.CustomID, "EntryOrder"); request = requestFactory.createOrderRequest(valuemap); if (request == null) { Console.WriteLine(requestFactory.getLastError()); } return(request); }
public void CreateRangeCloseOrder(string sOfferID, string sAccountID, string sTradeID, int iAmount, double dRateMin, double dRateMax, string sBuySell) { O2GRequestFactory factory = m_o2gsession.getRequestFactory(); if (factory == null) { return; } O2GValueMap valuemap = factory.createValueMap(); valuemap.setString(O2GRequestParamsEnum.Command, Constants.Commands.CreateOrder); valuemap.setString(O2GRequestParamsEnum.OrderType, Constants.Orders.MarketCloseRange); valuemap.setString(O2GRequestParamsEnum.AccountID, sAccountID); valuemap.setString(O2GRequestParamsEnum.OfferID, sOfferID); // The identifier of the instrument the order should be placed for. valuemap.setString(O2GRequestParamsEnum.TradeID, sTradeID); // The identifier of the trade to be closed. valuemap.setString(O2GRequestParamsEnum.BuySell, sBuySell); // The order direction (Constants.Buy for Buy, Constants.Sell for Sell). Must be opposite to the direction of the trade. valuemap.setInt(O2GRequestParamsEnum.Amount, iAmount); // The quantity of the instrument to be bought or sold. Must be <= size of the position (Lot of the trade). Must be divisible by baseUnitSize. valuemap.setDouble(O2GRequestParamsEnum.RateMin, dRateMin); // The minimum dRate at which the order can be filled. valuemap.setDouble(O2GRequestParamsEnum.RateMax, dRateMax); // The maximum dRate at which the order can be filled. valuemap.setString(O2GRequestParamsEnum.CustomID, "CloseRangeOrder"); // The custom identifier of the order. O2GRequest request = factory.createOrderRequest(valuemap); m_o2gsession.sendRequest(request); SaveOrders(sOfferID, sAccountID, sTradeID, iAmount, sBuySell); }
/// <summary> /// Create GetLastOrderUpdate request /// </summary> /// <param name="session"></param> /// <param name="sOrderID"></param> /// <param name="sAccountName"></param> /// <returns></returns> private static O2GRequest GetLastOrderUpdateRequest(O2GSession session, string sOrderID, string sAccountName) { O2GRequest request = null; O2GRequestFactory requestFactory = session.getRequestFactory(); if (requestFactory == null) { throw new Exception("Cannot create request factory"); } O2GValueMap valuemap = requestFactory.createValueMap(); valuemap.setString(O2GRequestParamsEnum.Command, Constants.Commands.GetLastOrderUpdate); valuemap.setString(O2GRequestParamsEnum.Key, Constants.KeyType.OrderID); valuemap.setString(O2GRequestParamsEnum.Id, sOrderID); // value of Key valuemap.setString(O2GRequestParamsEnum.AccountName, sAccountName); // Account name, not Account ID request = requestFactory.createOrderRequest(valuemap); 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> /// Subscribe or unsubscribe an instrument /// </summary> private static O2GRequest CreateSetSubscriptionStatusRequest(O2GSession session, string sOfferID, string sStatus, ResponseListener responseListener) { O2GRequest request = null; O2GRequestFactory requestFactory = session.getRequestFactory(); if (requestFactory == null) { throw new Exception("Cannot create request factory"); } O2GValueMap valueMap = requestFactory.createValueMap(); valueMap.setString(O2GRequestParamsEnum.Command, Constants.Commands.SetSubscriptionStatus); valueMap.setString(O2GRequestParamsEnum.SubscriptionStatus, sStatus); valueMap.setString(O2GRequestParamsEnum.OfferID, sOfferID); request = requestFactory.createOrderRequest(valueMap); if (request == null) { Console.WriteLine(requestFactory.getLastError()); } return(request); }
// Place live market OPEN order public void CreateTrueOpenMarketOrder(string sOfferID, string sAccountID, int iAmount, string sBuySell) { try { O2GRequestFactory factory = Session.getRequestFactory(); O2GValueMap valuemap = factory.createValueMap(); valuemap.setString(O2GRequestParamsEnum.Command, Constants.Commands.CreateOrder); valuemap.setString(O2GRequestParamsEnum.OrderType, Constants.Orders.TrueMarketOpen); // The identifier of the account the order should be placed for. valuemap.setString(O2GRequestParamsEnum.AccountID, sAccountID); // The identifier of the instrument the order should be placed for. valuemap.setString(O2GRequestParamsEnum.OfferID, sOfferID); // The order direction: Constants.Sell for "Sell", Constants.Buy for "Buy". valuemap.setString(O2GRequestParamsEnum.BuySell, sBuySell); // The quantity of the instrument to be bought or sold. valuemap.setInt(O2GRequestParamsEnum.Amount, iAmount); // The custom identifier of the order. valuemap.setString(O2GRequestParamsEnum.CustomID, "TrueMarketOrder"); O2GRequest request = factory.createOrderRequest(valuemap); if (request != null) { mRequestID = request.RequestID; Session.sendRequest(request); } else { Console.WriteLine("Cannot create request; probably some arguments are missing or incorrect"); } } catch (Exception openErr) { Console.WriteLine(openErr); } }
/// <summary> /// Create true market order request /// </summary> private static O2GRequest CreateTrueMarketOrderRequest(O2GSession session, string sOfferID, string sAccountID, int iAmount, string sBuySell) { O2GRequest request = null; O2GRequestFactory requestFactory = session.getRequestFactory(); if (requestFactory == null) { throw new Exception("Cannot create request factory"); } O2GValueMap valuemap = requestFactory.createValueMap(); valuemap.setString(O2GRequestParamsEnum.Command, Constants.Commands.CreateOrder); valuemap.setString(O2GRequestParamsEnum.OrderType, Constants.Orders.TrueMarketOpen); valuemap.setString(O2GRequestParamsEnum.AccountID, sAccountID); valuemap.setString(O2GRequestParamsEnum.OfferID, sOfferID); valuemap.setString(O2GRequestParamsEnum.BuySell, sBuySell); valuemap.setInt(O2GRequestParamsEnum.Amount, iAmount); valuemap.setString(O2GRequestParamsEnum.CustomID, "TrueMarketOrder"); request = requestFactory.createOrderRequest(valuemap); if (request == null) { Console.WriteLine(requestFactory.getLastError()); } return(request); }
/// <summary> /// Remove order request /// </summary> private static O2GRequest RemoveOrderRequest(O2GSession session, string accountID, string orderID) { O2GRequest request = null; O2GRequestFactory requestFactory = session.getRequestFactory(); if (requestFactory == null) { throw new Exception("Cannot create request factory"); } O2GValueMap valuemap = requestFactory.createValueMap(); valuemap.setString(O2GRequestParamsEnum.Command, Constants.Commands.DeleteOrder); valuemap.setString(O2GRequestParamsEnum.AccountID, accountID); valuemap.setString(O2GRequestParamsEnum.OrderID, orderID); valuemap.setString(O2GRequestParamsEnum.CustomID, "RemoveEntryOrder"); request = requestFactory.createOrderRequest(valuemap); 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); }
public static bool ChangeStop(this FxcmBroker fxcm, string stopOrderId, double rateStop) { if (fxcm.Status != ConnectStatus.Connected) { Log.Error("FXCM not connected"); return(false); } O2GRequestFactory requestFactory = fxcm.Session.getRequestFactory(); if (requestFactory == null) { throw new Exception("Cannot create request factory"); } var account = GetAccount(fxcm.Session); O2GValueMap valuemap = requestFactory.createValueMap(); valuemap.setString(O2GRequestParamsEnum.Command, Constants.Commands.EditOrder); valuemap.setString(O2GRequestParamsEnum.OrderType, Constants.Orders.Stop); valuemap.setString(O2GRequestParamsEnum.AccountID, account.AccountID); valuemap.setString(O2GRequestParamsEnum.OrderID, stopOrderId); valuemap.setDouble(O2GRequestParamsEnum.Rate, rateStop); var request = requestFactory.createOrderRequest(valuemap); if (request == null) { Log.Error($"Unable to process request - {requestFactory.getLastError()}"); return(false); } var ret = ProcessRequest(fxcm, request); return(ret); }
/// <summary> /// Create close market order request /// </summary> private static O2GRequest CreateCloseMarketOrderRequest(O2GSession session, string sInstrument, O2GTradeRow tradeRow) { O2GRequest request = null; O2GRequestFactory requestFactory = session.getRequestFactory(); if (requestFactory == null) { throw new Exception("Cannot create request factory"); } O2GLoginRules loginRules = session.getLoginRules(); O2GPermissionChecker permissionChecker = loginRules.getPermissionChecker(); O2GValueMap valuemap = requestFactory.createValueMap(); valuemap.setString(O2GRequestParamsEnum.Command, Constants.Commands.CreateOrder); if (permissionChecker.canCreateMarketCloseOrder(sInstrument) != O2GPermissionStatus.PermissionEnabled) { valuemap.setString(O2GRequestParamsEnum.OrderType, Constants.Orders.TrueMarketOpen); // in USA you need to use "OM" to close a position. } else { valuemap.setString(O2GRequestParamsEnum.OrderType, Constants.Orders.TrueMarketClose); valuemap.setString(O2GRequestParamsEnum.TradeID, tradeRow.TradeID); } valuemap.setString(O2GRequestParamsEnum.AccountID, tradeRow.AccountID); valuemap.setString(O2GRequestParamsEnum.OfferID, tradeRow.OfferID); valuemap.setString(O2GRequestParamsEnum.BuySell, tradeRow.BuySell.Equals(Constants.Buy) ? Constants.Sell : Constants.Buy); valuemap.setInt(O2GRequestParamsEnum.Amount, tradeRow.Amount); valuemap.setString(O2GRequestParamsEnum.CustomID, "CloseMarketOrder"); request = requestFactory.createOrderRequest(valuemap); if (request == null) { Console.WriteLine(requestFactory.getLastError()); } return(request); }
public void CreateTrueMarketCloseOrder(string sOfferID, string sAccountID, string sTradeID, int iAmount, string sBuySell) { O2GRequestFactory factory = _session.Session.getRequestFactory(); O2GValueMap valuemap = factory.createValueMap(); valuemap.setString(O2GRequestParamsEnum.Command, Constants.Commands.CreateOrder); valuemap.setString(O2GRequestParamsEnum.OrderType, Constants.Order.TrueMarketClose); valuemap.setString(O2GRequestParamsEnum.AccountID, sAccountID); // The identifier of the account the order should be placed for. valuemap.setString(O2GRequestParamsEnum.OfferID, sOfferID); // The identifier of the instrument the order should be placed for. // valuemap.setString(O2GRequestParamsEnum.TradeID, sTradeID); // The identifier of the trade to be closed. // valuemap.setInt(O2GRequestParamsEnum.Amount, iAmount); // The quantity of the instrument to be bought or sold. Must be <= to the size of the position ("Trades" table, Lot column). valuemap.setString(O2GRequestParamsEnum.NetQuantity, "Y"); valuemap.setString(O2GRequestParamsEnum.BuySell, (sBuySell.Equals("Buy")?Constants.Buy:Constants.Sell)); // The order direction: Constants.Buy for Buy, Constants.Sell for Sell. Must be opposite to the direction of the trade. valuemap.setString(O2GRequestParamsEnum.CustomID, "CloseTrueMarketOrder"); // The custom identifier of the order. O2GRequest request = factory.createOrderRequest(valuemap); _session.Session.sendRequest(request); }
public void CreateTrueMarketOrder(string accountID, string sOfferID, int iAmount, string sBuySell) { O2GRequestFactory factory = _session.Session.getRequestFactory(); O2GValueMap valuemap = factory.createValueMap(); valuemap.setString(O2GRequestParamsEnum.Command, Constants.Commands.CreateOrder); valuemap.setString(O2GRequestParamsEnum.OrderType, Constants.Order.TrueMarketOpen); valuemap.setString(O2GRequestParamsEnum.AccountID, accountID); // The identifier of the account the order should be placed for. valuemap.setString(O2GRequestParamsEnum.OfferID, sOfferID); // The identifier of the instrument the order should be placed for. valuemap.setString(O2GRequestParamsEnum.BuySell, (sBuySell.Equals("Buy")?Constants.Buy:Constants.Sell)); // The order direction: Constants.Sell for "Sell", Constants.Buy for "Buy". valuemap.setInt(O2GRequestParamsEnum.Amount, iAmount); // The quantity of the instrument to be bought or sold. valuemap.setString(O2GRequestParamsEnum.CustomID, "TrueMarketOrder"); // The custom identifier of the order. O2GRequest request = factory.createOrderRequest(valuemap); _session.Session.sendRequest(request); }
public void CreateTrueMarketCloseOrder(string sOfferID, string sAccountID, string sTradeID, int iAmount, string sBuySell) { O2GRequestFactory factory = m_o2gsession.getRequestFactory(); if (factory == null) { return; } O2GValueMap valuemap = factory.createValueMap(); valuemap.setString(O2GRequestParamsEnum.Command, Constants.Commands.CreateOrder); valuemap.setString(O2GRequestParamsEnum.OrderType, Constants.Orders.TrueMarketClose); valuemap.setString(O2GRequestParamsEnum.AccountID, sAccountID); // The identifier of the account the order should be placed for. valuemap.setString(O2GRequestParamsEnum.OfferID, sOfferID); // The identifier of the instrument the order should be placed for. valuemap.setString(O2GRequestParamsEnum.NetQuantity, "Y"); valuemap.setString(O2GRequestParamsEnum.BuySell, sBuySell); // The order direction: Constants.Buy for Buy, Constants.Sell for Sell. Must be opposite to the direction of the trade. valuemap.setString(O2GRequestParamsEnum.CustomID, "CloseTrueMarketOrder"); // The custom identifier of the order. O2GRequest request = factory.createOrderRequest(valuemap); m_o2gsession.sendRequest(request); SaveOrders(sOfferID, sAccountID, sTradeID, iAmount, sBuySell); }
// Place live market CLOSE order public void CreateTrueCloseMarketOrder(string sOfferID, string sAccountID, string sTradeID, int iAmount, string sBuySell) { try { Console.WriteLine("CLOSING ORDER"); O2GRequestFactory factory = mSession.getRequestFactory(); if (factory == null) { return; } Console.WriteLine("Factory not null"); Console.WriteLine("sOfferID: " + sOfferID); Console.WriteLine("sAccountID: " + sAccountID); Console.WriteLine("sTradeID: " + sTradeID); Console.WriteLine("iAmount: " + iAmount); Console.WriteLine("dRate: " + dRate); Console.WriteLine("sBuySell: " + sBuySell); O2GValueMap valuemap = factory.createValueMap(); valuemap.setString(O2GRequestParamsEnum.Command, Constants.Commands.CreateOrder); valuemap.setString(O2GRequestParamsEnum.OrderType, Constants.Orders.TrueMarketClose); valuemap.setString(O2GRequestParamsEnum.AccountID, sAccountID); valuemap.setString(O2GRequestParamsEnum.OfferID, sOfferID); valuemap.setString(O2GRequestParamsEnum.NetQuantity, "Y"); valuemap.setString(O2GRequestParamsEnum.BuySell, sBuySell); valuemap.setString(O2GRequestParamsEnum.CustomID, "CloseTrueMarketOrder"); O2GRequest request = factory.createOrderRequest(valuemap); mSession.sendRequest(request); } catch (Exception closeErr) { Console.WriteLine(closeErr); } }
/***************************************************************************************************************/ /***************************************************************************************************************/ /***** OPEN ORDERS *****/ /***************************************************************************************************************/ /* Open Order (Market Order) */ public void CreateMarketOrder(string sOfferID, string sAccountID, int iAmount, double dRate, string sBuySell) { O2GRequestFactory factory = m_o2gsession.getRequestFactory(); if (factory == null) { return; } O2GValueMap valuemap = factory.createValueMap(); valuemap.setString(O2GRequestParamsEnum.Command, Constants.Commands.CreateOrder); valuemap.setString(O2GRequestParamsEnum.OrderType, Constants.Orders.MarketOpen); valuemap.setString(O2GRequestParamsEnum.AccountID, sAccountID); // The identifier of the account the order should be placed for. valuemap.setString(O2GRequestParamsEnum.OfferID, sOfferID); // The identifier of the instrument the order should be placed for. valuemap.setString(O2GRequestParamsEnum.BuySell, sBuySell); // The order direction (use Constants.Buy for Buy, Constants.Sell for Sell) valuemap.setDouble(O2GRequestParamsEnum.Rate, dRate); // The dRate at which the order must be filled. valuemap.setInt(O2GRequestParamsEnum.Amount, iAmount); // The quantity of the instrument to be bought or sold. valuemap.setString(O2GRequestParamsEnum.CustomID, "OpenMarketOrder"); // The custom identifier of the order. O2GRequest request = factory.createOrderRequest(valuemap); m_o2gsession.sendRequest(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); }
public static bool CreateMarketOrder(this FxcmBroker fxcm, string instrument, int lotsAmount, TradeDirection direction, out string orderId, double?rateStop = null, double?rateLimit = null) { orderId = string.Empty; if (fxcm.Status != ConnectStatus.Connected) { Log.Error("FXCM not connected"); return(false); } O2GOfferRow offer = GetOffer(fxcm.Session, instrument); if (offer == null) { throw new Exception(string.Format("The instrument '{0}' is not valid", instrument)); } O2GRequest request = null; O2GRequestFactory requestFactory = fxcm.Session.getRequestFactory(); if (requestFactory == null) { throw new Exception("Cannot create request factory"); } var account = GetAccount(fxcm.Session); O2GValueMap valuemap = requestFactory.createValueMap(); valuemap.setString(O2GRequestParamsEnum.Command, Constants.Commands.CreateOrder); valuemap.setString(O2GRequestParamsEnum.OrderType, Constants.Orders.TrueMarketOpen); valuemap.setString(O2GRequestParamsEnum.AccountID, account.AccountID); valuemap.setString(O2GRequestParamsEnum.OfferID, offer.OfferID); valuemap.setString(O2GRequestParamsEnum.BuySell, direction == TradeDirection.Long ? "B" : "S"); if (rateStop != null) { valuemap.setDouble(O2GRequestParamsEnum.RateStop, rateStop.Value); } if (rateLimit != null) { valuemap.setDouble(O2GRequestParamsEnum.RateLimit, rateLimit.Value); } // Get account var loginRules = fxcm.Session.getLoginRules(); var tradingSettingsProvider = loginRules.getTradingSettingsProvider(); int iBaseUnitSize = tradingSettingsProvider.getBaseUnitSize(instrument, account); int iAmount = iBaseUnitSize * lotsAmount; valuemap.setInt(O2GRequestParamsEnum.Amount, iAmount); valuemap.setString(O2GRequestParamsEnum.CustomID, "TrueMarketOrder"); request = requestFactory.createOrderRequest(valuemap); if (request == null) { Log.Error($"Unable to process request - {requestFactory.getLastError()}"); return(false); } var ret = ProcessOrderRequest(fxcm, request, out orderId); return(ret); }