Skip to content

Commit b9cbc72

Browse files
committed
[Typo] fix relised/realized typo and rename enums
tmp tmp rename FILLED
1 parent 02142cf commit b9cbc72

35 files changed

+236
-195
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ No change, pypi issue version
281281
- [Transaction] class
282282
- [TransactionsManager] class
283283
- [TransactionsManager] factory
284-
- [TransactionsManager] transfer, blockchain, fee and realised_pnl
284+
- [TransactionsManager] transfer, blockchain, fee and realized_pnl
285285

286286
### Fixed
287287
- [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: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,9 @@ def parse_position(self, fixed, **kwargs):
190190
enums.ExchangeConstantsPositionColumns.SIDE.value: position_side,
191191
enums.ExchangeConstantsPositionColumns.MARGIN_TYPE.value:
192192
fixed.get(ccxt_enums.ExchangePositionCCXTColumns.MARGIN_TYPE.value, None),
193+
enums.ExchangeConstantsPositionColumns.SINGLE_CONTRACT_VALUE.value:
194+
decimal.Decimal(
195+
f"{fixed.get(ccxt_enums.ExchangePositionCCXTColumns.CONTRACT_SIZE.value, 1)}"),
193196
enums.ExchangeConstantsPositionColumns.SIZE.value:
194197
contract_size * contracts if original_side == enums.PositionSide.LONG.value
195198
else -contract_size * contracts,
@@ -198,7 +201,7 @@ def parse_position(self, fixed, **kwargs):
198201
enums.ExchangeConstantsPositionColumns.COLLATERAL.value:
199202
decimal.Decimal(
200203
f"{fixed.get(ccxt_enums.ExchangePositionCCXTColumns.COLLATERAL.value, 0)}"),
201-
enums.ExchangeConstantsPositionColumns.NOTIONAL.value:
204+
enums.ExchangeConstantsPositionColumns.VALUE.value:
202205
decimal.Decimal(
203206
f"{fixed.get(ccxt_enums.ExchangePositionCCXTColumns.NOTIONAL.value, 0)}"),
204207
enums.ExchangeConstantsPositionColumns.INITIAL_MARGIN.value:
@@ -209,10 +212,10 @@ def parse_position(self, fixed, **kwargs):
209212
f"{fixed.get(ccxt_enums.ExchangePositionCCXTColumns.LEVERAGE.value, 0)}"),
210213
enums.ExchangeConstantsPositionColumns.UNREALIZED_PNL.value:
211214
decimal.Decimal(
212-
f"{fixed.get(ccxt_enums.ExchangePositionCCXTColumns.UNREALISED_PNL.value, 0)}"),
213-
enums.ExchangeConstantsPositionColumns.REALISED_PNL.value:
215+
f"{fixed.get(ccxt_enums.ExchangePositionCCXTColumns.UNREALIZED_PNL.value, 0)}"),
216+
enums.ExchangeConstantsPositionColumns.REALIZED_PNL.value:
214217
decimal.Decimal(
215-
f"{fixed.get(ccxt_enums.ExchangePositionCCXTColumns.REALISED_PNL.value, 0)}"),
218+
f"{fixed.get(ccxt_enums.ExchangePositionCCXTColumns.REALIZED_PNL.value, 0)}"),
216219
enums.ExchangeConstantsPositionColumns.LIQUIDATION_PRICE.value:
217220
decimal.Decimal(
218221
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
@@ -26,8 +26,9 @@ class ExchangeConstantsMarketStatusCCXTColumns(enum.Enum):
2626

2727

2828
class ExchangePositionCCXTColumns(enum.Enum):
29-
CONTRACTS = "contracts"
30-
CONTRACT_SIZE = "contractSize"
29+
ID = "id"
30+
CONTRACTS = "contracts" # == ExchangeConstantsPositionColumn.SIZE
31+
CONTRACT_SIZE = "contractSize" # == ExchangeConstantsPositionColumns.SINGLE_CONTRACT_VALUE
3132
MARGIN_TYPE = "marginType"
3233
MARGIN_MODE = "marginMode"
3334
LEVERAGE = "leverage"
@@ -37,10 +38,10 @@ class ExchangePositionCCXTColumns(enum.Enum):
3738
INITIAL_MARGIN_PERCENTAGE = "initialMarginPercentage"
3839
MAINTENANCE_MARGIN = "maintenanceMargin"
3940
MAINTENANCE_MARGIN_PERCENTAGE = "maintenanceMarginPercentage"
40-
NOTIONAL = "notional"
41+
NOTIONAL = "notional" # == ExchangeConstantsPositionColumn.VALUE
4142
MARGIN_RATIO = "marginRatio"
42-
UNREALISED_PNL = "unrealizedPnl"
43-
REALISED_PNL = "realizedPnl"
43+
UNREALIZED_PNL = "unrealizedPnl"
44+
REALIZED_PNL = "realizedPnl"
4445
LIQUIDATION_PRICE = "liquidationPrice"
4546
MARK_PRICE = "markPrice"
4647
ENTRY_PRICE = "entryPrice"

octobot_trading/exchanges/types/rest_exchange.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ async def get_order_from_trades(self, symbol, order_id, order_to_update=None):
413413
order_to_update[ecoc.TIMESTAMP.value] = order_to_update.get(ecoc.TIMESTAMP.value,
414414
trade[ecoc.TIMESTAMP.value])
415415
order_to_update[ecoc.STATUS.value] = enums.OrderStatus.FILLED.value
416-
order_to_update[ecoc.FILLED.value] = trade[ecoc.AMOUNT.value]
416+
order_to_update[ecoc.FILLED_AMOUNT.value] = trade[ecoc.AMOUNT.value]
417417
order_to_update[ecoc.COST.value] = trade[ecoc.COST.value]
418418
order_to_update[ecoc.REMAINING.value] = 0
419419
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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ def update_from_raw(self, raw_order):
525525
price = stop_price
526526
filled_price = decimal.Decimal(str(price))
527527
# set average price with real average price if available, use filled_price otherwise
528-
average_price = decimal.Decimal(str(raw_order.get(enums.ExchangeConstantsOrderColumns.AVERAGE.value, 0.0)
528+
average_price = decimal.Decimal(str(raw_order.get(enums.ExchangeConstantsOrderColumns.FILLED_PRICE.value, 0.0)
529529
or filled_price))
530530

531531
return self.update(
@@ -535,7 +535,7 @@ def update_from_raw(self, raw_order):
535535
price=decimal.Decimal(str(price)),
536536
status=order_util.parse_order_status(raw_order),
537537
order_id=str(raw_order.get(enums.ExchangeConstantsOrderColumns.ID.value, None)),
538-
quantity_filled=decimal.Decimal(str(raw_order.get(enums.ExchangeConstantsOrderColumns.FILLED.value, 0.0)
538+
quantity_filled=decimal.Decimal(str(raw_order.get(enums.ExchangeConstantsOrderColumns.FILLED_AMOUNT.value, 0.0)
539539
or 0.0)),
540540
filled_price=decimal.Decimal(str(filled_price)),
541541
average_price=decimal.Decimal(str(average_price)),
@@ -610,7 +610,7 @@ def consider_as_canceled(self):
610610
def update_order_from_raw(self, raw_order):
611611
self.status = order_util.parse_order_status(raw_order)
612612
self.total_cost = decimal.Decimal(str(raw_order[enums.ExchangeConstantsOrderColumns.COST.value] or 0))
613-
self.filled_quantity = decimal.Decimal(str(raw_order[enums.ExchangeConstantsOrderColumns.FILLED.value] or 0))
613+
self.filled_quantity = decimal.Decimal(str(raw_order[enums.ExchangeConstantsOrderColumns.FILLED_AMOUNT.value] or 0))
614614
self.filled_price = decimal.Decimal(str(raw_order[enums.ExchangeConstantsOrderColumns.PRICE.value] or 0))
615615
if not self.filled_price and self.filled_quantity:
616616
self.filled_price = self.total_cost / self.filled_quantity
@@ -659,7 +659,7 @@ def to_dict(self):
659659
enums.ExchangeConstantsOrderColumns.AMOUNT.value: self.origin_quantity,
660660
enums.ExchangeConstantsOrderColumns.COST.value: self.total_cost,
661661
enums.ExchangeConstantsOrderColumns.QUANTITY_CURRENCY.value: self.quantity_currency,
662-
enums.ExchangeConstantsOrderColumns.FILLED.value: self.filled_quantity,
662+
enums.ExchangeConstantsOrderColumns.FILLED_AMOUNT.value: self.filled_quantity,
663663
enums.ExchangeConstantsOrderColumns.FEE.value: self.fee,
664664
enums.ExchangeConstantsOrderColumns.REDUCE_ONLY.value: self.reduce_only,
665665
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
@@ -399,15 +399,15 @@ async def get_order_size_portfolio_percent(exchange_manager, order_amount, side,
399399
portfolio_type=commons_constants.PORTFOLIO_TOTAL)
400400
if exchange_manager.is_future:
401401
# TODO check inverse
402-
if market_quantity is constants.ZERO:
402+
if market_quantity == constants.ZERO:
403403
return constants.ZERO
404404
return min(order_amount / market_quantity, constants.ONE) * constants.ONE_HUNDRED
405405
if side is enums.TradeOrderSide.SELL:
406-
if current_symbol_holding is constants.ZERO:
406+
if current_symbol_holding == constants.ZERO:
407407
return constants.ZERO
408408
return min(order_amount / current_symbol_holding, constants.ONE) * constants.ONE_HUNDRED
409409
if side is enums.TradeOrderSide.BUY:
410-
if current_market_holding is constants.ZERO:
410+
if current_market_holding == constants.ZERO:
411411
return constants.ZERO
412412
return min(order_amount / market_quantity, constants.ONE) * constants.ONE_HUNDRED
413413
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)