Преглед изворни кода

风险管理3月5日提交代码-liu.bolan-持仓头寸请求

Liu.bolan пре 4 година
родитељ
комит
019f400a32

+ 139 - 0
RMA/app/src/main/java/cn/muchinfo/rma/business/future/FutureManager.kt

@@ -1,6 +1,7 @@
 package cn.muchinfo.rma.business.future
 
 import cn.muchinfo.rma.global.GlobalDataCollection
+import cn.muchinfo.rma.global.data.FutureDetailsData
 import cn.muchinfo.rma.global.data.GoodsInfoAndQuotes
 import cn.muchinfo.rma.global.data.MiddleGoodsDetail
 import cn.muchinfo.rma.global.data.QuoteDayData
@@ -108,4 +109,142 @@ class FutureManager {
             goodsInfoAndQuotesList?.add(newInfoAndQuotes)
         }
     }
+
+    /**
+     * 获取企业风管期货历史委托单信息
+     * @param params Map<String, String> accountID/资金账户ID startDate/ 开始时间 - 闭区间,格式:yyyy-MM-dd endDate / 结束时间 - 闭区间,格式:yyyy-MM-dd
+     * @param responseBack Function3<[@kotlin.ParameterName] Boolean, [@kotlin.ParameterName] List<FutureDetailsData>?, [@kotlin.ParameterName] Error?, Unit>
+     */
+    fun queryErmcpHisOrderDetails(
+        params: Map<String, String>,
+        responseBack: (isSuccess: Boolean, respData: List<FutureDetailsData>?, error: Error?) -> Unit
+    ){
+        MyOkHttpUtils().query(
+            URL = SPUtils.getInstance().getString(Constant.goCommonSearchUrl) + "/Ermcp/QueryErmcpHisOrderDetails",
+            params = params,
+            type = "1",
+            callback = object : ResponseCallback<BaseResult<List<FutureDetailsData>>>(){
+                override fun onResponse(response: BaseResult<List<FutureDetailsData>>?, id: Int) {
+                    responseBack(true, response?.data, null)
+                }
+
+                override fun onError(call: Call?, e: Exception?, id: Int) {
+                    responseBack(false, null, Error(e?.message))
+                }
+
+            }
+        )
+    }
+
+
+    /**
+     * 获取企业风管期货历史成交单信息
+     * @param params Map<String, String> accountID/资金账户ID startDate/ 开始时间 - 闭区间,格式:yyyy-MM-dd endDate / 结束时间 - 闭区间,格式:yyyy-MM-dd goodsID/商品ID  buyOrSell/买卖方向,0:买 1:卖
+     * @param responseBack Function3<[@kotlin.ParameterName] Boolean, [@kotlin.ParameterName] List<FutureDetailsData>?, [@kotlin.ParameterName] Error?, Unit>
+     */
+    fun queryErmcpHisTradeDetails(
+        params: Map<String, String>,
+        responseBack: (isSuccess: Boolean, respData: List<FutureDetailsData>?, error: Error?) -> Unit
+    ){
+        MyOkHttpUtils().query(
+            URL = SPUtils.getInstance().getString(Constant.goCommonSearchUrl) + "/Ermcp/QueryErmcpHisTradeDetails",
+            params = params,
+            type = "1",
+            callback = object : ResponseCallback<BaseResult<List<FutureDetailsData>>>(){
+                override fun onResponse(response: BaseResult<List<FutureDetailsData>>?, id: Int) {
+                    responseBack(true, response?.data, null)
+                }
+
+                override fun onError(call: Call?, e: Exception?, id: Int) {
+                    responseBack(false, null, Error(e?.message))
+                }
+
+            }
+        )
+    }
+
+
+    /**
+     * 获取企业风管期货委托单信息
+     * @param params Map<String, String> accountID/资金账户ID
+     * @param responseBack Function3<[@kotlin.ParameterName] Boolean, [@kotlin.ParameterName] List<FutureDetailsData>?, [@kotlin.ParameterName] Error?, Unit>
+     */
+    fun queryErmcpOrderDetails(
+        params: Map<String, String>,
+        responseBack: (isSuccess: Boolean, respData: List<FutureDetailsData>?, error: Error?) -> Unit
+    ){
+        MyOkHttpUtils().query(
+            URL = SPUtils.getInstance().getString(Constant.goCommonSearchUrl) + "/Ermcp/QueryErmcpOrderDetails",
+            params = params,
+            type = "1",
+            callback = object : ResponseCallback<BaseResult<List<FutureDetailsData>>>(){
+                override fun onResponse(response: BaseResult<List<FutureDetailsData>>?, id: Int) {
+                    responseBack(true, response?.data, null)
+                }
+
+                override fun onError(call: Call?, e: Exception?, id: Int) {
+                    responseBack(false, null, Error(e?.message))
+                }
+
+            }
+        )
+    }
+
+
+    /**
+     * 获取企业风管期货成交单信息
+     * @param params Map<String, String> accountID/资金账户ID goodsID/商品ID buyOrSell/买卖方向,0:买 1:卖
+     * @param responseBack Function3<[@kotlin.ParameterName] Boolean, [@kotlin.ParameterName] List<FutureDetailsData>?, [@kotlin.ParameterName] Error?, Unit>
+     */
+    fun queryErmcpTradeDetails(
+        params: Map<String, String>,
+        responseBack: (isSuccess: Boolean, respData: List<FutureDetailsData>?, error: Error?) -> Unit
+    ){
+        MyOkHttpUtils().query(
+            URL = SPUtils.getInstance().getString(Constant.goCommonSearchUrl) + "/Ermcp/QueryErmcpTradeDetails",
+            params = params,
+            type = "1",
+            callback = object : ResponseCallback<BaseResult<List<FutureDetailsData>>>(){
+                override fun onResponse(response: BaseResult<List<FutureDetailsData>>?, id: Int) {
+                    responseBack(true, response?.data, null)
+                }
+
+                override fun onError(call: Call?, e: Exception?, id: Int) {
+                    responseBack(false, null, Error(e?.message))
+                }
+
+            }
+        )
+    }
+
+
+
+    /**
+     * 获取企业风管期货成交单信息
+     * @param params Map<String, String> accountID/资金账户ID marketID/所属市场ID
+     * @param responseBack Function3<[@kotlin.ParameterName] Boolean, [@kotlin.ParameterName] List<FutureDetailsData>?, [@kotlin.ParameterName] Error?, Unit>
+     */
+    fun queryErmcpTradePosition(
+        params: Map<String, String>,
+        responseBack: (isSuccess: Boolean, respData: List<FutureDetailsData>?, error: Error?) -> Unit
+    ){
+        MyOkHttpUtils().query(
+            URL = SPUtils.getInstance().getString(Constant.goCommonSearchUrl) + "/Ermcp/QueryErmcpTradePosition",
+            params = params,
+            type = "1",
+            callback = object : ResponseCallback<BaseResult<List<FutureDetailsData>>>(){
+                override fun onResponse(response: BaseResult<List<FutureDetailsData>>?, id: Int) {
+                    responseBack(true, response?.data, null)
+                }
+
+                override fun onError(call: Call?, e: Exception?, id: Int) {
+                    responseBack(false, null, Error(e?.message))
+                }
+
+            }
+        )
+    }
+
+
+
 }

+ 19 - 0
RMA/app/src/main/java/cn/muchinfo/rma/global/BaseGlobalData.java

@@ -5,6 +5,7 @@ import java.util.Date;
 import java.util.List;
 
 import cn.muchinfo.rma.global.data.AccountData;
+import cn.muchinfo.rma.global.data.FutureDetailsData;
 import cn.muchinfo.rma.global.data.GoodsInfoAndQuotes;
 import cn.muchinfo.rma.global.data.UserAccountData;
 import cn.muchinfo.rma.global.data.account.LoginQueryData;
@@ -70,6 +71,24 @@ public class BaseGlobalData {
      */
     private ArrayList<GoodsInfoAndQuotes> goodsInfoAndQuotesList;
 
+    /**
+     * 持仓头寸信息
+     * @return
+     */
+    private ArrayList<FutureDetailsData> tradePositionList;
+
+
+    public ArrayList<FutureDetailsData> getTradePositionList() {
+        if (tradePositionList == null){
+            tradePositionList = new ArrayList<>();
+        }
+        return tradePositionList;
+    }
+
+    public void setTradePositionList(ArrayList<FutureDetailsData> tradePositionList) {
+        this.tradePositionList = tradePositionList;
+    }
+
     public ArrayList<GoodsInfoAndQuotes> getGoodsInfoAndQuotesList() {
         if (goodsInfoAndQuotesList == null){
             goodsInfoAndQuotesList = new ArrayList<>();

+ 52 - 0
RMA/app/src/main/java/cn/muchinfo/rma/global/data/FutureDetailsData.kt

@@ -0,0 +1,52 @@
+package cn.muchinfo.rma.global.data
+
+/**
+ * 期货单据的综合实体包括成交单委托单和持仓头寸
+ */
+data class FutureDetailsData(
+    val accountid: String = "",//账户ID
+    val buyorsell: String = "",//买卖 - 0:买 1:卖
+    val channelbuildtype: String = "",//开平标志 - 0:无 1:建仓 2:平仓
+    val channelinnerorderstatus: String = "",//委托状态 - 1:委托请求 2:冻结成功 3:委托失败 4:委托部成部失败 5:委托成功 6:全部撤销 7:部成部撤 8:部成部撤部失败 9:全部成交
+    val channeloperatetype: String = "",//操作类型 - 1:正常委托 2:斩仓委托 3:强平委托
+    val closetype: String = "",//平仓方式 - 0:无 1:平今 2:平昨
+    val curexchangerate: String = "",//当前汇率
+    val exchangefullname: String = "",//外部交易所全称
+    val goodscode: String = "",//商品代码(内部)
+    val goodsid: String = "",//商品ID
+    val goodsname: String = "",//商品名称
+    val marketid: String = "",//市场ID
+    val openfreezemargin: String = "",//冻结保证金(冻结交易金额)
+    val orderid: String = "",//委托单号(107+Unix秒时间戳(10位)+2位(MarketServiceID)+xxxx)
+    val orderprice: String = "",//委托价格(账户)
+    val orderqty: String = "",//委托数量
+    val ordertime: String = "",//委托时间
+    val pricemode: String = "",//取价方式 - 1:市价 2: 限价
+    val tradedate: String = "",//交易日(yyyyMMdd)
+    val tradeqty: String = "",//成交数量
+    val closecharge: String = "",//平仓手续费(账户)
+    val closecharge2: String = "",//平仓手续费(商品)
+    val opencharge: String = "",//建仓手续费(账户)
+    val opencharge2: String = "",//建仓手续费(商品)
+    val tradeamount: String = "",//成交金额(账户)
+    val tradeid: String = "",//成交单号(108+Unix秒时间戳(10位)+2位(MarketServiceID)+xxxx)
+    val tradeprice: String = "",//成交价格
+    val tradetime: String = "",//成交时间
+    val agreeunit: String = "",//合约单位
+    val curpositionqty: String = "",//持仓(总仓数量, 期末头寸)
+    val curtdposition: String = "",//今仓数量(期末今日头寸)
+    val curtdpositionenabled: String = "",//今仓可用
+    val decimalplace: String = "",//报价小数位
+    val enableqty: String = "",//可用(总仓可用)
+    val exexchangename: String = "",//外部交易所名称
+    val last: String = "",//现价
+    val openaverageprice: String = "",//开仓均价【头寸变化更新】 = 开仓成本 / 期末头寸 / 合约单位
+    val opencost: String = "",//开仓成本
+    val openpl: String = "",//逐笔浮盈【实时行情更新】(MTP:开仓盈亏、平仓盈亏) 买方向 = (最新价 - 开仓均价) * 买期末头寸 * 合约单位;卖方向 = (开仓均价 - 最新价) * 卖期末头寸 * 合约单位
+    val outgoodscode: String = "",//商品代码(外部)
+    val positionaverageprice: String = "",//持仓均价【头寸变化更新】= 持仓成本 / 期末头寸 / 合约单位
+    val positioncost: String = "",//持仓成本
+    val positionpl: String = "",//盯市浮盈【实时行情更新】(MTP:浮动盈亏、持仓盈亏) 买方向 = (最新价 - 持仓均价) * 买期末头寸 * 合约单位;卖方向 = (持仓均价 - 最新价) * 卖期末头寸 * 合约单位
+    val positionplrate: String = "",//持仓盈亏比例【实时行情更新】 = 持仓盈亏 / 开仓成本
+    val usedmargin: String = ""//占用保证金
+)

+ 22 - 2
RMA/app/src/main/java/cn/muchinfo/rma/view/MainViewModel.kt

@@ -3,6 +3,8 @@ package cn.muchinfo.rma.view
 import androidx.lifecycle.MutableLiveData
 import cn.muchinfo.rma.global.GlobalDataCollection
 import cn.muchinfo.rma.global.database.DataBase
+import cn.muchinfo.rma.netManage.base.InteractiveException
+import cn.muchinfo.rma.view.autoWidget.toArrayList
 import cn.muchinfo.rma.view.base.BaseViewModel
 import kotlinx.coroutines.*
 import mtp.polymer.com.autowidget.utils.TaskUiModel
@@ -32,7 +34,7 @@ class MainViewModel : BaseViewModel() {
             MyApplication.getInstance()?.initializeManager?.getTaAccounts(params = params) { isSuccess, respData, error ->
                 isInitiaDataSuccess.postValue(isSuccess)
                 if (isSuccess) {
-                    getUserAccount()
+                    getUserAccount()//请求成功就继续请求用户账号信息
                     GlobalDataCollection.instance?.accountDataList = respData
                 } else {
                     loadingDialogStatus.postValue(TaskUiModel.idel())
@@ -95,11 +97,29 @@ class MainViewModel : BaseViewModel() {
         MyApplication.getInstance()?.initializeManager?.getUserAccount(params = params){isSuccess, respData, error ->
             isInitiaDataSuccess.postValue(isSuccess)
             if (isSuccess) {
-                loadingDialogStatus.postValue(TaskUiModel.success(msg = "数据初始化成功"))
+                queryErmcpTradePosition()//第三步请求持仓头寸
                 GlobalDataCollection.instance?.userAccountData = respData
             } else {
                 loadingDialogStatus.postValue(TaskUiModel.idel())
             }
         }
     }
+
+    /**
+     * 查询持仓头寸
+     */
+    fun queryErmcpTradePosition(){
+        val params = mutableMapOf<String, String>().apply {
+            put("accountID", GlobalDataCollection.instance?.accountId.toString())
+        }
+        
+        MyApplication.getInstance()?.futureManager?.queryErmcpTradePosition(params = params){isSuccess, respData, error ->  
+            if (isSuccess){
+                loadingDialogStatus.postValue(TaskUiModel.success(msg = "数据初始化成功"))
+                GlobalDataCollection.instance?.tradePositionList = respData?.toArrayList()
+            }else{
+                loadingDialogStatus.postValue(TaskUiModel.failed(InteractiveException(errorMessage = "数据初始化失败")))
+            }
+        }
+    }
 }

+ 75 - 0
RMA/app/src/main/java/cn/muchinfo/rma/view/base/future/trade/GoodsTradeActivity.kt

@@ -71,6 +71,81 @@ class GoodsTradeActivity : BaseActivity<GoodsTradeViewModel>(){
                     marginEnd = autoSize(36)
                 }
             }.lparams(matchParent, autoSize(120))
+
+            linearLayout {
+                gravity = Gravity.CENTER_VERTICAL
+                background = resources.getDrawable(R.color.rma_details_status)
+                emptyView()
+                textView {
+                    text = "权益:1279817249"
+                    textSizeAuto = 31
+                    textColorInt = R.color.rma_yellow_text_color
+                }.lparams(wrapContent, wrapContent)
+
+                emptyView()
+                textView {
+                    text = "可用:1279817249"
+                    textSizeAuto = 31
+                    textColorInt = R.color.rma_yellow_text_color
+                }.lparams(wrapContent, wrapContent)
+
+                emptyView()
+            }.lparams(matchParent, autoSize(70))
+
+            verticalLayout {
+                nestedScrollView {
+                    verticalLayout {
+                        linearLayout {
+                            verticalLayout {
+                                linearLayout {
+                                    gravity = Gravity.CENTER_VERTICAL
+                                    textView {
+                                        text = "品种"
+                                        textSizeAuto = 34
+                                        textColorInt = R.color.hint_text_color
+                                    }.lparams(wrapContent, wrapContent){
+                                        marginStart = autoSize(30)
+                                    }
+                                    emptyView()
+
+                                    textView {
+                                        text = "铁矿石2130"
+                                        textSizeAuto = 34
+                                        textColorInt = R.color.rma_black_33
+                                    }
+
+                                    emptyView()
+
+                                    imageView {
+                                        imageResource = R.mipmap.rma_file_image
+                                    }.lparams(autoSize(48), autoSize(48)){
+                                        marginEnd = autoSize(30)
+                                    }
+
+                                }.lparams(autoSize(90), matchParent)
+                                linearLayout {
+                                    gravity = Gravity.CENTER_VERTICAL
+                                    textView {
+                                        text = "2131"
+                                        textSizeAuto = 31
+                                        textColorInt = R.color.rma_red_color
+                                    }.lparams(wrapContent, wrapContent)
+                                }.lparams(autoSize(90), matchParent)
+                                linearLayout {
+
+                                }.lparams(autoSize(90), matchParent)
+                                linearLayout {
+
+                                }.lparams(autoSize(90), matchParent)
+                            }.lparams(0, autoSize(366),5f)
+
+                            verticalLayout {
+
+                            }.lparams(0, autoSize(366),2f)
+                        }.lparams(matchParent, autoSize(366))
+                    }
+                }
+            }
         }
     }
 

BIN
RMA/app/src/main/res/mipmap-xhdpi/rma_file_image.png


+ 1 - 0
RMA/app/src/main/res/values/colors.xml

@@ -38,6 +38,7 @@
     <color name="rma_dialog_activity_bg_color">#00ffffff</color>
     <color name="rma_report_title_color">#2F8C97</color>
     <color name="rma_account_name_bgcolor">#F38989</color>
+    <color name="rma_red_color">#FF2F2C</color>
 
 
     <color name="pickerview_timebtn_nor">#057dff</color>