using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//----------------------------------------------------------------
//Module Name: $safeprojectname$
//Purpose:
//CopyRight: Muchinfo
//History:
//----------------------------------------------------------------
//DateTime 2016/1/16 16:27:18
//Author
//Description Create
//----------------------------------------------------------------
using System.Windows;
using Muchinfo.MTPClient.Data.Enums;
using Muchinfo.MTPClient.Data.Model;
using Muchinfo.MTPClient.Data.Model.Account;
using Muchinfo.MTPClient.Infrastructure.Utilities;
using Muchinfo.MTPClient.Resources;
using GalaSoft.MvvmLight.Ioc;
using Muchinfo.MTPClient.IService;
namespace Muchinfo.MTPClient.Trade.ViewModels
{
public class BidCloseViewModel : CloseOrderBase
{
private bool _executePriceGotFocus;
private OrderMode _orderMode = OrderMode.STD; //设置成交属性
// private HoldingSummary _holdingSummary; //持仓汇总记录。
private decimal _pips = 5;
private Visibility _isTimeVisibility = Visibility.Collapsed;
//修改止盈/止损
private bool canProfitCharChange = false;
private bool canLossCharChange = false;
///
/// 最大手数
///
private decimal _maxLot;
private decimal _minPips = 0m;
private decimal _maxPips = 100m;
private decimal _incrementPips = 10m;
private decimal _marketPrice;
private Direction _openDirection;
private bool _isAllowEnsturt; //是否允许限价平仓
// private readonly int BidMarketHideType = ApplicationParameter.BidMarketHideType;//竞价商品卖方向隐藏方式
public BidCloseViewModel(HoldingOrder holdOrder,QuoteGoods goods, OrderType orderType = OrderType.BidMarketClose)
: base(holdOrder,goods, orderType)
{
IsBidMarket = true;
SetCommissions(goods);
IsBidDirection = holdOrder.Direction == Direction.Ask;
IsAskDirection = !IsBidDirection;
}
///
/// 汇总平仓
///
///
///
public BidCloseViewModel(HoldingSummary holdingSummary, QuoteGoods goods,OrderType orderType=OrderType.BidMarketClose )
: base(holdingSummary,goods)
{
IsBidMarket = true;
this._holdingSummary = holdingSummary;
CurrentOrderType = orderType;
SetCommissions(goods);
IsBidDirection = holdingSummary.Direction == Direction.Ask;
IsAskDirection = !IsBidDirection;
}
///
/// 按商品平仓
///
///
public BidCloseViewModel(QuoteGoods goods, List holdingSummaries, bool isDirection)
: base(goods)
{
IsBidMarket = true;
CurrentOrderType = OrderType.BidMarketClose;
IsDirectionEnable = isDirection;
_holdingSummaries = holdingSummaries;
var holdingSummary= holdingSummaries.FirstOrDefault();
if (holdingSummary != null)
{
IsBidDirection = holdingSummary.Direction == Direction.Ask;
SetHoldingSummay(holdingSummary);
IsAskDirection = !IsBidDirection;
}
SetCommissions(goods);
}
private TradeCloseMode _tradeCloseMode;
///
/// 平仓范围
///
public TradeCloseMode TradeCloseMode
{
get
{
return _tradeCloseMode;
}
set
{
Set(() => TradeCloseMode, ref _tradeCloseMode, value);
// TradeCloseModeChange();
}
}
private Dictionary _tradeCloseModes;
///
/// 平仓范围枚举
///
public Dictionary TradeCloseModes
{
get
{
//todo:显示平仓类型
var diction = new Dictionary();
diction.Add(TradeCloseMode.CloseAll, Muchinfo.MTPClient.Resources.Muchinfo_Resource.Trade_No);
diction.Add(TradeCloseMode.CloseToday, Muchinfo.MTPClient.Resources.Muchinfo_Resource.Trade_CloseToday);
diction.Add(TradeCloseMode.CloseHistory, Muchinfo.MTPClient.Resources.Muchinfo_Resource.Trade_CloseHistory);
return diction;
// return _tradeCloseModes;
}
set
{
Set(() => TradeCloseModes, ref _tradeCloseModes, value);
}
}
///
/// 获取和设置OrderModes
///
public Dictionary OrderModes
{
get
{
var types = new Dictionary
{
{OrderMode.STD, Muchinfo.MTPClient.Resources.Muchinfo_Resource.Trade_No},
{OrderMode.FAK, "FAK"},
{OrderMode.FOK,"FOK"}
};
return types;
}
}
///
/// 设置成交属性
///
public OrderMode OrderMode
{
get { return _orderMode; }
set { Set(() => OrderMode, ref _orderMode, value); }
}
private Visibility _upPriceVisibility;
///
/// 是否显示涨停价提示
///
public Visibility UpPriceVisibility
{
get { return _upPriceVisibility; }
set { Set(() => UpPriceVisibility, ref _upPriceVisibility, value); }
}
private Visibility _fallPriceVisibility;
///
/// 是否显示跌停价
///
public Visibility FallPriceVisibility
{
get
{
return _fallPriceVisibility;
}
set
{
Set(() => FallPriceVisibility, ref _fallPriceVisibility, value);
}
}
#region 竞价策略单
private bool _reverseOpenChecked;
public bool ReverseOpenChecked
{
get
{
return _reverseOpenChecked;
}
set
{
Set(() => ReverseOpenChecked, ref _reverseOpenChecked, value);
}
}
#endregion
#region 竞价报价
private List _bidCommissions;
///
/// 显示买入档
///
public List BidCommissions
{
get { return _bidCommissions; }
set { Set(() => BidCommissions, ref _bidCommissions, value); }
}
private List _askCommissions;
///
/// 显示卖出档
///
public List AskCommissions
{
get { return _askCommissions; }
set { Set(() => AskCommissions, ref _askCommissions, value); }
}
///
/// 设置买卖档
///
/// if set to true [bid].
/// The commissions.
/// List{Commission}.
private List SortCommissions(bool bid, Commission[] commissions)
{
var commissionLsit = new List();
int index = 1;
foreach (var commission in commissions)
{
commission.Index = index;
commission.FormatString = this.PriceFormat;
commissionLsit.Add(commission);
index++;
}
if (!bid)
{
commissionLsit = commissionLsit.OrderByDescending((item) => item.Index).ToList();
}
return commissionLsit;
}
private void SetCommissions(QuoteGoods goods)
{
BidCommissions = SortCommissions(true, goods.BidList);
AskCommissions = SortCommissions(false, goods.AskList);
}
#endregion
#region 虚函数
///
/// 获取和设置the order types
///
public override Dictionary OrderTypes
{
get
{
var types = new Dictionary
{
{OrderType.BidMarketClose, Muchinfo_Resource.OrderType_Enum_MarketClose},
{OrderType.BidLimitClose, Muchinfo_Resource.OrderType_Enum_LimitClose}
};
return types;
}
}
public override NewEntrustOrder BuildEntrustOrder()
{
var entrustOrder = base.BuildEntrustOrder();
if (CurrentOrderType == OrderType.BidLimitClose)
{
entrustOrder.EntrustPrice = ExecutePrice;
entrustOrder.PriceMode = OrderPriceMode.LimitPrice;
}
else
{
entrustOrder.EntrustPrice = QuotePrice;
entrustOrder.PriceMode = OrderPriceMode.MarketPrice;
}
if (this.HoldOrder != null)
{
entrustOrder.RelationTicket = HoldOrder.OrderID;
}
// entrustOrder.TradeCloseMode = TradeCloseMode;
entrustOrder.OrderMode = OrderMode;
//entrustOrder.StrategyType = ReverseOpenChecked ? StrategyType.ReverseOpen : StrategyType.None;
//entrustOrder.ReverseOpenPrice = entrustOrder.EntrustPrice;
entrustOrder.AllowTradeSub = Pips;
return entrustOrder;
}
public override void PostOrder(Action successAction, Action errorAction)
{
var entrustOrder = BuildEntrustOrder();
var orderService = SimpleIoc.Default.GetInstance();
orderService.BidMarketEntrustOrder(entrustOrder, successAction, errorAction);
}
#endregion
}
}