public void Issue42() { var rpcClient = BuildRpcClient(); var param = new NewStopLimitOrderRequestDTO { OrderId = 0, MarketId = 99498, Currency = null, AutoRollover = false, Direction = "buy", Quantity = 10m, BidPrice = 12094m, OfferPrice = 12098m, AuditId = "20110629-G2PREPROD3-0102794", TradingAccountId = 400002249, IfDone = null, OcoOrder = null, Applicability = null, ExpiryDateTimeUTC = null, Guaranteed = false, TriggerPrice = 0m }; var response = rpcClient.TradesAndOrders.Order(param); rpcClient.LogOut(); }
public void TestAddStopOrder() { var accountInfo = _client.AccountInformation.GetClientAndTradingAccount(); var orders = _client.TradesAndOrders.ListActiveStopLimitOrders(accountInfo.SpreadBettingAccount.TradingAccountId); const int orderId = 472307456; var order = _client.TradesAndOrders.GetOrder(orderId.ToString()).StopLimitOrder; var request = new NewStopLimitOrderRequestDTO { OrderId = orderId, TradingAccountId = order.TradingAccountId, Direction = "sell", MarketId = order.MarketId, Quantity = order.Quantity, OfferPrice = 5720, TriggerPrice = 5720, }; var resp = _client.TradesAndOrders.Order(request); _client.MagicNumberResolver.ResolveMagicNumbers(resp); }
/// <summary> /// Place an order on a particular market. Do not set any order ID fields when requesting a new order, the platform will generate them. /// </summary> /// <param name="order">The order request.</param> /// <param name="callback"></param> /// <param name="state"></param> public virtual void BeginOrder(NewStopLimitOrderRequestDTO order, ReliableAsyncCallback callback, object state) { string uriTemplate = "/newstoplimitorder"; _client.BeginRequest(RequestMethod.POST, "order", uriTemplate , new Dictionary<string, object> { { "order", order} },ContentType.JSON,ContentType.JSON, TimeSpan.FromMilliseconds(0), 30000,0 ,callback, state); }
// *********************************** // Order // *********************************** /// <summary> /// Place an order on a particular market. Do not set any order ID fields when requesting a new order, the platform will generate them. /// </summary> /// <param name="order">The order request.</param> public virtual ApiTradeOrderResponseDTO Order(NewStopLimitOrderRequestDTO order) { string uriTemplate = "/newstoplimitorder"; return _client.Request<ApiTradeOrderResponseDTO>(RequestMethod.POST,"order", uriTemplate , new Dictionary<string, object> { { "order", order} },ContentType.JSON,ContentType.JSON, TimeSpan.FromMilliseconds(0),30000,0 ); }
// *********************************** // Order // *********************************** /// <summary> /// <p>Place an order on a particular market. Post a <a onclick="dojo.hash('#type.NewStopLimitOrderRequestDTO'); return false;" class="json-link" href="#">NewStopLimitOrderRequestDTO</a> to the uri specified below.</p> <p>Do not set any order id fields when requesting a new order, the platform will generate them.</p> /// </summary> /// <param name="order">The order request</param> public ApiTradeOrderResponseDTO Order(NewStopLimitOrderRequestDTO order) { return Request<ApiTradeOrderResponseDTO>("order", "/newstoplimitorder", "POST", new Dictionary<string, object> { { "order", order} }, TimeSpan.FromMilliseconds(0), "trading"); }
/// <summary> /// <p>Place an order on a particular market. Post a <a onclick="dojo.hash('#type.NewStopLimitOrderRequestDTO'); return false;" class="json-link" href="#">NewStopLimitOrderRequestDTO</a> to the uri specified below.</p> <p>Do not set any order id fields when requesting a new order, the platform will generate them.</p> /// </summary> /// <param name="order">The order request</param> /// <param name="callback"></param> /// <param name="state"></param> public void BeginOrder(NewStopLimitOrderRequestDTO order, ApiAsyncCallback<ApiTradeOrderResponseDTO> callback, object state) { BeginRequest(callback, state, "order", "/newstoplimitorder", "POST", new Dictionary<string, object> { { "order", order} }, TimeSpan.FromMilliseconds(0), "trading"); }
private void OnMessageReceived(object sender, MessageEventArgs<PriceDTO> e) { if (!_listening || _ordered || Market == null) return; _ordered = true; var order = new NewStopLimitOrderRequestDTO { MarketId = e.Data.MarketId, AuditId = e.Data.AuditId, BidPrice = e.Data.Bid, OfferPrice = e.Data.Offer, Quantity = Market.WebMinSize.GetValueOrDefault() + 1, TradingAccountId = Account.TradingAccounts[0].TradingAccountId, Direction = "buy", Applicability = "GFD", ExpiryDateTimeUTC = DateTime.UtcNow + TimeSpan.FromDays(1) }; Dispatcher.BeginInvoke(() => listBox1.Items.Add("price update arrived, making a new trade")); RpcClient.TradesAndOrders.BeginOrder(order, ar => { try { var result = RpcClient.TradesAndOrders.EndTrade(ar); Dispatcher.BeginInvoke(() => { RpcClient.MagicNumberResolver.ResolveMagicNumbers(result); listBox1.Items.Add(String.Format("trading complete\n\tstatus = {0} {2}\n\tstatus reason = {1} {3}", result.Status, result.StatusReason, result.Status_Resolved, result.StatusReason_Resolved)); if (result.OrderId > 0) { listBox1.Items.Add(String.Format("created order {0}", result.OrderId)); } }); } catch (Exception ex) { Dispatcher.BeginInvoke(() => listBox1.Items.Add("trading failed!")); Dispatcher.BeginInvoke(() => listBox1.Items.Add("exception caught: " + ex)); } finally { Dispatcher.BeginInvoke(() => { Button1.IsEnabled = true; _listening = false; }); } }, null); }
public void CanOrder() { var gate = new AutoResetEvent(false); PriceDTO currentPrice = null; OrderDTO newOrder = null; var orderHasBeenPlacedFlag = false; var marketInformation = _rpcClient.Market.GetMarketInformation(_CFDmarketId.ToString()); var pricesListener = _streamingClient.BuildPricesListener(_CFDmarketId); var ordersListener = _streamingClient.BuildOrdersListener(); try { ordersListener.MessageReceived += (s, e) => { newOrder = e.Data; Console.WriteLine( string.Format( "New order has been recieved on Orders stream\r\n {0}", e.Data.ToStringWithValues())); gate.Set(); }; pricesListener.MessageReceived += (o, s) => { if (orderHasBeenPlacedFlag) return; currentPrice = s.Data; var order = new NewStopLimitOrderRequestDTO { MarketId = currentPrice.MarketId, BidPrice = currentPrice.Bid + 1, OfferPrice = currentPrice.Offer + 1, AuditId = currentPrice.AuditId, Quantity = marketInformation.MarketInformation.WebMinSize.GetValueOrDefault() + 1, TradingAccountId = _accounts.TradingAccounts[0].TradingAccountId, Direction = "buy", Applicability = "GTD", ExpiryDateTimeUTC = DateTime.UtcNow + TimeSpan.FromDays(1) }; var response = _rpcClient.TradesAndOrders.Order(order); orderHasBeenPlacedFlag = true; _rpcClient.MagicNumberResolver.ResolveMagicNumbers(response); Assert.AreEqual("Accepted", response.Status_Resolved, string.Format("Error placing order: \r\n{0}", response.ToStringWithValues())); }; if (!gate.WaitOne(TimeSpan.FromSeconds(15))) { throw new Exception("timed out waiting for order notification"); } Assert.IsNotNull(newOrder); } finally { _streamingClient.TearDownListener(pricesListener); _streamingClient.TearDownListener(ordersListener); } }
public void CanOrder() { var rpcClient = BuildRpcClient(); AccountInformationResponseDTO accounts = rpcClient.AccountInformation.GetClientAndTradingAccount(); NewStopLimitOrderRequestDTO order = new NewStopLimitOrderRequestDTO() { }; var response = rpcClient.TradesAndOrders.Order(order); }