static public string OpenApiOrderToString(ProtoOAOrder order) { var _str = "Order{orderId:" + order.orderId.ToString() + ", accountId:" + order.accountId + ", orderType:" + OpenApiOrderTypeToString(order.orderType); _str += ", tradeSide:" + TradeSideToString(order.tradeSide); _str += ", symbolName:" + order.symbolName + ", requestedVolume:" + order.requestedVolume.ToString() + ", executedVolume:" + order.executedVolume.ToString() + ", closingOrder:" + (order.closingOrder ? "TRUE" : "FALSE") + (order.executionPriceSpecified ? ", executionPrice:" + order.executionPrice.ToString() : "") + (order.limitPriceSpecified ? ", limitPrice:" + order.limitPrice.ToString() : "") + (order.stopPriceSpecified ? ", stopPrice:" + order.stopPrice.ToString() : "") + (order.stopLossPriceSpecified ? ", stopLossPrice:" + order.stopLossPrice.ToString() : "") + (order.takeProfitPriceSpecified ? ", takeProfitPrice:" + order.takeProfitPrice.ToString() : "") + (order.baseSlippagePriceSpecified ? ", baseSlippagePrice:" + order.baseSlippagePrice.ToString() : "") + (order.slippageInPipsSpecified ? ", slippageInPips:" + order.slippageInPips.ToString() : "") + (order.relativeStopLossInPipsSpecified ? ", relativeStopLossInPips:" + order.relativeStopLossInPips.ToString() : "") + (order.relativeTakeProfitInPipsSpecified ? ", relativeTakeProfitInPips:" + order.relativeTakeProfitInPips.ToString() : "") + (order.commissionSpecified ? ", commission:" + order.commission.ToString() : "") + (order.openTimestampSpecified ? ", openTimestamp:" + order.openTimestamp.ToString() : "") + (order.closeTimestampSpecified ? ", closeTimestamp:" + order.closeTimestamp.ToString() : "") + (order.expirationTimestampSpecified ? ", expirationTimestamp:" + order.expirationTimestamp.ToString() : "") + (order.channelSpecified ? ", channel:" + order.channel : "") + (order.commentSpecified ? ", comment:" + order.comment : "") + (order.closePositionDetails != null ? ", " + OpenApiClosePositionDetails(order.closePositionDetails) : ""); return(_str + "}"); }
static public string OpenApiOrderToString(ProtoOAOrder order) { var _str = "Order{orderId:" + order.OrderId.ToString() + ", accountId:" + order.AccountId + ", orderType:" + OpenApiOrderTypeToString(order.OrderType); _str += ", tradeSide:" + TradeSideToString(order.TradeSide); _str += ", symbolName:" + order.SymbolName + ", requestedVolume:" + order.RequestedVolume.ToString() + ", executedVolume:" + order.ExecutedVolume.ToString() + ", closingOrder:" + (order.ClosingOrder ? "TRUE" : "FALSE") + (order.HasExecutionPrice ? ", executionPrice:" + order.ExecutionPrice.ToString() : "") + (order.HasLimitPrice ? ", limitPrice:" + order.LimitPrice.ToString() : "") + (order.HasStopPrice ? ", stopPrice:" + order.StopPrice.ToString() : "") + (order.HasStopLossPrice ? ", stopLossPrice:" + order.StopLossPrice.ToString() : "") + (order.HasTakeProfitPrice ? ", takeProfitPrice:" + order.TakeProfitPrice.ToString() : "") + (order.HasBaseSlippagePrice ? ", baseSlippagePrice:" + order.BaseSlippagePrice.ToString() : "") + (order.HasSlippageInPips ? ", slippageInPips:" + order.SlippageInPips.ToString() : "") + (order.HasRelativeStopLossInPips ? ", relativeStopLossInPips:" + order.RelativeStopLossInPips.ToString() : "") + (order.HasRelativeTakeProfitInPips ? ", relativeTakeProfitInPips:" + order.RelativeTakeProfitInPips.ToString() : "") + (order.HasCommission ? ", commission:" + order.Commission.ToString() : "") + (order.HasOpenTimestamp ? ", openTimestamp:" + order.OpenTimestamp.ToString() : "") + (order.HasCloseTimestamp ? ", closeTimestamp:" + order.CloseTimestamp.ToString() : "") + (order.HasExpirationTimestamp ? ", expirationTimestamp:" + order.ExpirationTimestamp.ToString() : "") + (order.HasChannel ? ", channel:" + order.Channel : "") + (order.HasComment ? ", comment:" + order.Comment : "") + (order.HasClosePositionDetails ? ", " + OpenApiClosePositionDetails(order.ClosePositionDetails) : ""); return(_str + "}"); }
public ProtoMessage CreateExecutionEvent(ProtoOAExecutionType executionType, ProtoOAOrder order, ProtoOAPosition position = null, string reasonCode = null, string clientMsgId = null) { var _msg = ProtoOAExecutionEvent.CreateBuilder(); _msg.SetExecutionType(executionType); _msg.SetOrder(order); if (position != null) { _msg.SetPosition(position); } return(CreateMessage((uint)_msg.PayloadType, _msg.Build().ToByteString(), clientMsgId)); }
public ProtoMessage CreateExecutionEvent(ProtoOAExecutionType executionType, ProtoOAOrder order, ProtoOAPosition position = null, string reasonCode = null, string clientMsgId = null) { var _msg = new ProtoOAExecutionEvent(); _msg.executionType = executionType; _msg.order = order; if (position != null) { _msg.position = position; } if (reasonCode != null) { _msg.reasonCode = reasonCode; } return(CreateMessage((uint)_msg.payloadType, Utils.Serialize <ProtoOAExecutionEvent>(_msg), clientMsgId)); }
static public string GetOrderText(ProtoOAOrder order) { var _str = "Order{orderId:" + order.OrderId.ToString() + ", orderType:" + order.OrderType; _str += ", tradeSide:" + order.TradeData.TradeSide; _str += ", symbolName:" + order.TradeData.SymbolId + ", requestedVolume:" + order.TradeData.Volume.ToString() + ", executedVolume:" + order.ExecutedVolume.ToString() + ", closingOrder:" + (order.ClosingOrder ? "TRUE" : "FALSE") + (order.HasExecutionPrice ? ", executionPrice:" + order.ExecutionPrice.ToString() : "") + (order.HasLimitPrice ? ", limitPrice:" + order.LimitPrice.ToString() : "") + (order.HasStopPrice ? ", stopPrice:" + order.StopPrice.ToString() : "") + (order.HasStopLoss ? ", stopLossPrice:" + order.StopLoss.ToString() : "") + (order.HasTakeProfit ? ", takeProfitPrice:" + order.TakeProfit.ToString() : "") + (order.HasBaseSlippagePrice ? ", baseSlippagePrice:" + order.BaseSlippagePrice.ToString() : "") + (order.HasSlippageInPoints ? ", slippageInPoints:" + order.SlippageInPoints.ToString() : "") + (order.HasRelativeStopLoss ? ", relativeStopLoss:" + order.RelativeStopLoss.ToString() : "") + (order.HasRelativeTakeProfit ? ", relativeTakeProfit:" + order.RelativeTakeProfit.ToString() : "") + (order.HasExpirationTimestamp ? ", expirationTimestamp:" + order.ExpirationTimestamp.ToString() : ""); return(_str + "}"); }
//public ProtoOASpotSubscription GetSpotSubscription(byte[] obj = null) //{ // return ProtoOASpotSubscription.CreateBuilder().MergeFrom(obj).Build(); //} #endregion #region Creating new Proto Model objects with parameters specified public ProtoOAOrder.Builder CreateOrderBuilder(long orderId, long accountId, ProtoOAOrderType orderType, ProtoOATradeSide tradeSide, int symbolId, long requestedVolume, long executedVolume, bool closingOrder, string channel = null, string comment = null) { var _obj = ProtoOAOrder.CreateBuilder(); var _objTradeData = ProtoOATradeData.CreateBuilder(); _objTradeData.SetTradeSide(tradeSide); _objTradeData.SetSymbolId(symbolId); _objTradeData.SetVolume(requestedVolume); _obj.SetOrderId(orderId); // _obj.SetAccountId(accountId); _obj.SetOrderType(orderType); _obj.SetTradeData(_objTradeData); _obj.SetExecutedVolume(executedVolume); _obj.SetClosingOrder(closingOrder); //if (channel != null) // _obj.SetChannel(channel); //if (comment != null) // _obj.SetComment(comment); return(_obj); }
public ProtoOAOrder CreateOrder(long orderId, long accountId, ProtoOAOrderType orderType, ProtoTradeSide tradeSide, string symbolName, long requestedVolume, long executedVolume, bool closingOrder, string channel = null, string comment = null) { var _obj = new ProtoOAOrder(); _obj.orderId = orderId; _obj.accountId = accountId; _obj.orderType = orderType; _obj.tradeSide = tradeSide; _obj.symbolName = symbolName; _obj.requestedVolume = requestedVolume; _obj.executedVolume = executedVolume; _obj.closingOrder = closingOrder; if (channel != null) { _obj.channel = channel; } if (comment != null) { _obj.comment = comment; } return(_obj); }
public ProtoOAOrder GetOrder(byte[] obj = null) { return(ProtoOAOrder.CreateBuilder().MergeFrom(obj).Build()); }
public MainPage() { this.plotView = createChartPanel(); this.buyButton = new TradingButton("Buy"); this.sellButton = new TradingButton("Sell"); this.Content = new StackLayout { Orientation = StackOrientation.Vertical, HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.FillAndExpand, Children = { createTopPanel(), this.plotView, createBottomPanel() } }; // Using messaging center to ensure that content only gets loaded once authentication is successful. // Once Xamarin.Forms adds more support for view life cycle events, this kind of thing won't be as necessary. // The OnAppearing() and OnDisappearing() overrides just don't quite cut the mustard yet, nor do the Appearing and Disappearing delegates. MessagingCenter.Subscribe <App> (this, "Authenticated", (sender) => { accountsAPI = new AccountsAPI(App.ACCOUNTS_API_HOST_URL, App.Instance.Token); tradingAPI = new TradingAPI(App.TRADING_API_HOST, App.TRADING_API_PORT, App.Instance.Token, App.CLIENT_ID, App.CLIENT_SECRET); fillAccounts(); fillSymbols(); refreshPlotView(); tradingAPI.Start(); tradingAPI.ExecutionEvent += (executionEvent) => { Device.BeginInvokeOnMainThread(() => { String filledTitle = "Order Filled at {0}"; String filledMessage = "Your request to {0} {1} of {2} was filled at VWAP {3}"; if (executionEvent.executionType == ProtoOAExecutionType.OA_ORDER_FILLED) { ProtoOAOrder order = executionEvent.order; string title = String.Format(filledTitle, order.executionPrice); string message = String.Format(filledMessage, order.tradeSide, order.requestedVolume / 100, order.symbolName, order.executionPrice); DisplayAlert(title, message, "Close"); } }); }; tradingAPI.SpotEvent += (spotEvent) => { if (spotEvent.symbolName.Equals(currentSymbol.SymbolName)) { if (spotEvent.askPriceSpecified) { LineAnnotation annotation = (LineAnnotation)plotView.Model.Annotations[0]; annotation.Y = spotEvent.askPrice; annotation.Text = spotEvent.askPrice.ToString(); } Device.BeginInvokeOnMainThread(() => { if (spotEvent.askPriceSpecified) { buyButton.setPrice(spotEvent.askPrice); plotView.Model.InvalidatePlot(true); } if (spotEvent.bidPriceSpecified) { sellButton.setPrice(spotEvent.bidPrice); } }); } }; tradingAPI.SendSubscribeForTradingEventsRequest(currentTradingAccount.AccountId); tradingAPI.SendSubscribeForSpotsRequest(currentTradingAccount.AccountId, currentSymbol.SymbolName); }); }
public PendingOrderModel(ProtoOAOrder order, SymbolModel symbol) => Update(order, symbol);