Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enum] rename FILLED enum and realised into realized #789

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions Meta/Keywords/scripting_library/backtesting/run_data_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ def _read_pnl_from_trades(x_data, pnl_data, cumulative_pnl_data, trades_history,
def _read_pnl_from_transactions(x_data, pnl_data, cumulative_pnl_data, trading_transactions_history, x_as_trade_count):
previous_value = 0
for transaction in trading_transactions_history:
transaction_pnl = 0 if transaction["realised_pnl"] is None else transaction["realised_pnl"]
transaction_pnl = 0 if transaction["realized_pnl"] is None else transaction["realized_pnl"]
transaction_quantity = 0 if transaction["quantity"] is None else transaction["quantity"]
local_quantity = transaction_pnl + transaction_quantity
cumulated_pnl = local_quantity + previous_value
Expand Down Expand Up @@ -399,8 +399,8 @@ async def _get_historical_pnl(meta_database, plotted_element, include_cumulative
meta_database,
transaction_types=(trading_enums.TransactionType.TRADING_FEE.value,
trading_enums.TransactionType.FUNDING_FEE.value,
trading_enums.TransactionType.REALISED_PNL.value,
trading_enums.TransactionType.CLOSE_REALISED_PNL.value)
trading_enums.TransactionType.REALIZED_PNL.value,
trading_enums.TransactionType.CLOSE_REALIZED_PNL.value)
)
if trading_transactions_history:
# can rely on pnl history
Expand Down Expand Up @@ -552,16 +552,16 @@ async def plot_withdrawals(meta_database, plotted_element):
async def plot_positions(meta_database, plotted_element):
realized_pnl_history = await get_transactions(
meta_database,
transaction_types=(trading_enums.TransactionType.CLOSE_REALISED_PNL.value,)
transaction_types=(trading_enums.TransactionType.CLOSE_REALIZED_PNL.value,)
)
key_to_label = {
commons_enums.PlotAttributes.X.value: "Exit time",
"first_entry_time": "Entry time",
"average_entry_price": "Average entry price",
"average_exit_price": "Average exit price",
"cumulated_closed_quantity": "Cumulated closed quantity",
"realised_pnl": "Realised PNL",
commons_enums.PlotAttributes.SIDE.value: "Side",
"realized_pnl": "Realized PNL",
"trigger_source": "Closed by",
}

Expand Down Expand Up @@ -677,7 +677,7 @@ def _get_default_searches(columns, types):
def _get_wins_and_losses_from_transactions(x_data, wins_and_losses_data, trading_transactions_history,
x_as_trade_count):
for transaction in trading_transactions_history:
transaction_pnl = 0 if transaction["realised_pnl"] is None else transaction["realised_pnl"]
transaction_pnl = 0 if transaction["realized_pnl"] is None else transaction["realized_pnl"]
current_cumulative_wins = wins_and_losses_data[-1] if wins_and_losses_data else 0
if transaction_pnl < 0:
wins_and_losses_data.append(current_cumulative_wins - 1)
Expand Down Expand Up @@ -708,8 +708,8 @@ async def plot_historical_wins_and_losses(meta_database, plotted_element, exchan
meta_database,
transaction_types=(trading_enums.TransactionType.TRADING_FEE.value,
trading_enums.TransactionType.FUNDING_FEE.value,
trading_enums.TransactionType.REALISED_PNL.value,
trading_enums.TransactionType.CLOSE_REALISED_PNL.value)
trading_enums.TransactionType.REALIZED_PNL.value,
trading_enums.TransactionType.CLOSE_REALIZED_PNL.value)
)
if trading_transactions_history:
# can rely on pnl history
Expand All @@ -735,7 +735,7 @@ def _get_win_rates_from_transactions(x_data, win_rates_data, trading_transaction
wins_count = 0
losses_count = 0
for transaction in trading_transactions_history:
transaction_pnl = 0 if transaction["realised_pnl"] is None else transaction["realised_pnl"]
transaction_pnl = 0 if transaction["realized_pnl"] is None else transaction["realized_pnl"]
if transaction_pnl < 0:
losses_count += 1
elif transaction_pnl > 0:
Expand Down Expand Up @@ -766,8 +766,8 @@ async def plot_historical_win_rates(meta_database, plotted_element, exchange=Non
meta_database,
transaction_types=(trading_enums.TransactionType.TRADING_FEE.value,
trading_enums.TransactionType.FUNDING_FEE.value,
trading_enums.TransactionType.REALISED_PNL.value,
trading_enums.TransactionType.CLOSE_REALISED_PNL.value)
trading_enums.TransactionType.REALIZED_PNL.value,
trading_enums.TransactionType.CLOSE_REALIZED_PNL.value)
)
if trading_transactions_history:
# can rely on pnl history
Expand Down Expand Up @@ -813,8 +813,8 @@ async def plot_best_case_growth(meta_database, plotted_element, exchange=None,
meta_database,
transaction_types=(trading_enums.TransactionType.TRADING_FEE.value,
trading_enums.TransactionType.FUNDING_FEE.value,
trading_enums.TransactionType.REALISED_PNL.value,
trading_enums.TransactionType.CLOSE_REALISED_PNL.value)
trading_enums.TransactionType.REALIZED_PNL.value,
trading_enums.TransactionType.CLOSE_REALIZED_PNL.value)
)
if trading_transactions_history:
# can rely on pnl history
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ async def _test_historical_pnl_values_from_trades(price_data, trades_data, pnl_d
transaction_types=(
trading_enums.TransactionType.TRADING_FEE.value,
trading_enums.TransactionType.FUNDING_FEE.value,
trading_enums.TransactionType.REALISED_PNL.value,
trading_enums.TransactionType.CLOSE_REALISED_PNL.value)
trading_enums.TransactionType.REALIZED_PNL.value,
trading_enums.TransactionType.CLOSE_REALIZED_PNL.value)
)
if include_cumulative:
assert plotted_element.plot.call_count == 2
Expand Down
2 changes: 1 addition & 1 deletion Trading/Exchange/bitget/bitget_exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def fix_order(self, raw, **kwargs):
== trading_enums.TradeOrderSide.BUY.value:
# convert amount to have the same units as evert other exchange: use FILLED for accuracy
fixed[trading_enums.ExchangeConstantsOrderColumns.AMOUNT.value] = \
fixed[trading_enums.ExchangeConstantsOrderColumns.FILLED.value]
fixed[trading_enums.ExchangeConstantsOrderColumns.FILLED_AMOUNT.value]
except KeyError:
pass
return fixed
Expand Down
10 changes: 7 additions & 3 deletions Trading/Exchange/bybit/bybit_exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ def parse_position(self, fixed, **kwargs):
# if side == enums.PositionSide.LONG.value else enums.PositionSide.SHORT

unrealized_pnl = self.safe_decimal(fixed,
ccxt_enums.ExchangePositionCCXTColumns.UNREALISED_PNL.value,
ccxt_enums.ExchangePositionCCXTColumns.UNREALIZED_PNL.value,
constants.ZERO)
liquidation_price = self.safe_decimal(fixed,
ccxt_enums.ExchangePositionCCXTColumns.LIQUIDATION_PRICE.value,
Expand All @@ -404,12 +404,16 @@ def parse_position(self, fixed, **kwargs):
),
trading_enums.ExchangeConstantsPositionColumns.SIZE.value:
size if original_side == trading_enums.PositionSide.LONG.value else -size,
trading_enums.ExchangeConstantsPositionColumns.SINGLE_CONTRACT_VALUE.value:
self.safe_decimal(
fixed, ccxt_enums.ExchangePositionCCXTColumns.CONTRACT_SIZE.value, constants.ONE
),
trading_enums.ExchangeConstantsPositionColumns.INITIAL_MARGIN.value:
self.safe_decimal(
fixed, ccxt_enums.ExchangePositionCCXTColumns.INITIAL_MARGIN.value,
constants.ZERO
),
trading_enums.ExchangeConstantsPositionColumns.NOTIONAL.value:
trading_enums.ExchangeConstantsPositionColumns.VALUE.value:
self.safe_decimal(
fixed, ccxt_enums.ExchangePositionCCXTColumns.NOTIONAL.value, constants.ZERO
),
Expand All @@ -418,7 +422,7 @@ def parse_position(self, fixed, **kwargs):
fixed, ccxt_enums.ExchangePositionCCXTColumns.LEVERAGE.value, constants.ONE
),
trading_enums.ExchangeConstantsPositionColumns.UNREALIZED_PNL.value: unrealized_pnl,
trading_enums.ExchangeConstantsPositionColumns.REALISED_PNL.value:
trading_enums.ExchangeConstantsPositionColumns.REALIZED_PNL.value:
self.safe_decimal(
fixed, self.BYBIT_REALIZED_PNL, constants.ZERO
),
Expand Down
2 changes: 1 addition & 1 deletion Trading/Exchange/coinex/coinex_exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def fix_order(self, raw, **kwargs):
== trading_enums.TradeOrderSide.BUY.value:
# convert amount to have the same units as evert other exchange: use FILLED for accuracy
fixed[trading_enums.ExchangeConstantsOrderColumns.AMOUNT.value] = \
fixed[trading_enums.ExchangeConstantsOrderColumns.FILLED.value]
fixed[trading_enums.ExchangeConstantsOrderColumns.FILLED_AMOUNT.value]
except KeyError:
pass
return fixed
2 changes: 1 addition & 1 deletion Trading/Exchange/huobi/huobi_exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def fix_order(self, raw, **kwargs):
== trading_enums.TradeOrderSide.BUY.value:
# convert amount to have the same units as evert other exchange: use FILLED for accuracy
fixed[trading_enums.ExchangeConstantsOrderColumns.AMOUNT.value] = \
fixed[trading_enums.ExchangeConstantsOrderColumns.FILLED.value]
fixed[trading_enums.ExchangeConstantsOrderColumns.FILLED_AMOUNT.value]
except KeyError:
pass
return fixed
2 changes: 1 addition & 1 deletion Trading/Mode/arbitrage_trading_mode/arbitrage_trading.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ async def order_filled_callback(self, filled_order):
async with self.lock:
arbitrage = self._get_arbitrage(order_id)
if arbitrage is not None:
filled_quantity = filled_order[trading_enums.ExchangeConstantsOrderColumns.FILLED.value]
filled_quantity = filled_order[trading_enums.ExchangeConstantsOrderColumns.FILLED_AMOUNT.value]
if arbitrage.passed_initial_order:
# filled limit order or stop loss: close arbitrage
arbitrage_success = filled_order[trading_enums.ExchangeConstantsOrderColumns.TYPE.value] != \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ def get_order_dict(order_id, symbol, price, quantity, status, order_type, fees_a
trading_enums.ExchangeConstantsOrderColumns.SYMBOL.value: symbol,
trading_enums.ExchangeConstantsOrderColumns.PRICE.value: price,
trading_enums.ExchangeConstantsOrderColumns.AMOUNT.value: quantity,
trading_enums.ExchangeConstantsOrderColumns.FILLED.value: quantity,
trading_enums.ExchangeConstantsOrderColumns.FILLED_AMOUNT.value: quantity,
trading_enums.ExchangeConstantsOrderColumns.STATUS.value: status,
trading_enums.ExchangeConstantsOrderColumns.TYPE.value: order_type,
trading_enums.ExchangeConstantsOrderColumns.FEE.value: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ async def order_filled_callback(self, filled_order):
paid_fees = 0 if self.ignore_exchange_fees else \
decimal.Decimal(f"{trading_personal_data.total_fees_from_order_dict(filled_order, self.base)}")
sell_quantity = \
decimal.Decimal(f"{filled_order[trading_enums.ExchangeConstantsOrderColumns.FILLED.value]}") - paid_fees
decimal.Decimal(f"{filled_order[trading_enums.ExchangeConstantsOrderColumns.FILLED_AMOUNT.value]}") - paid_fees
price = decimal.Decimal(f"{filled_order[trading_enums.ExchangeConstantsOrderColumns.PRICE.value]}")
await self._create_sell_order_if_enabled(filled_order[trading_enums.ExchangeConstantsOrderColumns.ID.value],
sell_quantity,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ async def order_filled_callback(self, filled_order):
self.symbol_market, self.spread * self.flat_increment / self.increment)
price_increment = self.flat_spread - self.flat_increment
filled_price = decimal.Decimal(str(filled_order[trading_enums.ExchangeConstantsOrderColumns.PRICE.value]))
filled_volume = decimal.Decimal(str(filled_order[trading_enums.ExchangeConstantsOrderColumns.FILLED.value]))
filled_volume = decimal.Decimal(str(filled_order[trading_enums.ExchangeConstantsOrderColumns.FILLED_AMOUNT.value]))
price = filled_price + price_increment if now_selling else filled_price - price_increment
volume = self._compute_mirror_order_volume(now_selling, filled_price, price, filled_volume)
new_order = OrderData(new_side, volume, price, self.symbol, False, associated_entry_id)
Expand Down