|
|
@@ -57,7 +57,9 @@ class HoldViewModel : BaseViewModel() {
|
|
|
private var green: Drawable? = null
|
|
|
private var priceRed: Int = 0
|
|
|
private var priceGreen: Int = 0
|
|
|
+ private var priceBlack: Int = 0
|
|
|
private var fragment : Fragment? = null
|
|
|
+ private var refreshByQuote : Boolean = false
|
|
|
var futureHoldData: FutureHoldData? = null // 当前选择的item对应的数据
|
|
|
|
|
|
init {
|
|
|
@@ -69,6 +71,7 @@ class HoldViewModel : BaseViewModel() {
|
|
|
green = context?.getDrawable(R.drawable.rma_green)
|
|
|
priceGreen = context?.getColor(R.color.p_price_green)!!
|
|
|
priceRed = context.getColor(R.color.p_price_red)
|
|
|
+ priceBlack = context.getColor(R.color.rma_black_33)
|
|
|
}
|
|
|
|
|
|
override fun getItemCount(): Int {
|
|
|
@@ -80,6 +83,11 @@ class HoldViewModel : BaseViewModel() {
|
|
|
notifyDataSetChanged()
|
|
|
}
|
|
|
|
|
|
+ //刷新item是否是由于行情推送
|
|
|
+ fun updateByQuote(refreshByQuote : Boolean){
|
|
|
+ this.refreshByQuote = refreshByQuote
|
|
|
+ }
|
|
|
+
|
|
|
inner class HoldHolder(itemView: View?) : RecyclerView.ViewHolder(itemView!!) {
|
|
|
var idGoodsName = itemView?.findViewById<TextView>(R.id.id_goods_name) // 商品名称
|
|
|
var idTransDirection = itemView?.findViewById<TextView>(R.id.id_trans_direction) // 方向
|
|
|
@@ -110,16 +118,57 @@ class HoldViewModel : BaseViewModel() {
|
|
|
itemData?.openaverageprice.toString()//开仓均价【头寸变化更新】 = 开仓成本 / 期末头寸 / 合约单位
|
|
|
holder.idHoldAveragePrice?.text =
|
|
|
itemData?.positionaverageprice.toString()//持仓均价【头寸变化更新】= 持仓成本 / 期末头寸 / 合约单位
|
|
|
- holder.idZPl?.text =
|
|
|
- NumberUtils.roundNum(itemData?.positionpl.toString(),2)//盯市浮盈【实时行情更新】(MTP:浮动盈亏、持仓盈亏) 买方向 = (最新价 - 持仓均价) * 买期末头寸 * 合约单位;卖方向 = (持仓均价 - 最新价) * 卖期末头寸 * 合约单位
|
|
|
- holder.idPlp?.text = itemData?.positionplrate.toString()//持仓盈亏比例【实时行情更新】 = 持仓盈亏 / 开仓成本
|
|
|
- holder.id_pl?.text =
|
|
|
- NumberUtils.roundNum(itemData?.openpl.toString(),2)//逐笔浮盈【实时行情更新】(MTP:开仓盈亏、平仓盈亏) 买方向 = (最新价 - 开仓均价) * 买期末头寸 * 合约单位;卖方向 = (开仓均价 - 最新价) * 卖期末头寸 * 合约单位
|
|
|
- holder.idMargin?.text = itemData?.usedmargin.toString()//占用保证金
|
|
|
+ holder.idMargin?.text = itemData?.usedmargin.toString()//占用保证金
|
|
|
+
|
|
|
+ if (refreshByQuote){//行情下发的推送则自己算一遍
|
|
|
+ /**
|
|
|
+ * 获取基本信息(主要计算持仓浮动盈亏和平仓浮动盈亏)
|
|
|
+ * 盯市浮盈【实时行情更新】(MTP:浮动盈亏、持仓盈亏) 买方向 = (最新价 - 持仓均价) * 买期末头寸 * 合约单位;卖方向 = (持仓均价 - 最新价) * 卖期末头寸 * 合约单位
|
|
|
+ * 逐笔浮盈【实时行情更新】(MTP:开仓盈亏、平仓盈亏) 买方向 = (最新价 - 开仓均价) * 买期末头寸 * 合约单位;卖方向 = (开仓均价 - 最新价) * 卖期末头寸 * 合约单位
|
|
|
+ */
|
|
|
+ val quoteData = GlobalDataCollection.instance?.goodsInfoAndQuotesList?.find { itemData?.outgoodscode == it.outgoodscode }
|
|
|
+ if (quoteData != null){
|
|
|
+ itemData?.calculate()
|
|
|
+ holder.idZPl?.text =
|
|
|
+ NumberUtils.roundNum(itemData?.positionpl.toString(),2)
|
|
|
+ holder.idPlp?.text = itemData?.positionplrate.toString()
|
|
|
+ holder.id_pl?.text =
|
|
|
+ NumberUtils.roundNum(itemData?.openpl.toString(),2)
|
|
|
+ }else{
|
|
|
+ holder.idZPl?.text =
|
|
|
+ NumberUtils.roundNum(itemData?.positionpl.toString(),2)
|
|
|
+ holder.idPlp?.text = itemData?.positionplrate.toString()
|
|
|
+ holder.id_pl?.text =
|
|
|
+ NumberUtils.roundNum(itemData?.openpl.toString(),2)
|
|
|
+ }
|
|
|
+ }else{//第一次请求则直接拿go服务给的值
|
|
|
+ holder.idZPl?.text =
|
|
|
+ NumberUtils.roundNum(itemData?.positionpl.toString(),2)
|
|
|
+ holder.idPlp?.text = itemData?.positionplrate.toString()
|
|
|
+ holder.id_pl?.text =
|
|
|
+ NumberUtils.roundNum(itemData?.openpl.toString(),2)
|
|
|
+ }
|
|
|
+
|
|
|
+ if (itemData?.positionpl == 0.0){
|
|
|
+ holder.idZPl?.setTextColor(priceBlack)
|
|
|
+ holder.idPlp?.setTextColor(priceBlack)
|
|
|
+ holder.id_pl?.setTextColor(priceBlack)
|
|
|
+ }else if (itemData?.positionpl ?: 0.0 > 0){
|
|
|
+ holder.idZPl?.setTextColor(priceRed)
|
|
|
+ holder.idPlp?.setTextColor(priceRed)
|
|
|
+ holder.id_pl?.setTextColor(priceRed)
|
|
|
+ }else if (itemData?.positionpl ?: 0.0 < 0){
|
|
|
+ holder.idZPl?.setTextColor(priceGreen)
|
|
|
+ holder.idPlp?.setTextColor(priceGreen)
|
|
|
+ holder.id_pl?.setTextColor(priceGreen)
|
|
|
+ }
|
|
|
+
|
|
|
if (list?.get(position)?.buyorsell == 0) {
|
|
|
holder.idTransDirection?.text = context?.resources?.getString(R.string.str_buy)
|
|
|
+ holder.idTransDirection?.setTextColor(priceRed)
|
|
|
} else {
|
|
|
holder.idTransDirection?.text = context?.resources?.getString(R.string.str_sell)
|
|
|
+ holder.idTransDirection?.setTextColor(priceGreen)
|
|
|
}
|
|
|
|
|
|
/** 快捷反手 */
|