/// <summary> /// OnOrderUpdate->OnExecutionUpdate->OnPositionUpdate /// OnPositionUpdate: check new trade, change position for curTrade, no order update; /// OnExecutionUpdate: check filled order, update the new entry order and liquidate order; /// OnOrderUpdate: deal with working order, rejected/cancelled orders; /// </summary> /// <param name="order"></param> /// <param name="limitPrice"></param> /// <param name="stopPrice"></param> /// <param name="quantity"></param> /// <param name="filled"></param> /// <param name="averageFillPrice"></param> /// <param name="orderState"></param> /// <param name="time"></param> /// <param name="error"></param> /// <param name="comment"></param> protected override void OnOrderUpdate(Cbi.Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, Cbi.OrderState orderState, DateTime time, Cbi.ErrorCode error, string comment) { //if(BarsInProgress !=0) return; IndicatorProxy.Log2Disk = true; if (PrintOut > 1 && !IsInStrategyAnalyzer) { IndicatorProxy.PrintLog(true, IsLiveTrading(), CurrentBars[BarsInProgress] + "[" + BarsInProgress + "]:OnOrderUpdate IsUnmanaged=" + IsUnmanaged); } //The logic is implemented in the method below CurrentTrade.OnCurOrderUpdate(order, limitPrice, stopPrice, quantity, filled, averageFillPrice, orderState, time, error, comment); return; //The order execution is implemented in the method below if (IsUnmanaged) { OnOrderUpdateUM(order, limitPrice, stopPrice, quantity, filled, averageFillPrice, orderState, time, error, comment); } else { OnOrderUpdateMG(order, limitPrice, stopPrice, quantity, filled, averageFillPrice, orderState, time, error, comment); } }
/// <summary> /// Constructor. </summary> /// <param name="orders"> the orders to be recorded (cannot be empty) </param> public TradingRecord(params Order[] orders) : this(orders[0].OrderType) { foreach (var o in orders) { var newOrderWillBeAnEntry = CurrentTrade.New; if (newOrderWillBeAnEntry && !o.OrderType.Equals(_startingType)) { // Special case for entry/exit types reversal // E.g.: BUY, SELL, // BUY, SELL, // SELL, BUY, // BUY, SELL CurrentTrade = new Trade(o.OrderType); } var newOrder = CurrentTrade.Operate(o.Index, o.Price, o.Amount); RecordOrder(newOrder, newOrderWillBeAnEntry); } }
void HandleTradeRequest(CallbackMsg msg) { var details = msg as SteamTrading.TradeRequestCallback; string name = SteamFriends.GetFriendPersonaName(details.Other); string log = String.Format("Trade request to {0} status: {1}", name, details.Status.ToString()); Logger.WriteLine(log); ResetPendingTrade(); if (details.Status != EEconTradeResponse.Accepted) { return; } CurrentTrade = details.Trade; CurrentTrade.Initialize(); }
protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time) { if (BarsInProgress != 0) { return; } IndicatorProxy.Log2Disk = true; if (PrintOut > 1 && !IsInStrategyAnalyzer) { IndicatorProxy.PrintLog(true, IsLiveTrading(), CurrentBar + ":OnExecutionUpdate" + ";IsUnmanaged=" + IsUnmanaged + ";IsLiveTrading=" + IsLiveTrading() + ";IsInitialEntry=" + execution.IsInitialEntry + ";IsEntry=" + execution.IsEntry + ";IsExit=" + execution.IsExit + ";IsLastExit=" + execution.IsLastExit + ";GetMarketPosition=" + GetMarketPosition() + ";marketPosition=" + marketPosition + ";quantity=" + quantity + ";HasPosition=" + HasPosition() + ";GetAvgPrice=" + GetAvgPrice() + ";price=" + price); } CurrentTrade.OnCurExecutionUpdate(execution, executionId, price, quantity, marketPosition, orderId, time); return; if (IsUnmanaged) { OnExecutionUpdateUM(execution, executionId, price, quantity, marketPosition, orderId, time); } else { OnExecutionUpdateMG(execution, executionId, price, quantity, marketPosition, orderId, time); } }
protected override void OnPositionUpdate(Cbi.Position position, double averagePrice, int quantity, Cbi.MarketPosition marketPosition) { IndicatorProxy.Log2Disk = true; int bsx = BarsSinceExitExecution(0, "", 0); int bse = BarsSinceEntryExecution(0, "", 0); if (PrintOut > 1 && !IsInStrategyAnalyzer) { IndicatorProxy.PrintLog(true, IsLiveTrading(), CurrentBar + ":OnPositionUpdate, CurrentTrade not updated -- " + ";BarsSinceExit, BarsSinceEntry=" + bsx + "," + bse + ";IsUnmanaged=" + IsUnmanaged + ";IsLiveTrading=" + IsLiveTrading() + ";GetMarketPosition=" + GetMarketPosition() + ";marketPosition=" + marketPosition + ";HasPosition=" + HasPosition() + ";CurrentTrade.PosQuantity=" + CurrentTrade.PosQuantity + ";CurrentTrade.MktPosition=" + CurrentTrade.MktPosition + ";quantity=" + quantity + ";GetAvgPrice=" + GetAvgPrice() + ";averagePrice=" + averagePrice); } //Print(position.ToString() + "--MarketPosition=" + position.MarketPosition); CurrentTrade.OnCurPositionUpdate(position, averagePrice, quantity, marketPosition); if (CurrentTrade.MktPosition != null && CurrentTrade.PosAvgPrice != null && CurrentTrade.PosQuantity != null && CurrentTrade.PosUnrealizedPnL != null) { if (PrintOut > 1 && !IsInStrategyAnalyzer) { IndicatorProxy.PrintLog(true, IsLiveTrading(), String.Format("{0}: OnPositionUpdate, CurrentTrade updated -- CurrentTrade.PosAvgPrice: {1}, CurrentTrade.PosQuantit={2}, CurrentTrade.MktPosition={3}, PnL={4}", CurrentBar, CurrentTrade.PosAvgPrice, CurrentTrade.PosQuantity, CurrentTrade.MktPosition, CurrentTrade.PosUnrealizedPnL)); } } }