BittyTax icon indicating copy to clipboard operation
BittyTax copied to clipboard

FTX parser: Initial implementation.

Open rokups opened this issue 4 years ago • 3 comments

As title says. Though i do not have good data to properly test it as my transactions have margin/futures stuff interleaved.

People interested in #80 - please test if you are able.

rokups avatar Dec 18 '21 11:12 rokups

How are we supposed to handle conversions of stablecoin to fiat and back? For example FTX deals mostly in USD, but it does withdrawals and deposits and withdrawals in all kinds of stablecoins. I suppose we could automatically add a synthetic trade to convert from stablecoin to plain USD and back? For time being i am adding manual trades, but that does not work quite as expected. For example:

check pool: BTC (ok)
check pool: BUSD +2,309.12357835 (mismatch)
check pool: ETH (ok)
check pool: FTM (ok)
check pool: FTT (ok)
check pool: LRC (ok)
check pool: MATIC +0.00081742 (mismatch)
check pool: RUNE (ok)
check pool: SHIB (ok)
check pool: SOL (ok)
check pool: USDC +226 (mismatch)
check pool: USDT -4,559.681458 (mismatch)

Lets focus on USDC here. I sent some USD to a different FTX account here.

Some debug logs:

import: row[125] ['Trade', '226', 'USDC', '', '226', 'USD', '', '0', 'USD', '', 'FTX', '2021-11-28T16:44:00.503991 UTC', '']
import: row[126] ['Withdrawal', '', '', '', '226', 'USDC', '', '0', 'USDC', '', 'FTX', '2021-11-28T16:44:01.503991 UTC', 'Internal FTX transfer to ...']

audit: TR Trade 226 USDC <- 226 USD + fee=0 USD 'FTX' 2021-11-28T16:44:00.503991 UTC [TID:124]
audit:   FTX:USDC=226 (+226)
audit:   FTX:USD=-991.2762737601756267 (-226)
audit:   FTX:USD=-991.2762737601756267 (-0)
audit: TR Withdrawal 226 USDC + fee=0 USDC 'FTX' 2021-11-28T16:44:01.503991 UTC 'Internal FTX transfer to 21zVw4ryP2QErDgnneAZtK9NY6GAmcwnbY77mesBvPiK' [TID:125]
audit:   FTX:USDC=0 (-226)
audit:   FTX:USDC=0 (-0)

split: TR Trade 226 USDC <- 226 USD + fee=0 USD 'FTX' 2021-11-28T16:44:00.503991 UTC [TID:124]
price: 2021-11-28, 1 USD=0.885661146 EUR via BittyTaxAPI (United States Dollar)
price: 2021-11-28, 1 USD=€0.89 EUR, 226 USD=€200.16 EUR
split:   BUY Trade 226 USDC (~€200.16 EUR) 'FTX' 2021-11-28T16:44:00.503991 GMT [TID:124.1]
split: TR Withdrawal 226 USDC + fee=0 USDC 'FTX' 2021-11-28T16:44:01.503991 UTC 'Internal FTX transfer to 21zVw4ryP2QErDgnneAZtK9NY6GAmcwnbY77mesBvPiK' [TID:125]
split:   SELL* Withdrawal 226 USDC 'FTX' 2021-11-28T16:44:01.503991 GMT 'Internal FTX transfer to 21zVw4ryP2QErDgnneAZtK9NY6GAmcwnbY77mesBvPiK' [TID:125.1]

section104: BUY Trade 226 USDC (~€200.16 EUR) 'FTX' 2021-11-28T16:44:00.503991 GMT [TID:124.1]
section104:   USDC=226 (+226) cost=€200.16 EUR (+€200.16 EUR) fees=€0.00 EUR (+€0.00 EUR)
section104: //SELL* Withdrawal 226 USDC 'FTX' 2021-11-28T16:44:01.503991 GMT 'Internal FTX transfer to ...' [TID:125.1] <- transfer

What is this about? Any way i should fix it? section104 is some UK tax thing i guess? I looked over tax.py and omg UK taxes are complicated. In my country everything is a lot simpler (profits - expenses * 0.15 essentially) so i intend to get that simplified scheme going on. Given that, should i be concerned with what check pool produces?

rokups avatar Dec 18 '21 12:12 rokups

I suppose we could automatically add a synthetic trade to convert from stablecoin to plain USD and back? And i realized a problem with that. BittyTax expects one transaction record per parsed row and i see no obvious way to create two transactions (conversion + withdrawal or conversion + deposit). It is possible to do conversion without a transaction (depositing BUSD would turn into depositing USD), but that breaks cross-exchange transfers. 😞

rokups avatar Dec 18 '21 15:12 rokups

We should also add the "Staking Reward History" export from ftx.com/staking. The headers are: "Time","Notes","Coin","Reward" Example line: "2022-02-21T01:01:00.166465+00:00","SRM Staking Reward","SRM_LOCKED","0.0005" Should be parsed as: Staking 0.0005 SRM_LOCKED

One issue I can foresee is that BittyTax won't have a price for SRM_LOCKED. We could change it to SRM (price available from CoinGecko) however it break consistency with the Trades output which has periodic trades of SRM_LOCKED to SRM at 1:1 rate as it vests.

curtailment avatar Feb 21 '22 14:02 curtailment

works very well. can we merge this in? I am sure a lot of ppl will want to write off their FTX portfolio now

dakkusingh avatar Dec 08 '22 14:12 dakkusingh

Hi @dakkusingh, can you provide some example exports to test with, please obfuscate any personal/private data. Add them to issue https://github.com/BittyTax/BittyTax/issues/80.

nanonano avatar Dec 08 '22 19:12 nanonano

id	time	market	side	type	size	price	total	fee	feeCurrency
0	2022-11-08	BTC/USD	buy	Limit	0.0013	19500	25.35	0.00000026	BTC
0	2022-11-08	BTC/USD	buy	Limit	0.0012	19550	23.46	0.00000024	BTC
0	2022-11-08	BTC/USD	buy	Limit	0.0011	19600	21.56	0.00000022	BTC
0	2022-11-08	BTC/USD	buy	Limit	0.0011	19650	21.615	0.00000022	BTC
0	2022-11-08	BTC/USD	buy	Limit	0.001	19700	19.7	0.0000002	BTC
0	2022-11-08	BTC/USD	buy	Limit	0.001	19750	19.75	0.0000002	BTC
0	2022-10-29	BTC/USD	sell	Market	0.0046	20664	95.0544	0.06653808	USD

@nanonano you can give this dummy data a try. column 1 is the transaction ID - which i have omitted to just a 0

dakkusingh avatar Dec 09 '22 15:12 dakkusingh

Hi @dakkusingh, thanks for adding the example data, can you confirm that when you tested it, it balanced exactly with your FTX account?

nanonano avatar Dec 11 '22 14:12 nanonano

@nanonano yes it was working very well - only tested with trades - not deposits and withdrawals.

dakkusingh avatar Dec 12 '22 09:12 dakkusingh

Nice work @rokups.

Mostly seems to work great but I encountered an issue with some data. It looks as though FTX sometimes has negative fees for trades when it's refunding margin fees which bittytax doesn't like.

Example data:

"id","time","market","side","type","size","price","total","fee","feeCurrency"
"0","2021-01-27T15:04:20.304580+00:00","ETH/USD","buy","Limit","1.957","1238","2422.766","-0.000029355","ETH"

bittytax_conv handles the file fine showing a negative fee. But when trying to use bittytax to parse the generated file it complains about the negative fee value:

import: 'FTX T' row[2] ['Trade', '1.957', 'ETH', '', '2422.766', 'USD', '', '-2.9355e-05', 'ETH', '', 'FTX', '2021-01-27T15:04:20.304580', 'Limit']                                                            
ERROR Invalid data for Fee Quantity: '-0.000029355'  

On Koinly this would show as two trades, with one showing up as "Margin fee refunded".

image

Would that match the preferred behaviour here? If so is there an example of this being handled on another exchange in bittytax I can refer to?

I realise its been a while so I'm happy to take a look if nobody else does. At least the FTX format shouldn't be changing again :)

rolo avatar Jan 24 '23 10:01 rolo

any chance we can get this merged?

dakkusingh avatar Apr 04 '23 14:04 dakkusingh

@dakkusingh it's on the list, will look at this soon.

nanonano avatar Apr 16 '23 11:04 nanonano

@nanonano - please let me know if there is anything I can do to help in getting this integrated.

dakkusingh avatar Oct 25 '23 13:10 dakkusingh

Thanks for https://github.com/BittyTax/BittyTax/issues/80 I guess this can also be closed.

dakkusingh avatar Oct 29 '23 12:10 dakkusingh