public static bool AllowAccept(OrderTask orderTask,QuotePolicyDetail quotePolicyDetail,string origin,int acceptDQVariation) { //Allow: (isNormal = IsBuy), SetPrice >= Calculated.Quotepolicy.Ask, SetPrice <= Calculated.Quotepolicy.Bid InstrumentClient instrument = orderTask.Transaction.Instrument; Price ask = null; Price bid = null; Price marketOriginPrice = new Price(origin, instrument.NumeratorUnit, instrument.Denominator); marketOriginPrice = marketOriginPrice + acceptDQVariation; if (quotePolicyDetail.PriceType == PriceType.WatchOnly) { int diffValue = instrument.GetSourceAskBidDiffValue(); bid = marketOriginPrice; ask = bid + diffValue; } else if (quotePolicyDetail.PriceType == PriceType.OriginEnable) { bid = marketOriginPrice + quotePolicyDetail.AutoAdjustPoints + (0 - quotePolicyDetail.SpreadPoints); var diffValue = instrument.GetSourceAskBidDiffValue(); ask = bid + (Math.Abs(diffValue)) + (quotePolicyDetail.SpreadPoints); } else { bid = marketOriginPrice + (quotePolicyDetail.AutoAdjustPoints); ask = bid + (quotePolicyDetail.SpreadPoints); } Price setPrice = new Price(orderTask.SetPrice, instrument.NumeratorUnit, instrument.Denominator); if(instrument.IsNormal == (orderTask.IsBuy == BuySell.Buy)) { if (ask != null) { return setPrice > ask; } } else { if (bid != null) { return setPrice < bid; } } return false; }
public bool AllowAccept(OrderTask orderTask,QuotePolicyDetail quotePolicyDetail, bool isBuy, string marketPrice, int acceptDQVariation) { InstrumentClient instrument = orderTask.Transaction.Instrument; Price marketPricePrice = Price.CreateInstance(marketPrice, instrument.NumeratorUnit, instrument.Denominator); marketPricePrice = marketPricePrice + acceptDQVariation; if (quotePolicyDetail.PriceType == PriceType.OriginEnable) { marketPricePrice = marketPricePrice + quotePolicyDetail.AutoAdjustPoints + (0 - quotePolicyDetail.SpreadPoints); } else { marketPricePrice = marketPricePrice + (quotePolicyDetail.AutoAdjustPoints); } Price setPrice = new Price(orderTask.SetPrice, instrument.NumeratorUnit, instrument.Denominator); if (instrument.IsNormal == isBuy) { if (marketPricePrice != null) { return setPrice > marketPricePrice; } } else { if (marketPricePrice != null) { return setPrice < marketPricePrice; } } return false; }
internal void CreateBestPrice(bool isAdd) { int adjust = isAdd ? 1 : -1; if (this._BSStatus == BSStatus.Both) { this._BestBuyString = this.Ask; this._BestSellString = this.Bid; this.BestBuy = this.BestSell = this.GetBestBuySellString(this.Ask, this.Bid); this.AnswerPrice = this.BestBuy; } else { Price ask = new Price(this.Ask, this._Instrument.NumeratorUnit, this._Instrument.Denominator); Price bid = new Price(this.Bid, this._Instrument.NumeratorUnit, this._Instrument.Denominator); if (this._Instrument.IsNormal ^ (this._BSStatus == BSStatus.Buy)) { this.BestBuy = (ask - adjust).ToString(); this.BestSell = (bid - adjust).ToString(); this.AnswerPrice = this.BestSell; } else { this.BestBuy = (ask + adjust).ToString(); this.BestSell = (bid + adjust).ToString(); this.AnswerPrice = this.BestBuy; } } this.SetPrice = string.IsNullOrEmpty(this.BestBuy) ? this.BestSell : this.BestBuy; }
internal void SetAvgPrice() { Price price = null; decimal avgBuyPriceValue = this._BuyLot != decimal.Zero ? this._BuyLotMultiplyAvgPriceSum / this._BuyLot : decimal.Zero; price = new Price(avgBuyPriceValue.ToString(), this._MinNumeratorUnit, this._MaxDenominator); this.BuyAvgPrice = price == null ? "0" : price.ToString(); decimal avgSellPriceValue = this._SellLot != decimal.Zero ? this._SellLotMultiplyAvgPriceSum / this._SellLot : decimal.Zero; price = new Price(avgSellPriceValue.ToString(), this._MinNumeratorUnit, this._MaxDenominator); this.SellAvgPrice = price == null ? "0" : price.ToString(); decimal avgNetPriceValue = this._NetLot != decimal.Zero ? this._NetLotMultiplyAvgPriceSum / this._NetLot : decimal.Zero; price = new Price(avgNetPriceValue.ToString(), this._MinNumeratorUnit, this._MaxDenominator); this.NetAvgPrice = price == null ? "0" : price.ToString(); }
private OrderRange GetPriceRange(string executePrice, int interval, InstrumentClient instrument) { Price rangeValue = new Price(executePrice, (int)instrument.NumeratorUnit, (int)instrument.Denominator); Price beginPrice = rangeValue; Price EndPrice = rangeValue + interval; OrderRange orderRange = new OrderRange(RangeType.Price, interval, beginPrice.ToString(), EndPrice.ToString()); return orderRange; }
public int GetSourceAskBidDiffValue() { int diffValue = 0; Price lastAsk = new Price(this.LastQuotation.Ask, this.NumeratorUnit, this.Denominator); Price lastBid = new Price(this.LastQuotation.Bid, this.NumeratorUnit, this.Denominator); diffValue = lastAsk - lastBid; return diffValue; }
internal void UpdateMarketPrice(bool isBuy) { //if (!this._Instrument.NumeratorUnit.HasValue) return; if (isBuy) { Price bid = new Price(this.Bid, this._Instrument.NumeratorUnit, this._Instrument.Denominator); this.MarketPrice = bid; } else { Price ask = new Price(this.Ask, this._Instrument.NumeratorUnit, this._Instrument.Denominator); this.MarketPrice = ask; } }
internal void SetCustomerPrice() { Price ask = new Price(this.Ask, this._Instrument.NumeratorUnit, this._Instrument.Denominator); Price bid = new Price(this.Bid, this._Instrument.NumeratorUnit, this._Instrument.Denominator); if (this._Instrument.IsNormal ^ (this.BuySell == BuySell.Buy)) { this.CustomerPrice = this.MarketPrice + 1; } else { this.CustomerPrice = this.MarketPrice - 1; } }
internal override AddTransactionCommandBase CreateDoneTransaction(Account account, Transaction ifTran, Guid sourceOrderId, iExchange.Common.Price limitPrice, iExchange.Common.Price stopPrice) { throw new NotImplementedException(); }
internal override AddTransactionCommandBase CreateByAutoClose(Account account, Agent.Order openOrder, iExchange.Common.Price closePrice, iExchange.Common.OrderType orderType) { throw new NotImplementedException(); }
internal override AddTransactionCommandBase CreateDoneTransaction(Account account, Transaction ifTran, Guid sourceOrderId, iExchange.Common.Price limitPrice, iExchange.Common.Price stopPrice) { return(new AddPhysicalTransactionCommand(account, (PhysicalTransaction)ifTran, sourceOrderId, limitPrice, stopPrice)); }
internal override AddTransactionCommandBase CreateByAutoClose(Account account, Order openOrder, iExchange.Common.Price closePrice, iExchange.Common.OrderType orderType) { return(new AddPhysicalTransactionCommand(account, (PhysicalOrder)openOrder, closePrice, orderType)); }
public static bool IsProblePrice(InstrumentClient instrument,string marketPrice,string executedPrice) { Price setExecutedPrice = new Price(executedPrice, instrument.NumeratorUnit, instrument.Denominator); Price currentPrice = new Price(marketPrice, instrument.NumeratorUnit, instrument.Denominator); return (Math.Abs(currentPrice - setExecutedPrice) > instrument.AlertVariation); }
public static bool IsLimitedPriceByDailyMaxMove(string newPrice,InstrumentClient instrument) { bool isLimited = false; if (!string.IsNullOrEmpty(newPrice) && instrument.DailyMaxMove != 0) { Price adjustPrice = new Price(newPrice, instrument.NumeratorUnit, instrument.Denominator); Price previousClosePrice = new Price(instrument.PreviousClosePrice, instrument.NumeratorUnit, instrument.Denominator); if((adjustPrice > (previousClosePrice + instrument.DailyMaxMove)) || (adjustPrice < (previousClosePrice - instrument.DailyMaxMove))) { isLimited = true; } } return isLimited; }
internal void UpdateDiff() { Price customerAskPrice = new Price((double)this.CustomerAskPrice, this._Instrument.NumeratorUnit, this._Instrument.Denominator); Price customerBidPrice = new Price((double)this.CustomerBidPrice, this._Instrument.NumeratorUnit, this._Instrument.Denominator); Price ask = new Price(this.Ask, this._Instrument.NumeratorUnit, this._Instrument.Denominator); Price bid = new Price(this.Bid, this._Instrument.NumeratorUnit, this._Instrument.Denominator); this.AskDiff = ask - customerAskPrice; this.BidDiff = bid - customerBidPrice; }
internal void SetCustomerPrice(bool isBuy) { string pricString = isBuy ? this.CustomerBidPrice.ToString() : this.CustomerAskPrice.ToString(); Price price = new Price(pricString, this._Instrument.NumeratorUnit, this._Instrument.Denominator); Price ask = new Price(this.Ask, this._Instrument.NumeratorUnit, this._Instrument.Denominator); Price bid = new Price(this.Bid, this._Instrument.NumeratorUnit, this._Instrument.Denominator); Price marketPrice = isBuy ? ask : bid; if (this._Instrument.IsNormal ^ (this.BuySell == BuySell.Buy)) { price = marketPrice + 1; } else { price = marketPrice - 1; } }