ccxt icon indicating copy to clipboard operation
ccxt copied to clipboard

How calculate proft/lose of my trades ?

Open asaltrader opened this issue 6 years ago • 3 comments

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 avatar May 22 '20 18:05 asaltrader

@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.

kroitor avatar May 22 '20 18:05 kroitor

@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.

Is this still working like that? I'm not being able to get closed PnL by any means

nostat1k avatar Jun 16 '21 17:06 nostat1k

@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)

kroitor avatar Jun 17 '21 20:06 kroitor