using System; using System.Collections.Generic; using System.Linq; using System.Text; //---------------------------------------------------------------- //Module Name: $safeprojectname$ //Purpose: //CopyRight: Muchinfo //History: //---------------------------------------------------------------- //DateTime 2016/9/14 16:42:39 //Author //Description Create //---------------------------------------------------------------- using Muchinfo.MTPClient.Adapter.Abstract; using Muchinfo.MTPClient.Data; using Muchinfo.MTPClient.Data.Enums; using Muchinfo.MTPClient.Data.Model.Account; using Muchinfo.MTPClient.Data.Model.Listing; using Muchinfo.MTPClient.Infrastructure.LinkProxy; using Muchinfo.MTPClient.Infrastructure.Utilities; using Muchinfo.MTPClient.IService; using Muchinfo.MTPClient.NetworkCore; using Muchinfo.MTPClient.Resources; using Muchinfo.MTPClient.Service.Utilities; namespace Muchinfo.MTPClient.Service { public class ListingService : IListingService { private ListingAdapter _listingAdapter; public ListingService() { _listingAdapter = LinkManager.Instance.TradeAdapterFactory.CreateListingAdapter(); } public void QueryListingEntrust(long goodsid, Action> successAction, Action errorAction) { var queryCommonParams = new List(); queryCommonParams.Add(new QueryCommonParam() { ParamKey = "DeliveryGoodsId", ParamValue = goodsid + string.Empty }); QueryCommonHelper.QueryCommon(QueryStatement.QueryListingOrder, queryCommonParams, new Action>((listingOrder) => { if (successAction != null) { successAction(listingOrder); } }), (error) => { if (errorAction != null) { //RequestFunc = 查询委托单 error.RequestFunc = Client_Resource.Listing_Query; errorAction(error); } }); } public void QueryListingEntrust(string key,long goodsGroupid, Action> successAction, Action errorAction ) { //#if DEBUG // if (successAction != null) // { // var listings = new List(); // for (int i = 0; i < 20; i++) // { // var tem = new ListingEntrustOrder() { AllowModifyPrice = 34, AuditStatus = 1, OrderQty = 33, OrderPrice = 3553, AvailQty = 55555, }; // tem.MoneyMode = i % 2 == 0 ? eMoneyMode.MONEYMODE_MARGIN : eMoneyMode.MONEYMODE_PAY; // listings.Add(tem); // } // successAction(listings); // } // return; //#endif var queryCommonParams=new List(); if (!string.IsNullOrWhiteSpace(key)) { queryCommonParams.Add(new QueryCommonParam(){ParamKey ="QueryKey",ParamValue = key}); } if (goodsGroupid>0) { queryCommonParams.Add(new QueryCommonParam() { ParamKey = "GoodsGroupid", ParamValue = goodsGroupid+string.Empty }); } QueryCommonHelper.QueryCommon(QueryStatement.QueryListingOrder, queryCommonParams, new Action>((listingOrder) => { if (successAction != null) { successAction(listingOrder); } }), (error) => { if (errorAction != null) { //RequestFunc = 查询委托单 error.RequestFunc = Client_Resource.Listing_Query; errorAction(error); } }); } public void QueryDelistingOrders(ulong accountid, Direction direction, int orderStatus, Action> successAction, Action errorAction) { var queryCommonParams = new List(); queryCommonParams.Add(new QueryCommonParam() { ParamKey = "accountId", ParamValue = accountid + string.Empty }); ////查询个人摘牌记录(这个字段不为空时查询摘牌记录) queryCommonParams.Add(new QueryCommonParam() { ParamKey = "Delisting", ParamValue = accountid + string.Empty }); if (direction != Direction.unSet) { queryCommonParams.Add(new QueryCommonParam() { ParamKey = "buyOrSell", ParamValue = ((int)direction) + string.Empty }); } if (orderStatus != -1) { queryCommonParams.Add(new QueryCommonParam() { ParamKey = "status", ParamValue = orderStatus + string.Empty }); } QueryCommonHelper.QueryCommon(QueryStatement.QueryDeListingOrder, queryCommonParams, new Action>((dlistingOrder) => { if (successAction != null) { UserManager.UpdateCacheOrder(dlistingOrder.QueryResults); successAction(dlistingOrder.QueryResults); } }), (error) => { if (errorAction != null) { //RequestFunc = 查询委托单 error.RequestFunc = Client_Resource.Delisting_Query; errorAction(error); } }); } /// /// 摘牌委托订单 /// /// /// /// public void DeListingEntrustOrder(Data.Model.NewEntrustOrder entrustOrder, Action successAction, Action errorAction) { return; //var reqeust = _listingAdapter.ToDeListingEntrustOrder(entrustOrder); //var packgage = new TCPPackage() { Content = reqeust, FunCode = FuncCode.FID_DeListingOrderReq }; //LinkManager.Instance.TradeTcpLinkProxy.SendPackage(packgage, new Action((revPackgage) => //{ // var responeEntrity = _listingAdapter.ToDeListingOrder(revPackgage.Content); // if (responeEntrity.RetCode == 0) // { // //todo:生成委托单 // successAction(responeEntrity.Entity); // } // else // { // if (errorAction != null) // { // //RequestFunc = 市场委托订单 // errorAction(new ErrorEntity() { ReturnCode = responeEntrity.RetCode, ReturnDesc = responeEntrity.RetMessage, RequestFunc = Client_Resource.Delisting_Order }); // } // } //}), new Action((errorCode, errorDesc) => //{ ////通信错误 // if (errorAction != null) // { // errorAction(new ErrorEntity() { ReturnCode = errorCode, ReturnDesc = errorDesc, RequestFunc = Client_Resource.Delisting_Order }); // } //})); } public void QueryDelistingRecord(long orderId, Action> successAction, Action errorAction) { var queryCommonParams = new List(); queryCommonParams.Add(new QueryCommonParam() { ParamKey = "RelationID", ParamValue = orderId+string.Empty }); QueryCommonHelper.QueryCommon(QueryStatement.QueryDeListingRecord, queryCommonParams, new Action>((dlistingOrder) => { if (successAction != null) { successAction(dlistingOrder.QueryResults); } }), (error) => { if (errorAction != null) { //RequestFunc = 查询委托单 error.RequestFunc = Client_Resource.Delisting_Record; errorAction(error); } }); } public void QueryCustomerDelistingCount(long orderId, ulong accountId, Action> successAction, Action errorAction) { var queryCommonParams = new List(); queryCommonParams.Add(new QueryCommonParam() { ParamKey = "accountId", ParamValue = accountId + string.Empty }); queryCommonParams.Add(new QueryCommonParam() { ParamKey = "orderId", ParamValue = orderId + string.Empty }); QueryCommonHelper.QueryCommon(QueryStatement.QueryDeListingTradeCount, queryCommonParams, new Action>((dlistingOrder) => { if (successAction != null) { successAction(dlistingOrder.QueryResults); } }), (error) => { if (errorAction != null) { //RequestFunc = 查询委托单 error.RequestFunc = Client_Resource.Delisting_Record; errorAction(error); } }); } public void QueryDeliveryGoods(long exchId, eSponsorType sponsor, Action> successAction, Action errorAction) { var queryCommonParams = new List(); queryCommonParams.Add(new QueryCommonParam() { ParamKey = "exchangeAreaId", ParamValue = exchId + string.Empty }); // queryCommonParams.Add(new QueryCommonParam() { ParamKey = "sponsor", ParamValue = sponsor + string.Empty }); QueryCommonHelper.QueryCommon(QueryStatement.SearchDeliveryGoods, queryCommonParams, new Action>((dlistingOrder) => { if (successAction != null) { successAction(dlistingOrder); } }), (error) => { if (errorAction != null) { //RequestFunc = 查询委托单 error.RequestFunc = Client_Resource.Delisting_Record; errorAction(error); } }); } public void QueryMyOrders(string NameCodeOrder, ulong accountId, Action> successAction, Action errorAction) { var queryCommonParams = new List(); if (!string.IsNullOrWhiteSpace(NameCodeOrder)) { queryCommonParams.Add(new QueryCommonParam() { ParamKey = "QueryKey", ParamValue = NameCodeOrder + string.Empty }); } queryCommonParams.Add(new QueryCommonParam() { ParamKey = "accountId", ParamValue = accountId + string.Empty }); QueryCommonHelper.QueryCommon(QueryStatement.QueryListingMyOrders, queryCommonParams, new Action>((dlistingOrder) => { if (successAction != null) { successAction(dlistingOrder); } }), (error) => { if (errorAction != null) { //RequestFunc = 查询委托单 error.RequestFunc = Client_Resource.ListingMarket_MyOrders; errorAction(error); } }); } public void QueryMyListingOrders(ulong accountId, int direction, int status, Action> successAction, Action errorAction) { var queryCommonParams = new List(); if (direction!=-1) { queryCommonParams.Add(new QueryCommonParam() { ParamKey = "buyOrSell", ParamValue = direction + string.Empty }); } if (status != -1) { queryCommonParams.Add(new QueryCommonParam() { ParamKey = "status", ParamValue = status + string.Empty }); } queryCommonParams.Add(new QueryCommonParam() { ParamKey = "accountId", ParamValue = accountId + string.Empty }); QueryCommonHelper.QueryCommon(QueryStatement.QueryListingRequest, queryCommonParams, new Action>((listingOrder) => { if (successAction != null) { successAction(listingOrder); } }), (error) => { if (errorAction != null) { //RequestFunc = 查询委托单 error.RequestFunc = Client_Resource.ListingMarket_MyOrders; errorAction(error); } }); } public void ListingEntrustOrders(ListingEntrustOrder order, Action successAction, Action errorAction) { return; //var reqeust = _listingAdapter.ToListingEntrustOrder(order); //var packgage = new TCPPackage() { Content = reqeust, FunCode = FuncCode.FID_ListingOrderReq }; //LinkManager.Instance.TradeTcpLinkProxy.SendPackage(packgage, new Action((revPackgage) => //{ // var responeEntrity = _listingAdapter.ToListingOrder(revPackgage.Content); // if (responeEntrity.RetCode == 0) // { // //todo:生成委托单 // successAction(responeEntrity.Entity); // } // else // { // if (errorAction != null) // { // //RequestFunc = 市场委托订单 // errorAction(new ErrorEntity() { ReturnCode = responeEntrity.RetCode, ReturnDesc = responeEntrity.RetMessage, RequestFunc = Client_Resource.ListingMarket_ListingTrade }); // } // } //}), new Action((errorCode, errorDesc) => //{ ////通信错误 // if (errorAction != null) // { // errorAction(new ErrorEntity() { ReturnCode = errorCode, ReturnDesc = errorDesc, RequestFunc = Client_Resource.ListingMarket_ListingTrade }); // } //})); } public void QueryListingEntrust(uint goodsid, Direction direction, Action> successAction, Action errorAction) { var queryCommonParams = new List(); queryCommonParams.Add(new QueryCommonParam() { ParamKey = "DeliveryGoodsId", ParamValue = goodsid + string.Empty }); queryCommonParams.Add(new QueryCommonParam() { ParamKey = "buyOrSell", ParamValue =((int) direction) + string.Empty }); QueryCommonHelper.QueryCommon(QueryStatement.QueryListingOrder, queryCommonParams, new Action>((listingOrder) => { if (successAction != null) { successAction(listingOrder); } }), (error) => { if (errorAction != null) { //RequestFunc = 查询委托单 error.RequestFunc = Client_Resource.Listing_Query; errorAction(error); } }); } } }