Skip to content

Commit 7b4c59a

Browse files
committed
[Typo] fix relised/realized typo and rename enums
tmp
1 parent 92053df commit 7b4c59a

35 files changed

+237
-196
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ No change, pypi issue version
268268
- [Transaction] class
269269
- [TransactionsManager] class
270270
- [TransactionsManager] factory
271-
- [TransactionsManager] transfer, blockchain, fee and realised_pnl
271+
- [TransactionsManager] transfer, blockchain, fee and realized_pnl
272272

273273
### Fixed
274274
- [Positions] missing mark_price fetching

octobot_trading/enums.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ class TransactionType(enum.Enum):
118118
BLOCKCHAIN_WITHDRAWAL = "blockchain_withdrawal"
119119
FUNDING_FEE = "funding_fee"
120120
TRADING_FEE = "trading_fee"
121-
REALISED_PNL = "realised_pnl"
122-
CLOSE_REALISED_PNL = "close_realised_pnl"
121+
REALIZED_PNL = "realized_pnl"
122+
CLOSE_REALIZED_PNL = "close_realized_pnl"
123123
TRANSFER = "transfer"
124124

125125

@@ -162,6 +162,7 @@ class PositionMode(enum.Enum):
162162

163163
class ExchangeConstantsFundingColumns(enum.Enum):
164164
SYMBOL = "symbol"
165+
TIMESTAMP = "timestamp"
165166
LAST_FUNDING_TIME = "last_funding_time"
166167
FUNDING_RATE = "funding_rate"
167168
NEXT_FUNDING_TIME = "next_funding_time"
@@ -301,8 +302,8 @@ class ExchangeConstantsOrderColumns(enum.Enum):
301302
PRICE = "price"
302303
AMOUNT = "amount"
303304
COST = "cost"
304-
AVERAGE = "average"
305-
FILLED = "filled"
305+
FILLED_AMOUNT = "filled_amount"
306+
FILLED_PRICE = "filled_price"
306307
REMAINING = "remaining"
307308
STATUS = "status"
308309
FEE = "fee"
@@ -314,9 +315,10 @@ class ExchangeConstantsOrderColumns(enum.Enum):
314315
REDUCE_ONLY = "reduceOnly"
315316
STOP_PRICE = "stopPrice"
316317
TRIGGER_ABOVE = "triggerAbove"
318+
TIME_IN_FORCE = "timeInForce"
317319
TAG = "tag"
318-
319-
320+
321+
320322
class ExchangeConstantsPositionColumns(enum.Enum):
321323
ID = "id"
322324
TIMESTAMP = "timestamp"
@@ -325,12 +327,12 @@ class ExchangeConstantsPositionColumns(enum.Enum):
325327
MARK_PRICE = "mark_price"
326328
LIQUIDATION_PRICE = "liquidation_price"
327329
BANKRUPTCY_PRICE = "bankruptcy_price"
328-
UNREALIZED_PNL = "unrealised_pnl" # unrealised_pnl on Bybit api and unrealized_pnl on exchange UI
329-
REALISED_PNL = "realised_pnl"
330+
UNREALIZED_PNL = "unrealized_pnl" # unrealized_pnl on Bybit api and unrealized_pnl on exchange UI
331+
REALIZED_PNL = "realized_pnl"
330332
CLOSING_FEE = "closing_fee"
331-
QUANTITY = "quantity"
333+
SINGLE_CONTRACT_VALUE = "single_contract_value"
332334
SIZE = "size"
333-
NOTIONAL = "notional"
335+
VALUE = "position_value"
334336
INITIAL_MARGIN = "initial_margin"
335337
COLLATERAL = "collateral"
336338
LEVERAGE = "leverage"

octobot_trading/exchanges/connectors/ccxt/ccxt_adapter.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,24 +177,27 @@ def parse_position(self, fixed, **kwargs):
177177
enums.ExchangeConstantsPositionColumns.SIDE.value: position_side,
178178
enums.ExchangeConstantsPositionColumns.MARGIN_TYPE.value:
179179
fixed.get(ccxt_enums.ExchangePositionCCXTColumns.MARGIN_TYPE.value, None),
180-
enums.ExchangeConstantsPositionColumns.QUANTITY.value:
180+
enums.ExchangeConstantsPositionColumns.SINGLE_CONTRACT_VALUE.value:
181181
decimal.Decimal(
182-
f"{fixed.get(ccxt_enums.ExchangePositionCCXTColumns.CONTRACT_SIZE.value, 0)}"),
182+
f"{fixed.get(ccxt_enums.ExchangePositionCCXTColumns.CONTRACT_SIZE.value, 1)}"),
183+
enums.ExchangeConstantsPositionColumns.SIZE.value:
184+
decimal.Decimal(
185+
f"{fixed.get(ccxt_enums.ExchangePositionCCXTColumns.CONTRACTS.value, 0)}"),
183186
enums.ExchangeConstantsPositionColumns.COLLATERAL.value:
184187
decimal.Decimal(
185188
f"{fixed.get(ccxt_enums.ExchangePositionCCXTColumns.COLLATERAL.value, 0)}"),
186-
enums.ExchangeConstantsPositionColumns.NOTIONAL.value:
189+
enums.ExchangeConstantsPositionColumns.VALUE.value:
187190
decimal.Decimal(
188191
f"{fixed.get(ccxt_enums.ExchangePositionCCXTColumns.NOTIONAL.value, 0)}"),
189192
enums.ExchangeConstantsPositionColumns.LEVERAGE.value:
190193
decimal.Decimal(
191194
f"{fixed.get(ccxt_enums.ExchangePositionCCXTColumns.LEVERAGE.value, 0)}"),
192195
enums.ExchangeConstantsPositionColumns.UNREALIZED_PNL.value:
193196
decimal.Decimal(
194-
f"{fixed.get(ccxt_enums.ExchangePositionCCXTColumns.UNREALISED_PNL.value, 0)}"),
195-
enums.ExchangeConstantsPositionColumns.REALISED_PNL.value:
197+
f"{fixed.get(ccxt_enums.ExchangePositionCCXTColumns.UNREALIZED_PNL.value, 0)}"),
198+
enums.ExchangeConstantsPositionColumns.REALIZED_PNL.value:
196199
decimal.Decimal(
197-
f"{fixed.get(ccxt_enums.ExchangePositionCCXTColumns.REALISED_PNL.value, 0)}"),
200+
f"{fixed.get(ccxt_enums.ExchangePositionCCXTColumns.REALIZED_PNL.value, 0)}"),
198201
enums.ExchangeConstantsPositionColumns.LIQUIDATION_PRICE.value:
199202
decimal.Decimal(
200203
f"{fixed.get(ccxt_enums.ExchangePositionCCXTColumns.LIQUIDATION_PRICE.value, 0)}"),

octobot_trading/exchanges/connectors/ccxt/enums.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ class ExchangeConstantsCCXTColumns(enum.Enum):
2222

2323

2424
class ExchangePositionCCXTColumns(enum.Enum):
25-
CONTRACTS = "contracts"
26-
CONTRACT_SIZE = "contractSize"
25+
ID = "id"
26+
CONTRACTS = "contracts" # == ExchangeConstantsPositionColumn.SIZE
27+
CONTRACT_SIZE = "contractSize" # == ExchangeConstantsPositionColumns.SINGLE_CONTRACT_VALUE
2728
MARGIN_TYPE = "marginType"
2829
MARGIN_MODE = "marginMode"
2930
LEVERAGE = "leverage"
@@ -33,10 +34,10 @@ class ExchangePositionCCXTColumns(enum.Enum):
3334
INITIAL_MARGIN_PERCENTAGE = "initialMarginPercentage"
3435
MAINTENANCE_MARGIN = "maintenanceMargin"
3536
MAINTENANCE_MARGIN_PERCENTAGE = "maintenanceMarginPercentage"
36-
NOTIONAL = "notional"
37+
NOTIONAL = "notional" # == ExchangeConstantsPositionColumn.VALUE
3738
MARGIN_RATIO = "marginRatio"
38-
UNREALISED_PNL = "unrealizedPnl"
39-
REALISED_PNL = "realizedPnl"
39+
UNREALIZED_PNL = "unrealizedPnl"
40+
REALIZED_PNL = "realizedPnl"
4041
LIQUIDATION_PRICE = "liquidationPrice"
4142
MARK_PRICE = "markPrice"
4243
ENTRY_PRICE = "entryPrice"

octobot_trading/exchanges/types/rest_exchange.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ async def get_order_from_trades(self, symbol, order_id, order_to_update=None):
386386
order_to_update[ecoc.TIMESTAMP.value] = order_to_update.get(ecoc.TIMESTAMP.value,
387387
trade[ecoc.TIMESTAMP.value])
388388
order_to_update[ecoc.STATUS.value] = enums.OrderStatus.FILLED.value
389-
order_to_update[ecoc.FILLED.value] = trade[ecoc.AMOUNT.value]
389+
order_to_update[ecoc.FILLED_AMOUNT.value] = trade[ecoc.AMOUNT.value]
390390
order_to_update[ecoc.COST.value] = trade[ecoc.COST.value]
391391
order_to_update[ecoc.REMAINING.value] = 0
392392
order_to_update[ecoc.FEE.value] = trade[ecoc.FEE.value]

octobot_trading/personal_data/__init__.pxd

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ from octobot_trading.personal_data.transactions cimport (
9999
Transaction,
100100
BlockchainTransaction,
101101
FeeTransaction,
102-
RealisedPnlTransaction,
102+
RealizedPnlTransaction,
103103
TransferTransaction,
104104
create_blockchain_transaction,
105-
create_realised_pnl_transaction,
105+
create_realized_pnl_transaction,
106106
create_fee_transaction,
107107
create_transfer_transaction,
108108
)
@@ -189,10 +189,10 @@ __all__ = [
189189
"Transaction",
190190
"BlockchainTransaction",
191191
"FeeTransaction",
192-
"RealisedPnlTransaction",
192+
"RealizedPnlTransaction",
193193
"TransferTransaction",
194194
"create_blockchain_transaction",
195-
"create_realised_pnl_transaction",
195+
"create_realized_pnl_transaction",
196196
"create_fee_transaction",
197197
"create_transfer_transaction",
198198
]

octobot_trading/personal_data/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,10 @@
168168
Transaction,
169169
BlockchainTransaction,
170170
FeeTransaction,
171-
RealisedPnlTransaction,
171+
RealizedPnlTransaction,
172172
TransferTransaction,
173173
create_blockchain_transaction,
174-
create_realised_pnl_transaction,
174+
create_realized_pnl_transaction,
175175
create_fee_transaction,
176176
create_transfer_transaction,
177177
)
@@ -355,10 +355,10 @@
355355
"Transaction",
356356
"BlockchainTransaction",
357357
"FeeTransaction",
358-
"RealisedPnlTransaction",
358+
"RealizedPnlTransaction",
359359
"TransferTransaction",
360360
"create_blockchain_transaction",
361-
"create_realised_pnl_transaction",
361+
"create_realized_pnl_transaction",
362362
"create_fee_transaction",
363363
"create_transfer_transaction",
364364
]

octobot_trading/personal_data/orders/order.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ def update_from_raw(self, raw_order):
509509
price = stop_price
510510
filled_price = decimal.Decimal(str(price))
511511
# set average price with real average price if available, use filled_price otherwise
512-
average_price = decimal.Decimal(str(raw_order.get(enums.ExchangeConstantsOrderColumns.AVERAGE.value, 0.0)
512+
average_price = decimal.Decimal(str(raw_order.get(enums.ExchangeConstantsOrderColumns.FILLED_PRICE.value, 0.0)
513513
or filled_price))
514514

515515
return self.update(
@@ -519,7 +519,7 @@ def update_from_raw(self, raw_order):
519519
price=decimal.Decimal(str(price)),
520520
status=order_util.parse_order_status(raw_order),
521521
order_id=str(raw_order.get(enums.ExchangeConstantsOrderColumns.ID.value, None)),
522-
quantity_filled=decimal.Decimal(str(raw_order.get(enums.ExchangeConstantsOrderColumns.FILLED.value, 0.0)
522+
quantity_filled=decimal.Decimal(str(raw_order.get(enums.ExchangeConstantsOrderColumns.FILLED_AMOUNT.value, 0.0)
523523
or 0.0)),
524524
filled_price=decimal.Decimal(str(filled_price)),
525525
average_price=decimal.Decimal(str(average_price)),
@@ -643,7 +643,7 @@ def to_dict(self):
643643
enums.ExchangeConstantsOrderColumns.AMOUNT.value: self.origin_quantity,
644644
enums.ExchangeConstantsOrderColumns.COST.value: self.total_cost,
645645
enums.ExchangeConstantsOrderColumns.QUANTITY_CURRENCY.value: self.quantity_currency,
646-
enums.ExchangeConstantsOrderColumns.FILLED.value: self.filled_quantity,
646+
enums.ExchangeConstantsOrderColumns.FILLED_AMOUNT.value: self.filled_quantity,
647647
enums.ExchangeConstantsOrderColumns.FEE.value: self.fee,
648648
enums.ExchangeConstantsOrderColumns.REDUCE_ONLY.value: self.reduce_only,
649649
enums.ExchangeConstantsOrderColumns.TAG.value: self.tag

octobot_trading/personal_data/orders/order_util.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -390,15 +390,15 @@ async def get_order_size_portfolio_percent(exchange_manager, order_amount, side,
390390
portfolio_type=commons_constants.PORTFOLIO_TOTAL)
391391
if exchange_manager.is_future:
392392
# TODO check inverse
393-
if market_quantity is constants.ZERO:
393+
if market_quantity == constants.ZERO:
394394
return constants.ZERO
395395
return min(order_amount / market_quantity, constants.ONE) * constants.ONE_HUNDRED
396396
if side is enums.TradeOrderSide.SELL:
397-
if current_symbol_holding is constants.ZERO:
397+
if current_symbol_holding == constants.ZERO:
398398
return constants.ZERO
399399
return min(order_amount / current_symbol_holding, constants.ONE) * constants.ONE_HUNDRED
400400
if side is enums.TradeOrderSide.BUY:
401-
if current_market_holding is constants.ZERO:
401+
if current_market_holding == constants.ZERO:
402402
return constants.ZERO
403403
return min(order_amount / market_quantity, constants.ONE) * constants.ONE_HUNDRED
404404
raise errors.InvalidArgumentError(f"Unhandled side: {side}")

octobot_trading/personal_data/portfolios/assets/future_asset.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ cdef class FutureAsset(asset_class.Asset):
2929
cpdef object set(self, object total=*, object available=*, object initial_margin=*, object position_margin=*,
3030
object unrealized_pnl=*, object order_margin=*, object margin_balance=*)
3131
cpdef object set_unrealized_pnl(self, object unrealized_pnl) # needs object to forward exceptions
32-
cpdef object update_realised_pnl(self, object realized_pnl_update) # needs object to forward exceptions
32+
cpdef object update_realized_pnl(self, object realized_pnl_update) # needs object to forward exceptions
3333

3434
cdef object _update_total(self)
3535
cdef object _update_available(self)

octobot_trading/personal_data/portfolios/assets/future_asset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def set_unrealized_pnl(self, unrealized_pnl):
146146
self.unrealized_pnl = unrealized_pnl
147147
self._update_total()
148148

149-
def update_realised_pnl(self, realized_pnl_update):
149+
def update_realized_pnl(self, realized_pnl_update):
150150
"""
151151
Updates the realized pnl value
152152
:param realized_pnl_update: the realized pnl update

octobot_trading/personal_data/portfolios/portfolio_util.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def get_draw_down(exchange_manager):
8383
.origin_portfolio.portfolio[value_currency].total
8484
portfolio_history = [origin_value]
8585
for transaction in exchange_manager.exchange_personal_data.transactions_manager.transactions.values():
86-
current_pnl = transaction.quantity if hasattr(transaction, "quantity") else transaction.realised_pnl
86+
current_pnl = transaction.quantity if hasattr(transaction, "quantity") else transaction.realized_pnl
8787
portfolio_history.append(portfolio_history[-1] + current_pnl)
8888

8989
current_draw_down = constants.ONE_HUNDRED - \
@@ -108,15 +108,15 @@ async def get_coefficient_of_determination_data(transactions, start_balance,
108108
if hasattr(transaction, "quantity"):
109109
current_pnl = float(transaction.quantity)
110110
pnl_history_times.append(transaction.creation_time)
111-
elif hasattr(transaction, 'realised_pnl'):
112-
current_pnl = float(transaction.realised_pnl)
111+
elif hasattr(transaction, "realized_pnl"):
112+
current_pnl = float(transaction.realized_pnl)
113113
pnl_history_times.append(transaction.creation_time)
114114
elif isinstance(transaction, dict):
115115
if transaction["quantity"]:
116116
current_pnl = transaction["quantity"]
117117
pnl_history_times.append(transaction["x"])
118-
elif transaction['realised_pnl']:
119-
current_pnl = transaction['realised_pnl']
118+
elif transaction["realized_pnl"]:
119+
current_pnl = transaction["realized_pnl"]
120120
pnl_history_times.append(transaction["x"])
121121

122122
if current_pnl is not None:

octobot_trading/personal_data/portfolios/types/future_portfolio.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def update_portfolio_data_from_position_size_update(self,
5454
"""
5555
Update portfolio data from position size update
5656
:param position: the position updated instance
57-
:param realized_pnl_update: the position realised pnl update
57+
:param realized_pnl_update: the position realized pnl update
5858
:param size_update: the position size update
5959
:param margin_update: the position margin update
6060
:param has_increased_position_size: if the update increased position size
@@ -89,7 +89,7 @@ def update_portfolio_data_from_position_size_update(self,
8989

9090
def update_portfolio_available_from_order(self, order, is_new_order=True):
9191
"""
92-
Realise portfolio availability update
92+
Realize portfolio availability update
9393
:param order: the order that triggers the portfolio update
9494
:param is_new_order: True when the order is being created
9595
"""

octobot_trading/personal_data/positions/position.pxd

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ cdef class Position(util.Initializable):
4848
cdef public object margin
4949
cdef public object initial_margin
5050
cdef public object unrealized_pnl
51-
cdef public object realised_pnl
51+
cdef public object realized_pnl
5252
cdef public object fee_to_close
5353

5454
cdef public double timestamp
@@ -70,7 +70,7 @@ cdef class Position(util.Initializable):
7070
object value,
7171
object initial_margin,
7272
object unrealized_pnl,
73-
object realised_pnl,
73+
object realized_pnl,
7474
object fee_to_close,
7575
object status=*)
7676
cdef bint _should_change(self, object original_value, object new_value)
@@ -87,7 +87,7 @@ cdef class Position(util.Initializable):
8787
cdef bint _is_update_increasing_size(self, object size_update)
8888
cdef bint _is_update_decreasing_size(self, object size_update)
8989
cdef bint _is_update_closing(self, object size_update)
90-
cdef object _update_size(self, object update_size, object realised_pnl_update=*, object trigger_source=*) # needs object to forward exceptions
90+
cdef object _update_size(self, object update_size, object realized_pnl_update=*, object trigger_source=*) # needs object to forward exceptions
9191
cdef void _check_and_update_size(self, object size_update)
9292
cdef void _update_margin(self)
9393
cdef void _reset_entry_price(self)
@@ -96,7 +96,7 @@ cdef class Position(util.Initializable):
9696
cdef void _on_side_update(self, bint reset_entry_price)
9797
cdef object _on_size_update(self,
9898
object size_update,
99-
object realised_pnl_update,
99+
object realized_pnl_update,
100100
object margin_update,
101101
bint is_update_increasing_position_size) # needs object to forward exceptions
102102

0 commit comments

Comments
 (0)