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
64 stars 42 forks source link

Negative Transaction Fees #102

Closed macanudo527 closed 1 year ago

macanudo527 commented 1 year ago

I'm working with an exchange that actually has negative fees for makers.

I guess this is INCOME for providing liquidity?

eprbell commented 1 year ago

Interesting: representing income as negative fee sounds like a peculiarity of the exchange. If it's income it should be represented in RP2 as an income-typed in-transaction.

macanudo527 commented 1 year ago

This is for Bitbank. Their maker fee is -0.02%, and their taker fee is %0.12. Basically, they are trying to reward liquidity providers. They are one of the only exchanges that offer a good variety of crypto assets. Most exchanges in Japan just offer BTC and ETH, and maybe another like MANA or XRP. They just recently started listing ADA in a lot of places.

My guess is that they want to keep their market liquid since altcoins are still not that popular in Japan.

Should I make this a part of the abstract_ccxt_plugin? I don't know of any other exchange that does this. Or, I could just override the _process_buy_and_sell() function to add the INCOME transaction in bitbank.py.

macanudo527 commented 1 year ago

I decided to override _process_buy_and_sell(). It will be in my bundle of fixes I'm working on.

eprbell commented 1 year ago

Sorry my response time is increasing. I recently ended my sabbatical and went back to work so I'll be able to spend time on this mostly in the weekends. Anyway, I think overriding in bitbank.py is the right decision.

topherbuckley commented 1 year ago

I'm getting an error when importing from bitbank due to something seemingly related to this:

Traceback (most recent call last):
  File "/media/christopher/HDD/git/dali-rp2/src/dali/dali_main.py", line 168, in _dali_main_internal
    resolved_transactions: List[AbstractTransaction] = resolve_transactions(transactions, dali_configuration, args.read_spot_price_from_web)
  File "/media/christopher/HDD/git/dali-rp2/src/dali/transaction_resolver.py", line 289, 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:
InTransaction:
  plugin=Bitbank.cc_REST
  unique_id=XXX
  raw_data={"timestamp": 1637583318405, "datetime": "2021-11-22T12:15:18.405Z", "symbol": "ETH/JPY", "id": "XXX", "order": "YYY", "type": "limit", "side": "sell", "takerOrMaker": "maker", "price": 477096.0, "amount": 0.1159, "cost": 55295.4264, "fee": {"currency": "JPY", "cost": 0.0}, "info": {"trade_id": "XXX", "order_id": "YYY", "pair": "eth_jpy", "side": "sell", "type": "limit", "amount": "0.1159", "price": "477096", "maker_taker": "maker", "fee_amount_base": "0.00000000", "fee_amount_quote": "-11.0591", "executed_at": "1637583318405"}, "fees": [{"currency": "JPY", "cost": 0.0}]}
  timestamp=2021-11-22 12:15:18+0000
  asset=JPY
  exchange=Bitbank.cc
  holder=christopher
  transaction_type=Buy
  spot_price=__unknown
  crypto_in=55295.4264
  fiat_fee=None
  fiat_in_no_fee=None
  fiat_in_with_fee=None
  notes=Buy side of conversion from 0.1159 ETH -> 55295.4264 JPY(ETH out-transaction unique id: XXX
InTransaction:
  plugin=Bitbank.cc_REST
  unique_id=XXX
  raw_data={"timestamp": 1637583318405, "datetime": "2021-11-22T12:15:18.405Z", "symbol": "ETH/JPY", "id": "XXX", "order": "YYY", "type": "limit", "side": "sell", "takerOrMaker": "maker", "price": 477096.0, "amount": 0.1159, "cost": 55295.4264, "fee": {"currency": "JPY", "cost": -11.0591}, "info": {"trade_id": "XXX", "order_id": "YYY", "pair": "eth_jpy", "side": "sell", "type": "limit", "amount": "0.1159", "price": "477096", "maker_taker": "maker", "fee_amount_base": "0.00000000", "fee_amount_quote": "-11.0591", "executed_at": "1637583318405"}, "fees": [{"currency": "JPY", "cost": -11.0591}]}
  timestamp=2021-11-22 12:15:18+0000
  asset=JPY
  exchange=Bitbank.cc
  holder=christopher
  transaction_type=Income
  spot_price=__unknown
  crypto_in=11.0591
  fiat_fee=None
  fiat_in_no_fee=None
  fiat_in_with_fee=None
  notes=Fee income for transaction #XXX

I may have been overly cautious, but I obfuscated the order ID and transactions to YYY and XXX respectively.

Was there something I need to add to the config file to work with this?

eprbell commented 1 year ago

This looks like a bug in the Bitbank data loader. It looks like there are two in-transactions with the same unique id, so the transaction resolver tries to match them but can't because they are both in-transactions. Could you open a separate issue for this?