private void OnGraphUpdate(PriceDTO val) { var item = new GraphItem { Value = (double)val.Price, Time = val.TickDate }; var key = val.MarketId.ToString(); PriceGraph.AddItem(key, item); PriceGraphSingle.AddItem(key, item); }
/// <summary> /// /// </summary> /// <param name="target"></param> /// <param name="source"></param> public static void Populate(PriceDTO target, PriceDTO source) { target.AuditId = source.AuditId; target.Bid = source.Bid; target.Change = source.Change; target.Direction = source.Direction; target.High = source.High; target.Low = source.Low; target.MarketId = source.MarketId; target.Offer = source.Offer; target.Price = source.Price; target.StatusSummary = source.StatusSummary; target.TickDate = source.TickDate; }
public ApiTradeOrderResponseDTO Trade(PriceDTO price, Direction direction) { AccountInformationResponseDTO accountInfo = _client.AccountInformation.GetClientAndTradingAccount(); int tradingAccountId = GetTradingAccountId(_client, price.MarketId, accountInfo); var request = new NewTradeOrderRequestDTO { MarketId = price.MarketId, Direction = direction.ToString().ToLower(), Quantity = Quantity, BidPrice = price.Bid, OfferPrice = price.Offer, AuditId = price.AuditId, TradingAccountId = tradingAccountId, AutoRollover = false }; ApiTradeOrderResponseDTO response = _client.TradesAndOrders.Trade(request); return response; }
public abstract void ProcessTick(PriceDTO price);
public ApiTradeOrderResponseDTO OpenPosition(PriceDTO price) { return Trade(price, Direction.buy); }
public ApiTradeOrderResponseDTO ClosePostion(PriceDTO price) { return Trade(price, Direction.sell); }
private void OnGraphUpdate(PriceDTO val) { // NOTE this code is a temporary workaround until datetime bug is fixed var ticksString = val.TickDate.Substring(7, val.TickDate.Length - 10); var time = new DateTime(1970, 1, 1, 0, 0, 0, 0).AddMilliseconds(Int64.Parse(ticksString)); var item = new GraphItem { Value = (double)val.Price, Time = time }; var key = val.MarketId.ToString(); PriceGraph.AddItem(key, item); PriceGraphSingle.AddItem(key, item); }
private void UpdateUi(PriceDTO data) { _logic.ProcessTick(data); if (_logic.PositionIsOpen) { StatusLabel.Text = "position is open."; } else { StatusLabel.Text = "no position."; } if (_logic.BidPending) { StatusLabel.Text = StatusLabel.Text + " sell is pending..."; } else if (_logic.OfferPending) { StatusLabel.Text = StatusLabel.Text + " buy is pending..."; } }
public override void ProcessTick(PriceDTO price) { if (PositionIsOpen) { // check to see if we should start thinking about selling if (BidPending) { // we are now waiting for the price to stop rising so we can sell. // hopefully it does not plummet past the sell trigger if (price.Bid >= BidPrice) { if (price.Bid >= LastBidPrice) { // still rising, lets wait... LastBidPrice = price.Bid; } else { // price is no longer rising but is still above our trigger so // SELL SELL SELL ClosePostion(price); BidPending = false; LastBidPrice = 0; PositionIsOpen = false; } } else { // it has fallen and we need to stand down BidPending = false; LastBidPrice = 0; } } else { if (price.Bid >= BidPrice) { // get ready to sell LastBidPrice = price.Bid; BidPending = true; } } } else { // check to see if we should start thinking about buying if (OfferPending) { // we saw the price equal or less than to our trigger price at some time // in the past and we are going to be greedy and wait until it stops falling if (price.Offer <= OfferPrice) { // is the current price still falling? this is where some fluctuation can be tolerated by complex logic if (price.Offer < LastOfferPrice) { // yes, just let it fall LastOfferPrice = price.Offer; } else { // no, it is rising, time to buy OpenPosition(price); OfferPending = false; PositionIsOpen = true; LastOfferPrice = 0; } } else { // the price has risen above our trigger price since last tick, cancel pending buy OfferPending = false; LastOfferPrice = 0; } } else { // if the price falls below our offer then go on alert and wait for it to stop falling and then buy if (price.Offer <= OfferPrice) { LastOfferPrice = price.Offer; OfferPending = true; } } } }
private int Trade(Client client, AccountInformationResponseDTO accountInfo, int marketId, PriceDTO price, decimal quantity, string direction, IEnumerable<int> closeOrderIds) { var tradeRequest = new NewTradeOrderRequestDTO { MarketId = marketId, Quantity = quantity, Direction = direction, TradingAccountId = accountInfo.SpreadBettingAccount.TradingAccountId, AuditId = price.AuditId, BidPrice = price.Bid, OfferPrice = price.Offer, Close = closeOrderIds.ToArray(), }; var resp = client.TradesAndOrders.Trade(tradeRequest); if (resp.OrderId == 0) { client.MagicNumberResolver.ResolveMagicNumbers(resp); var message = GetResponseDescription(resp); throw new ApplicationException(message); } return resp.OrderId; }