第一步:问题的定性。问题出在哪里,客户表示缺失了一条rule,但这条rule本身就不应该存在,它所对应的数据就不存在。 由此得到,问题出在了数据计算上。
第二步:问题细化。数据计算理论上来说不会有大问题,因为包括测试和uat,再加上prod,前前后后得有三个月,都没出问题的情况下,突然跟我说数据有问题,我也不知道该从什么地方下手,但可以做的是从错误的数据开始,倒推到源头,看是哪个会有问题。
第三步:追溯问题,在将当天相关类型(某个数据源表的当天所有数据)导出为excel之后,发现在tradeEntry方面并没有出现改问题,问题到此出现停滞。
第四步:从直接的数据,而非最终的数据源来判断,在这里我找到了position的数据,这些可以直接反应出数据的问题,事实上也确实有问题,这时候我突然也明白了为什么我从tradeEntry上找不到答案了,因为我根本没有用它,我们用的是trade,这里还有一个小的问题,trade在从uat导出的时候,保存为excel文件,txt文件都是可以的,在转换进excel时,空格就是划分。
第五步:最终定位,事实上,客户在prod做了一个我个人非常希望的操作,它把那个rule配上去了,然后把错误的结果展示出来了,这就很灵性了,从0.01的journal上,我可以有9成的把握,问题出在了精度上(客户的这一步比较早,差不多 问题还在第三步的时候就执行了,当然在后面的实践中也被验证了。)
第六步:精度问题的分析。在处理过程中,对应trade有两次处理,一次是trade进入系统前,amount的计算–这里采用的是考虑第三位的保留两位小数。一次是在系统中,这里也是保留两位小数,但里面有一个精度问题,在采用bigDecimal运算的时候如果使用的是double转bigdecimal,就会出现精度的丢失,一定要string转bigDecimal,此次的问题就在于0.315在转换过程中变成了0.31499999,直接导致差了0.01.
插曲:发现了还存在第三种精度丢失的情况,如果是从页面录入的trade,就会直接截取小数点后两位,不考虑任何进位,本来以为跟我这个有关,但一想到这些trade,理论上都是从外部进来的,就不可能会有这种情况,但,最后还是觉得会有一点问题。
题外话,但是也是在中途折磨我的一个东西。
git分支冲突的解决。如果是prod有冲突,应该就地拉出一个without的分支,保存在本地,之后所有需要经过prod的操作,都从原分支开始,再合到without里面去。
以下是trade的数据,数据繁多,但关键的就是quantity*price=amount,这里就存在了差值。
*************************** 1. row ***************************
id: 291796
trade_id: TD1126886
explode_id: EX446486
deal_id: CS21777
version: 1212
action: ADD
link_id:
external_ref_id: 63aea4c7e7a2446fbc0edad9305c79d9
source: System
exchange_id: 0
clearing_house_id: 0
company_id: 1212
contra_broker_id: 251
account_id: 100001117
sub_account: S00
account_type: 06
order_type: NULL
order_method:
order_cancel_reason:
cross_account_id: 100001074
cross_account_type: 06
trade_date: 2020-04-28
fixing_date: NULL
settlement_date: 2020-04-30
settlement_date_2: NULL
currency: ZAR
quantity: 144850.0000000
quantity_2: 0.0000000
amount: 2704045.3100000
currency_2: USD
amount_2: 144850.0000000
buy_sell_indicator: B
sell_type:
roll_type: 0
product_id: 5644
security_type: FXSpot
member_id: 1212
execution_broker_id: 0
execution_time: 2020-04-28 00:00:00.001
average_price_indicator: 1
fill_price: 18.6679000
fill_price_2: 0.0000000
interest_points: 0.0000000
interest_points_2: 0.0000000
markup: 0.0000000
blotter_code: FXST
capacity:
business_date: 2020-04-28
create_time: 2020-04-29 02:06:35
update_time: 4821-12-27 00:00:00
create_by: System
update_by: System
remark: Give-up
order_channel: EA-Trade
status: 1
open_or_close: NULL
pb_account_id: 100001087
trade_type: C
roll_trade_type:
roll_trade_id:
standard_spot: 1
sequence: 1
cash_settled: 1
waive_commission: 1
for_delivery: 0
execution_only: 1
cfd: 0
inverted: NULL
*************************** 2. row ***************************
id: 291803
trade_id: TD1126887
explode_id: EX446487
deal_id: CS21777
version: 1212
action: ADD
link_id: 44205761108455-44205760847467
external_ref_id: e0634a17709147da83f60547e42772e4
source: System
exchange_id: 0
clearing_house_id: 0
company_id: 1212
contra_broker_id: 263
account_id: 100001074
sub_account: S00
account_type: 06
order_type: NULL
order_method:
order_cancel_reason:
cross_account_id: 100001087
cross_account_type: 06
trade_date: 2020-04-28
fixing_date: NULL
settlement_date: 2020-04-30
settlement_date_2: NULL
currency: ZAR
quantity: 144850.0000000
quantity_2: 0.0000000
amount: 2704045.3100000
currency_2: USD
amount_2: 144850.0000000
buy_sell_indicator: B
sell_type:
roll_type: 0
product_id: 5644
security_type: FXSpot
member_id: 1212
execution_broker_id: 0
execution_time: 2020-04-28 00:00:00.001
average_price_indicator: 1
fill_price: 18.6679000
fill_price_2: 0.0000000
interest_points: 0.0000000
interest_points_2: 0.0000000
markup: 0.0000000
blotter_code: FXST
capacity:
business_date: 2020-04-28
create_time: 2020-04-29 02:06:35
update_time: 4821-12-27 00:00:00
create_by: System
update_by: System
remark: Give-up
order_channel: EA-Trade
status: 1
open_or_close: NULL
pb_account_id: 100001087
trade_type: C
roll_trade_type:
roll_trade_id:
standard_spot: 1
sequence: 1
cash_settled: 1
waive_commission: 1
for_delivery: 0
execution_only: 1
cfd: 0
inverted: NULL
2 rows in set (0.09 sec)