|
|
@@ -104,14 +104,15 @@ class HoldViewModel : BaseViewModel() {
|
|
|
/**
|
|
|
* 获取配置器。
|
|
|
*/
|
|
|
- fun getAdapter(fragment : Fragment): RecyclerView.Adapter<HoldAdapter.HoldHolder> {
|
|
|
- return HoldAdapter(context,fragment)
|
|
|
+ fun getAdapter(fragment: Fragment): RecyclerView.Adapter<HoldAdapter.HoldHolder> {
|
|
|
+ return HoldAdapter(context, fragment)
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 通用的适配器。
|
|
|
*/
|
|
|
- inner class HoldAdapter(context: Context?,fragment : Fragment) : RecyclerView.Adapter<HoldAdapter.HoldHolder>() {
|
|
|
+ inner class HoldAdapter(context: Context?, fragment: Fragment) :
|
|
|
+ RecyclerView.Adapter<HoldAdapter.HoldHolder>() {
|
|
|
private var list: ArrayList<FutureHoldData>? = null
|
|
|
private var inflater: LayoutInflater? = null
|
|
|
private var context: Context? = null
|
|
|
@@ -120,8 +121,8 @@ class HoldViewModel : BaseViewModel() {
|
|
|
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
|
|
|
+ private var fragment: Fragment? = null
|
|
|
+ private var refreshByQuote: Boolean = false
|
|
|
var futureHoldData: FutureHoldData? = null // 当前选择的item对应的数据
|
|
|
|
|
|
init {
|
|
|
@@ -146,7 +147,7 @@ class HoldViewModel : BaseViewModel() {
|
|
|
}
|
|
|
|
|
|
//刷新item是否是由于行情推送
|
|
|
- fun updateByQuote(refreshByQuote : Boolean){
|
|
|
+ fun updateByQuote(refreshByQuote: Boolean) {
|
|
|
this.refreshByQuote = refreshByQuote
|
|
|
}
|
|
|
|
|
|
@@ -180,46 +181,51 @@ class HoldViewModel : BaseViewModel() {
|
|
|
itemData?.openaverageprice.toString()//开仓均价【头寸变化更新】 = 开仓成本 / 期末头寸 / 合约单位
|
|
|
holder.idHoldAveragePrice?.text =
|
|
|
itemData?.positionaverageprice.toString()//持仓均价【头寸变化更新】= 持仓成本 / 期末头寸 / 合约单位
|
|
|
- holder.idMargin?.text = itemData?.usedmargin.toString()//占用保证金
|
|
|
+ holder.idMargin?.text = itemData?.usedmargin.toString()//占用保证金
|
|
|
|
|
|
- if (refreshByQuote){//行情下发的推送则自己算一遍
|
|
|
+ if (refreshByQuote) {//行情下发的推送则自己算一遍
|
|
|
/**
|
|
|
* 获取基本信息(主要计算持仓浮动盈亏和平仓浮动盈亏)
|
|
|
* 盯市浮盈【实时行情更新】(MTP:浮动盈亏、持仓盈亏) 买方向 = (最新价 - 持仓均价) * 买期末头寸 * 合约单位;卖方向 = (持仓均价 - 最新价) * 卖期末头寸 * 合约单位
|
|
|
* 逐笔浮盈【实时行情更新】(MTP:开仓盈亏、平仓盈亏) 买方向 = (最新价 - 开仓均价) * 买期末头寸 * 合约单位;卖方向 = (开仓均价 - 最新价) * 卖期末头寸 * 合约单位
|
|
|
*/
|
|
|
- val quoteData = GlobalDataCollection.instance?.goodsInfoAndQuotesList?.find { itemData?.outgoodscode == it.outgoodscode }
|
|
|
- if (quoteData != null){
|
|
|
+ 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()
|
|
|
+ NumberUtils.roundNum(itemData?.positionpl.toString(), 2)
|
|
|
+ holder.idPlp?.text =
|
|
|
+ itemData?.positionplrate?.times(100.0)
|
|
|
+ ?.let { NumberUtils.roundNum(it, 2) + "%" }
|
|
|
holder.id_pl?.text =
|
|
|
- NumberUtils.roundNum(itemData?.openpl.toString(),2)
|
|
|
- }else{
|
|
|
+ NumberUtils.roundNum(itemData?.openpl.toString(), 2)
|
|
|
+ } else {
|
|
|
holder.idZPl?.text =
|
|
|
- NumberUtils.roundNum(itemData?.positionpl.toString(),2)
|
|
|
- holder.idPlp?.text = itemData?.positionplrate.toString()
|
|
|
+ NumberUtils.roundNum(itemData?.positionpl.toString(), 2)
|
|
|
+ holder.idPlp?.text = itemData?.positionplrate?.times(100.0)
|
|
|
+ ?.let { NumberUtils.roundNum(it, 2) + "%" }
|
|
|
holder.id_pl?.text =
|
|
|
- NumberUtils.roundNum(itemData?.openpl.toString(),2)
|
|
|
+ NumberUtils.roundNum(itemData?.openpl.toString(), 2)
|
|
|
}
|
|
|
- }else{//第一次请求则直接拿go服务给的值
|
|
|
+ } else {//第一次请求则直接拿go服务给的值
|
|
|
holder.idZPl?.text =
|
|
|
- NumberUtils.roundNum(itemData?.positionpl.toString(),2)
|
|
|
- holder.idPlp?.text = itemData?.positionplrate.toString()
|
|
|
+ NumberUtils.roundNum(itemData?.positionpl.toString(), 2)
|
|
|
+ holder.idPlp?.text = itemData?.positionplrate?.times(100.0)
|
|
|
+ ?.let { NumberUtils.roundNum(it, 2) + "%" }
|
|
|
holder.id_pl?.text =
|
|
|
- NumberUtils.roundNum(itemData?.openpl.toString(),2)
|
|
|
+ NumberUtils.roundNum(itemData?.openpl.toString(), 2)
|
|
|
}
|
|
|
|
|
|
- if (itemData?.positionpl == 0.0){
|
|
|
+ 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){
|
|
|
+ } 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){
|
|
|
+ } else if (itemData?.positionpl ?: 0.0 < 0) {
|
|
|
holder.idZPl?.setTextColor(priceGreen)
|
|
|
holder.idPlp?.setTextColor(priceGreen)
|
|
|
holder.id_pl?.setTextColor(priceGreen)
|
|
|
@@ -240,7 +246,7 @@ class HoldViewModel : BaseViewModel() {
|
|
|
setMessage("确认将该合约的所有持仓进行快捷反手操作?")
|
|
|
addAction("取消") { dialog, _ -> dialog.dismiss() }
|
|
|
addAction("确定") { dialog, _ ->
|
|
|
- commitDealData(true ,true)
|
|
|
+ commitDealData(true, true)
|
|
|
dialog.dismiss()
|
|
|
}
|
|
|
}?.show()
|
|
|
@@ -253,7 +259,7 @@ class HoldViewModel : BaseViewModel() {
|
|
|
setMessage("确认将该合约的所有持仓进行快捷反手操作?")
|
|
|
addAction("取消") { dialog, _ -> dialog.dismiss() }
|
|
|
addAction("确定") { dialog, _ ->
|
|
|
- commitDealData(false ,true)
|
|
|
+ commitDealData(false, true)
|
|
|
dialog.dismiss()
|
|
|
}
|
|
|
}?.show()
|
|
|
@@ -273,7 +279,8 @@ class HoldViewModel : BaseViewModel() {
|
|
|
OrderDetail.start(
|
|
|
context!!,
|
|
|
data,
|
|
|
- context?.resources?.getString(R.string.str_order_detail_head))
|
|
|
+ context?.resources?.getString(R.string.str_order_detail_head)
|
|
|
+ )
|
|
|
}
|
|
|
|
|
|
if (list?.get(position)?.selected == true) {
|
|
|
@@ -308,13 +315,13 @@ class HoldViewModel : BaseViewModel() {
|
|
|
|
|
|
// 选择i
|
|
|
list?.forEach { itemValue ->
|
|
|
- if (itemValue.goodsid == futureHoldData?.goodsid){
|
|
|
- if (itemValue.buyorsell == futureHoldData?.buyorsell){
|
|
|
+ if (itemValue.goodsid == futureHoldData?.goodsid) {
|
|
|
+ if (itemValue.buyorsell == futureHoldData?.buyorsell) {
|
|
|
itemValue.selected = !itemValue.selected
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
itemValue.selected = false
|
|
|
}
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
itemValue.selected = false
|
|
|
}
|
|
|
}
|
|
|
@@ -330,13 +337,13 @@ class HoldViewModel : BaseViewModel() {
|
|
|
* 操作请求
|
|
|
* @param isClose Boolean 是否是平仓单
|
|
|
*/
|
|
|
- fun commitDealData(isBackHand : Boolean,isClose: Boolean) {
|
|
|
+ fun commitDealData(isBackHand: Boolean, isClose: Boolean) {
|
|
|
(fragment as HoldFragment).loadingDialogStatus.postValue(TaskUiModel.inFlight())
|
|
|
var tradePrice = 0.0 //交易价格
|
|
|
- var itemData : FutureHoldData
|
|
|
- if (isClose){
|
|
|
+ var itemData: FutureHoldData
|
|
|
+ if (isClose) {
|
|
|
itemData = futureHoldData ?: FutureHoldData()
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
itemData = GlobalDataCollection.instance?.itemData ?: FutureHoldData()
|
|
|
}
|
|
|
val datas = ChannelOrderReqData()
|
|
|
@@ -365,7 +372,7 @@ class HoldViewModel : BaseViewModel() {
|
|
|
if (isBackHand) {
|
|
|
GlobalDataCollection.instance?.setItemData(itemData)
|
|
|
(fragment as HoldFragment).isBackhandByLose = 1
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
(fragment as HoldFragment).isBackhandByLose = 0
|
|
|
}
|
|
|
datas.clientOrderTime = TimeUtils.getNowString() // 客户端委托时间 当前时间
|
|
|
@@ -418,16 +425,22 @@ class HoldViewModel : BaseViewModel() {
|
|
|
GlobalScope.launch {
|
|
|
MyApplication.getInstance()?.futureManager?.tradeRequest(data = datas) { isCompleted, err ->
|
|
|
if (isCompleted) {
|
|
|
- if ((fragment as HoldFragment).isBackhandByLose == 1){
|
|
|
- commitDealData(false ,false)
|
|
|
- }else{
|
|
|
- (fragment as HoldFragment).loadingDialogStatus.postValue(TaskUiModel.success(msg = "请求成功"))
|
|
|
+ if ((fragment as HoldFragment).isBackhandByLose == 1) {
|
|
|
+ commitDealData(false, false)
|
|
|
+ } else {
|
|
|
+ (fragment as HoldFragment).loadingDialogStatus.postValue(
|
|
|
+ TaskUiModel.success(
|
|
|
+ msg = "请求成功"
|
|
|
+ )
|
|
|
+ )
|
|
|
(fragment as HoldFragment).onRefresh()
|
|
|
}
|
|
|
- }else{
|
|
|
- (fragment as HoldFragment).loadingDialogStatus.postValue(TaskUiModel.failed(
|
|
|
- InteractiveException(errorMessage = err?.message!!)
|
|
|
- ))
|
|
|
+ } else {
|
|
|
+ (fragment as HoldFragment).loadingDialogStatus.postValue(
|
|
|
+ TaskUiModel.failed(
|
|
|
+ InteractiveException(errorMessage = err?.message!!)
|
|
|
+ )
|
|
|
+ )
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -457,5 +470,4 @@ class HoldViewModel : BaseViewModel() {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
}
|