|
|
@@ -9,17 +9,18 @@ import android.widget.TextView
|
|
|
import androidx.lifecycle.MutableLiveData
|
|
|
import androidx.recyclerview.widget.RecyclerView
|
|
|
import cn.muchinfo.rma.R
|
|
|
-import cn.muchinfo.rma.business.future.FutureManager
|
|
|
+import cn.muchinfo.rma.business.future.adapter.ChannelOrderReqData
|
|
|
import cn.muchinfo.rma.global.GlobalDataCollection
|
|
|
-import cn.muchinfo.rma.global.data.futureOrders.FutureEntrustData
|
|
|
import cn.muchinfo.rma.global.data.futureOrders.FutureHoldData
|
|
|
+import cn.muchinfo.rma.view.MyApplication
|
|
|
import cn.muchinfo.rma.view.autoWidget.onThrottleFirstClick
|
|
|
import cn.muchinfo.rma.view.base.BaseViewModel
|
|
|
-import cn.muchinfo.rma.view.base.app.Constant
|
|
|
+import cn.muchinfo.rma.view.base.app.FutureConstent
|
|
|
import cn.muchinfo.rma.view.eventbus.EventConstent
|
|
|
-import cn.muchinfo.rma.view.eventbus.MessageEvent
|
|
|
import cn.muchinfo.rma.view.eventbus.TradeMessageEvent
|
|
|
-import com.blankj.utilcode.util.SPUtils
|
|
|
+import com.blankj.utilcode.util.TimeUtils
|
|
|
+import kotlinx.coroutines.GlobalScope
|
|
|
+import kotlinx.coroutines.launch
|
|
|
import org.greenrobot.eventbus.EventBus
|
|
|
|
|
|
/**
|
|
|
@@ -81,20 +82,67 @@ class HoldViewModel : BaseViewModel() {
|
|
|
var idHoldAveragePrice = itemView?.findViewById<TextView>(R.id.id_hold_average_price) // 持仓均价
|
|
|
var idZPl = itemView?.findViewById<TextView>(R.id.id_zpl) // 盯市浮盈
|
|
|
var idPlp = itemView?.findViewById<TextView>(R.id.id_plp) // 盈亏比例
|
|
|
+ var id_pl = itemView?.findViewById<TextView>(R.id.id_pl)//逐笔浮盈
|
|
|
var idMargin = itemView?.findViewById<TextView>(R.id.id_margin) // 保证金
|
|
|
+
|
|
|
+ var quick_backhand = itemView?.findViewById<TextView>(R.id.quick_backhand)//快捷反手
|
|
|
+ var key_positions = itemView?.findViewById<TextView>(R.id.key_positions)//一键平仓
|
|
|
+ var id_chart = itemView?.findViewById<TextView>(R.id.id_chart)//图表
|
|
|
+ var id_entrust_detail = itemView?.findViewById<TextView>(R.id.id_entrust_detail)//详情
|
|
|
}
|
|
|
|
|
|
override fun onBindViewHolder(holder: HoldHolder, position: Int) {
|
|
|
- holder.idGoodsName?.text = list?.get(position)?.goodsname
|
|
|
- holder.idAvailable?.text = list?.get(position)?.enableqty.toString() // 可用(总仓可用)
|
|
|
- holder.idHoldTotal?.text = list?.get(position)?.curpositionqty.toString() // 持仓(总仓数量, 期末头寸)
|
|
|
+ holder.itemView.tag = list?.get(position)
|
|
|
+ val itemData = list?.get(position)
|
|
|
+ holder.idGoodsName?.text = itemData?.goodsname
|
|
|
+ holder.idAvailable?.text = itemData?.enableqty.toString() // 可用(总仓可用)
|
|
|
+ holder.idHoldTotal?.text = itemData?.curpositionqty.toString() // 持仓(总仓数量, 期末头寸)
|
|
|
+ holder.idOpenAveragePrice?.text = itemData?.openaverageprice.toString()//开仓均价【头寸变化更新】 = 开仓成本 / 期末头寸 / 合约单位
|
|
|
+ holder.idHoldAveragePrice?.text = itemData?.positionaverageprice.toString()//持仓均价【头寸变化更新】= 持仓成本 / 期末头寸 / 合约单位
|
|
|
+ holder.idZPl?.text = itemData?.positionpl.toString()//盯市浮盈【实时行情更新】(MTP:浮动盈亏、持仓盈亏) 买方向 = (最新价 - 持仓均价) * 买期末头寸 * 合约单位;卖方向 = (持仓均价 - 最新价) * 卖期末头寸 * 合约单位
|
|
|
+ holder.idPlp?.text = itemData?.positionplrate.toString()//持仓盈亏比例【实时行情更新】 = 持仓盈亏 / 开仓成本
|
|
|
+ holder.id_pl?.text = itemData?.openpl.toString()//逐笔浮盈【实时行情更新】(MTP:开仓盈亏、平仓盈亏) 买方向 = (最新价 - 开仓均价) * 买期末头寸 * 合约单位;卖方向 = (开仓均价 - 最新价) * 卖期末头寸 * 合约单位
|
|
|
+ holder.idMargin?.text = itemData?.usedmargin.toString()//占用保证金
|
|
|
if (list?.get(position)?.buyorsell == 0) {
|
|
|
holder.idTransDirection?.text = context?.resources?.getString(R.string.str_buy)
|
|
|
} else {
|
|
|
holder.idTransDirection?.text = context?.resources?.getString(R.string.str_sell)
|
|
|
}
|
|
|
|
|
|
+ /** 快捷反手 */
|
|
|
+ holder.quick_backhand?.onThrottleFirstClick {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 一键平仓 **/
|
|
|
+ holder.key_positions?.onThrottleFirstClick {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 图表 **/
|
|
|
+ holder.id_chart?.onThrottleFirstClick {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 详情 **/
|
|
|
+ holder.id_entrust_detail?.onThrottleFirstClick {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if (list?.get(position)?.selected == true) {
|
|
|
+ holder.quick_backhand?.visibility = View.VISIBLE
|
|
|
+ holder.key_positions?.visibility = View.VISIBLE
|
|
|
+ holder.id_chart?.visibility = View.VISIBLE
|
|
|
+ holder.id_entrust_detail?.visibility = View.VISIBLE
|
|
|
+ } else if(list?.get(position)?.selected == false) {
|
|
|
+ holder.quick_backhand?.visibility = View.GONE
|
|
|
+ holder.key_positions?.visibility = View.GONE
|
|
|
+ holder.id_chart?.visibility = View.GONE
|
|
|
+ holder.id_entrust_detail?.visibility = View.GONE
|
|
|
+ }
|
|
|
+
|
|
|
holder.itemView.onThrottleFirstClick {
|
|
|
+ clickItem(it!!)
|
|
|
val data = list?.get(position)
|
|
|
EventBus.getDefault().post(TradeMessageEvent(messageType = EventConstent.TRADEGOODSID,goodsId = data?.goodsid.toString(),buyOrSell = data?.buyorsell ?: 0,outGoodsCode = data?.outgoodscode ?: ""))
|
|
|
}
|
|
|
@@ -120,6 +168,119 @@ class HoldViewModel : BaseViewModel() {
|
|
|
return HoldHolder(inflater?.inflate(R.layout.hold_item, parent, false))
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 操作请求
|
|
|
+ * @param isClose Boolean 是否是平仓单
|
|
|
+ */
|
|
|
+ private fun commitDealData(isClose: Boolean) {
|
|
|
+ val datas = ChannelOrderReqData()
|
|
|
+ datas.setAccountID(GlobalDataCollection.instance?.accountId ?: 0) // 交易账号
|
|
|
+ val goodsQuote = GlobalDataCollection.instance?.getmGoodsInfoClass()?.get(futureHoldData?.outgoodscode)
|
|
|
+ if (isClose) {
|
|
|
+ if (futureHoldData?.buyorsell == 0) {
|
|
|
+ //平仓---平买单,方向是卖
|
|
|
+ datas.setBuyOrSell(0)
|
|
|
+ } else {
|
|
|
+ //平仓---平卖单,方向是买
|
|
|
+ datas.setBuyOrSell(1)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ datas.setBuyOrSell(futureHoldData?.buyorsell ?: 0)
|
|
|
+ }
|
|
|
+ datas.clientOrderTime = TimeUtils.getNowString() // 客户端委托时间 当前时间
|
|
|
+ datas.clientType = 3 // 客户端类型: 1客户端 3 手机端 android
|
|
|
+ datas.goodsID = futureHoldData?.goodsid ?: 0//商品id
|
|
|
+ datas.loginID = GlobalDataCollection.instance?.loginRsp?.loginID ?: 0 //登录账号
|
|
|
+
|
|
|
+ datas.marketID = futureHoldData?.marketid ?: 0
|
|
|
+ datas.validType = 1 // 有效类型-1当日有效
|
|
|
+ datas.channelOperateType = FutureConstent.ChannelOperateType_ORDER // 操作类型 1:正常类型 默认写死???
|
|
|
+ datas.channelOrderSrc = 1 // 单据来源委托来源-1:客户端 //默认写死?
|
|
|
+ datas.hedgeFlag = 0 // 投机套保标志-0:无
|
|
|
+// if (goodsQuote.getQuoteDay() != null && goodsInfo.getQuoteDay().getAsk() != null) {
|
|
|
+// val decial: Int = goodsInfo.getGoodsInfo().getDecimalPlace()
|
|
|
+// val setp: Double
|
|
|
+// setp = if ("0" == overDot) { //如果没有拿到超价点数则按照原来的计算吧
|
|
|
+// goodsInfo.getGoodsInfo().getQuoteMinUnit() * Math.pow(
|
|
|
+// 10.0,
|
|
|
+// -goodsInfo.getGoodsInfo().getDecimalPlace()
|
|
|
+// )
|
|
|
+// } else {
|
|
|
+// goodsInfo.getGoodsInfo().getQuoteMinUnit() * Math.pow(
|
|
|
+// 10.0,
|
|
|
+// -goodsInfo.getGoodsInfo().getDecimalPlace()
|
|
|
+// ) * java.lang.Double.valueOf(overDot)
|
|
|
+// }
|
|
|
+// val askLimitPrice: String = Utils.roundNum(
|
|
|
+// if (java.lang.Double.valueOf(
|
|
|
+// goodsInfo.getQuoteDay().getAsk()
|
|
|
+// ) != 0
|
|
|
+// ) java.lang.Double.valueOf(
|
|
|
+// goodsInfo.getQuoteDay().getAsk()
|
|
|
+// ) + setp /*limitStep*/ else 0, decial
|
|
|
+// )
|
|
|
+// val bidLimitPrice: String = Utils.roundNum(
|
|
|
+// if (java.lang.Double.valueOf(
|
|
|
+// goodsInfo.getQuoteDay().getBid()
|
|
|
+// ) != 0
|
|
|
+// ) java.lang.Double.valueOf(
|
|
|
+// goodsInfo.getQuoteDay().getBid()
|
|
|
+// ) - setp /*limitStep*/ else 0, decial
|
|
|
+// )
|
|
|
+// if (buyOrSell == 0) {
|
|
|
+// tradePrice = bidLimitPrice.toDouble()
|
|
|
+// } else {
|
|
|
+// tradePrice = askLimitPrice.toDouble()
|
|
|
+// }
|
|
|
+// }
|
|
|
+// datas.orderPrice = orderPrice.toDouble()
|
|
|
+ datas.orderQty = futureHoldData?.enableqty?.toLong() ?: 0
|
|
|
+
|
|
|
+ if (isClose) {
|
|
|
+ // 平仓
|
|
|
+ datas.closeType = 2
|
|
|
+ datas.channelBuildType = FutureConstent.eChannelBuildType_CLOSE // 下单类型 建仓还是平仓
|
|
|
+ } else {
|
|
|
+ // 买卖建仓
|
|
|
+ datas.closeType = 1
|
|
|
+ datas.channelBuildType = FutureConstent.eChannelBuildType_OPEN // 下单类型 建仓还是平仓
|
|
|
+ }
|
|
|
+ datas.priceMode = FutureConstent.PriceMode_PRICEMODE_LIMIT // 限价
|
|
|
+// datas.setCloseTodayQty(amountInputEdittext.text.toString().toLong())
|
|
|
+// if (goodsInfo.getInnerDealMode() === 3) {
|
|
|
+// if (mTradeSummaryData != null) {
|
|
|
+// val todayAvailQty: String =
|
|
|
+// java.lang.String.valueOf(mTradeSummaryData.getTodayAvailQty())
|
|
|
+// if (mTradeSummaryData.getTodayAvailQty() > 0) { //
|
|
|
+// if (mTradeSummaryData.getTodayAvailQty() > tradeNum) { // 如果平今的大于输入的数量,那就不要使用平今数量,直接赋值tradeNum给CloseTodayQty
|
|
|
+// datas.setCloseTodayQty(java.lang.Double.valueOf(tradeNum).toLong())
|
|
|
+// } else {
|
|
|
+// datas.setCloseTodayQty(
|
|
|
+// java.lang.Double.valueOf(todayAvailQty.trim { it <= ' ' }).toLong()
|
|
|
+// )
|
|
|
+// }
|
|
|
+// } else {
|
|
|
+// datas.setCloseTodayQty(0)
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+ datas.setTimeValidType(FutureConstent.ValidTypeEnum_VALIDTYPE_DR) // 时间有效类型 默认写死当日有效
|
|
|
+ datas.setRelatedID(0) // 关联单号 默认写死
|
|
|
+ datas.setServiceTime("") //服务端时间string
|
|
|
+ // datas.setIp(PolApplication.getIPAddress(getContext()));B
|
|
|
+// val bbb: String = Utils.getCommonIp()
|
|
|
+// datas.setIp(bbb)
|
|
|
+ datas.setValidtime("") // 有效时间string
|
|
|
+ GlobalScope.launch {
|
|
|
+ MyApplication.getInstance()?.futureManager?.tradeRequest(data = datas){isCompleted, err ->
|
|
|
+ if (isCompleted){
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -127,11 +288,11 @@ class HoldViewModel : BaseViewModel() {
|
|
|
*/
|
|
|
fun queryHold() {
|
|
|
val params = mutableMapOf<String, String>()
|
|
|
- params["accountID"] = SPUtils.getInstance().getLong(Constant.SELECT_ACCOUNT_ID).toString()
|
|
|
+ params["accountID"] = GlobalDataCollection.instance?.accountId.toString()
|
|
|
// if (marketID != null) {
|
|
|
// params["marketID"] = marketID!!
|
|
|
// }
|
|
|
- FutureManager().queryErmcpTradePosition(params) { isSuccess, respData, _ ->
|
|
|
+ MyApplication.getInstance()?.futureManager?.queryErmcpTradePosition(params) { isSuccess, respData, _ ->
|
|
|
if (isSuccess && !respData!!.isNullOrEmpty()) {
|
|
|
list = respData as ArrayList<FutureHoldData>
|
|
|
holdLiveData.value = list
|