eprbell / dali-rp2

DaLI (Data Loader Interface) is a data loader and input generator for RP2 (https://pypi.org/project/rp2), the privacy-focused, free, open-source cryptocurrency tax calculator: DaLI removes the need to manually prepare RP2 input files. Just like RP2, DaLI is also free, open-source and it prioritizes user privacy.
https://pypi.org/project/dali-rp2/
Apache License 2.0
65 stars 42 forks source link

2 transactions with same uniqueID in binance #164

Open Larision opened 1 year ago

Larision commented 1 year ago
ERROR: Fatal exception occurred:
Traceback (most recent call last):
  File "/home/kali/renta/dali-rp2/src/dali/dali_main.py", line 181, in _dali_main_internal
    resolved_transactions: List[AbstractTransaction] = resolve_transactions(transactions, dali_configuration, args.read_spot_price_from_web)
                                                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kali/renta/dali-rp2/src/dali/transaction_resolver.py", line 290, in resolve_transactions
    raise RP2RuntimeError(
rp2.rp2_error.RP2RuntimeError: Internal error: attempting to resolve two transactions that aren't Intra/Intra, In/Out or Out/In:
OutTransaction:
  plugin=Binance.com_REST
  unique_id=7484550
  raw_data={"info": {"symbol": "CAKEBNB", "id": "7484550", "orderId": "103694345", "orderListId": "-1", "price": "0.04646000", "qty": "1.47000000", "quoteQty": "0.06829620", "commission": "0.00005125", "commissionAsset": "BNB", "time": "1633735165866", "isBuyer": true, "isMaker": true, "isBestMatch": true}, "timestamp": 1633735165866, "datetime": "2021-10-08T23:19:25.866Z", "symbol": "CAKE/BNB", "id": "7484550", "order": "103694345", "type": null, "side": "buy", "takerOrMaker": "maker", "price": 0.04646, "amount": 1.47, "cost": 0.0682962, "fee": {"cost": 5.125e-05, "currency": "BNB"}, "fees": [{"cost": 5.125e-05, "currency": "BNB"}]}
  timestamp=2021-10-08 23:19:25+0000
  asset=BNB
  exchange=Binance.com
  holder=fran
  transaction_type=Sell
  spot_price=__unknown
  crypto_out_no_fee=0.0682962
  crypto_fee=0.00005125
  crypto_out_with_fee=0.06834745
  fiat_out_no_fee=None
  fiat_fee=None
  notes=Sell side of conversion from 0.0682962 BNB -> 1.47 CAKE(CAKE in-transaction unique id: 7484550
OutTransaction:
  plugin=Binance.com_REST
  unique_id=7484550
  raw_data={"info": {"symbol": "BETAUSDT", "id": "7484550", "orderId": "67825086", "orderListId": "-1", "price": "1.35567000", "qty": "19.00000000", "quoteQty": "25.75773000", "commission": "0.00003097", "commissionAsset": "BNB", "time": "1638451894562", "isBuyer": true, "isMaker": true, "isBestMatch": true}, "timestamp": 1638451894562, "datetime": "2021-12-02T13:31:34.562Z", "symbol": "BETA/USDT", "id": "7484550", "order": "67825086", "type": null, "side": "buy", "takerOrMaker": "maker", "price": 1.35567, "amount": 19.0, "cost": 25.75773, "fee": {"cost": 3.097e-05, "currency": "BNB"}, "fees": [{"cost": 3.097e-05, "currency": "BNB"}]}
  timestamp=2021-12-02 13:31:34+0000
  asset=BNB
  exchange=Binance.com
  holder=fran
  transaction_type=Fee
  spot_price=__unknown
  crypto_out_no_fee=0
  crypto_fee=0.00003097
  crypto_out_with_fee=0.00003097
  fiat_out_no_fee=None
  fiat_fee=None
  notes=Fee for conversion from 25.75773 USDT -> 19.0 BETA

i suppose is a binance issue, @macanudo527 maybe if same uniqueID and different asset pair, check orderid? as you mencioned in #157 ??

macanudo527 commented 1 year ago

This is truly strange, the id and orderId should be the same.

macanudo527 commented 1 year ago

These are just regular trades?

eprbell commented 1 year ago

This is truly strange, the id and orderId should be the same.

Can you elaborate on this? Curious why they should be the same. In any case since these are not transactions that need the resolver (they are a sale and a fee related to conversions), how about the following ideas:

Would this work?

macanudo527 commented 1 year ago

Can you elaborate on this? Curious why they should be the same.

Sorry, I misread the CCXT codebase. They shouldn't be the same actually.

I think this change will disambiguate the ids and it make it safe for all the other exchanges as well.

Larision commented 1 year ago
            # Users can use other crypto assets to pay for trades
            if fee_asset != out_asset and RP2Decimal(transaction_fee) > ZERO:
                out_transaction_list.append(
                    OutTransaction(
                        plugin=self.plugin_name(),
                        unique_id=f"{transaction[_ID]}/fee",

will work with this /fee addition in abstract_ccxt_input_plugin??

macanudo527 commented 1 year ago

@Larision I think @eprbell 's suggestion should fix this issue if you want to implement that.

Larision commented 1 year ago

@macanudo527 @eprbell Srry but not easy to me. Where shoud i fix it?