How calculate proft/lose of my trades ?
I want to calculate profit/lose of my trades i use ccxt to trade in Binance futures and everything work great ! but now i want to show profit/lose of my all trades how can i do that ?
@asaltrader
You can get your person trade info using the fetch_my_trades method with defaultType: 'future' option set, as shown below:
import ccxt
from pprint import pprint
exchange = ccxt.binance({
'enableRateLimit': True,
'apiKey': 'YOUR_API_KEY',
'secret': 'YOUR_SECRET',
'options': { 'defaultType': 'future' },
})
symbol = 'BTC/USDT'
trades = exchange.fetch_my_trades(symbol)
for trade in trades:
pprint('-------------------------------')
pprint(trade)
↑ Look for realizedPnl (realized profit and loss) inside the trade['info'] for each trade.
This is documented here: https://github.com/ccxt/ccxt/wiki/Manual#personal-trades-1
Let us know if that does not answer your question. Feel free to reopen it or just ask further questions if any.
@asaltrader
You can get your person trade info using the
fetch_my_tradesmethod withdefaultType: 'future'option set, as shown below:import ccxt from pprint import pprint exchange = ccxt.binance({ 'enableRateLimit': True, 'apiKey': 'YOUR_API_KEY', 'secret': 'YOUR_SECRET', 'options': { 'defaultType': 'future' }, }) symbol = 'BTC/USDT' trades = exchange.fetch_my_trades(symbol) for trade in trades: pprint('-------------------------------') pprint(trade)↑ Look for
realizedPnl(realized profit and loss) inside thetrade['info']for each trade.This is documented here: https://github.com/ccxt/ccxt/wiki/Manual#personal-trades-1
Let us know if that does not answer your question. Feel free to reopen it or just ask further questions if any.
Is this still working like that? I'm not being able to get closed PnL by any means
@nostat1k paste your verbose output:
import ccxt
from pprint import pprint
print('CCXT Version:', ccxt.__version__)
exchange = ccxt.binance({
'enableRateLimit': True,
'apiKey': 'YOUR_API_KEY',
'secret': 'YOUR_SECRET',
'options': { 'defaultType': 'future' },
})
markets = exchange.load_markets()
exchange.verbose = True # after loading the markets
symbol = 'BTC/USDT'
trades = exchange.fetch_my_trades(symbol)
for trade in trades:
pprint('-------------------------------')
pprint(trade)