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

update master #681

Merged
merged 172 commits into from
Jan 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
172 commits
Select commit Hold shift + click to select a range
dec5060
readme update
brettelliot Nov 4, 2024
d9442bd
fix bug so that negative absolute drifts cause a rebalance
brettelliot Nov 4, 2024
c0fcd7b
fix bug in calculating limit price; set default slippate to 50 BPS; a…
brettelliot Nov 5, 2024
0666d79
rename absolute_drift to just drift
brettelliot Nov 5, 2024
b263cf7
enabling or preventing shorting in the drift rebalancer
brettelliot Nov 5, 2024
367f8f3
add shorting strategy param
brettelliot Nov 5, 2024
22e3789
fixed futures and orders position object representations, better filt…
Al4ise Nov 6, 2024
81abc7e
futures improvements, fixed an edge case where portfolio value is 0
Al4ise Nov 7, 2024
3dac0f1
Merge pull request #617 from Lumiwealth/ib-asset-fix
grzesir Nov 7, 2024
5dad969
added tests for bars index being timestamp
brettelliot Nov 7, 2024
a4f70cf
move driftRebalancer to examples; change example to be more lumibot l…
brettelliot Nov 7, 2024
9dbe81c
Merge pull request #611 from Lumiwealth/be-drift-rebalancer-3
grzesir Nov 8, 2024
6a62730
remove numpy restriction and deploy
grzesir Nov 9, 2024
cfee974
even more rigorous retry policies for requests to the ib api
Al4ise Nov 10, 2024
16dc56f
Merge remote-tracking branch 'origin/dev' into ib-retry-policy
Al4ise Nov 10, 2024
2b62d69
formatted
Al4ise Nov 10, 2024
316fe65
Merge pull request #621 from Lumiwealth/ib-retry-policy
grzesir Nov 11, 2024
6593027
fix conflict
brettelliot Nov 11, 2024
bbb1e3f
make sure the index of bars returned by tradier is a timestamp
brettelliot Nov 7, 2024
e2f2dd5
add tests for timezone
brettelliot Nov 7, 2024
1e36c36
check tzinfo; note alpaca tz is UTC which is different from all others
brettelliot Nov 8, 2024
057b675
use a trading calendar to get the start date that is length bars earl…
brettelliot Nov 8, 2024
65880bc
Merge pull request #619 from Lumiwealth/get-bars-fixes
grzesir Nov 11, 2024
6b781e2
add logging when rebalancing
brettelliot Nov 11, 2024
050add4
deploy v3.8.7
grzesir Nov 12, 2024
e273f0f
Merge pull request #623 from Lumiwealth/drift-rebalancer-4
grzesir Nov 13, 2024
e6f947a
bug fixes supposedly
Al4ise Nov 14, 2024
252c29d
Merge remote-tracking branch 'origin/dev' into ib-retry-policy
Al4ise Nov 14, 2024
55f7b1e
Merge pull request #625 from Lumiwealth/ib-retry-policy
grzesir Nov 14, 2024
dd8992f
deploy v3.8.8
grzesir Nov 14, 2024
7e4b178
move DriftRebalancer logic to components; refactor tests
brettelliot Nov 14, 2024
c1c399d
refactored limit order drift rebalancer logic into components
brettelliot Nov 14, 2024
7cd41fe
refactored check if rebalance needed to rebalance logic
brettelliot Nov 14, 2024
efa8142
fix a bug where it got the wrong number of bars when asked to get dat…
brettelliot Nov 14, 2024
fc4c566
move logic out of drift rebalancer strategy and into components
brettelliot Nov 14, 2024
e55c351
pull orders better; catch exceptions;
brettelliot Nov 15, 2024
8dbb4b3
initial work on IB websockets
Al4ise Nov 15, 2024
4a31616
super not ready
Al4ise Nov 15, 2024
37facef
Added DriftRebalancerLogic
brettelliot Nov 16, 2024
4c7b761
refactored tests for DriftCalculationLogic
brettelliot Nov 17, 2024
07a20e4
use DriftRebalancerLogic
brettelliot Nov 17, 2024
eb030ab
Relative drift tests
brettelliot Nov 17, 2024
ecbbec5
market order tests
brettelliot Nov 17, 2024
af9df4e
fixes for orders and websockets
Al4ise Nov 17, 2024
d4ce763
Merge remote-tracking branch 'origin/dev' into ib-retry-policy
Al4ise Nov 17, 2024
6be2a8a
added pytest.ini to gitignore
brettelliot Nov 17, 2024
cb56d61
update comments
brettelliot Nov 17, 2024
a68bf3c
added check when current_weight and target_weight are zero
brettelliot Nov 17, 2024
d1a3e69
more fixes for shorting
brettelliot Nov 18, 2024
eb58784
add websocket
Al4ise Nov 18, 2024
66b1022
removed self.config
Al4ise Nov 18, 2024
62e5a2f
http status codes return
Al4ise Nov 18, 2024
5ba6c33
Merge pull request #626 from Lumiwealth/drift-rebalancer-5
grzesir Nov 18, 2024
7eb1638
Merge pull request #627 from Lumiwealth/ib-retry-policy
grzesir Nov 18, 2024
c54100e
conform orders during submit_order
brettelliot Nov 11, 2024
64966f9
Update alpaca.py
brettelliot Nov 16, 2024
2f57010
Delete test_brokers.py
brettelliot Nov 16, 2024
6f7711d
warn when conforming orders
brettelliot Nov 18, 2024
b2f6e5b
Merge pull request #624 from Lumiwealth/conform-orders
grzesir Nov 18, 2024
3292430
deploy v3.8.9
grzesir Nov 19, 2024
1a0008f
fix setup.py
Al4ise Nov 19, 2024
4fe64bb
Merge pull request #629 from Lumiwealth/ws-patch
grzesir Nov 19, 2024
160f534
deploy v3.8.10
grzesir Nov 19, 2024
97581cb
next iteration of error handling and trade events working for IB
Al4ise Nov 21, 2024
4b2e761
Merge remote-tracking branch 'origin/dev' into ib-retry-policy
Al4ise Nov 21, 2024
addfa57
Merge pull request #631 from Lumiwealth/ib-retry-policy
grzesir Nov 21, 2024
da3174b
v3.8.11 deployed
grzesir Nov 21, 2024
637f349
polygon helper now gets missing dates when there are nans
brettelliot Nov 21, 2024
930daf1
Localize tradier bars.df index instead of converting it
brettelliot Nov 21, 2024
83e645c
renamed set_pandas_float_display_precision
brettelliot Nov 21, 2024
a90a420
moved test_bars to test_get_historical_prices
brettelliot Nov 21, 2024
29c43a2
set_pandas_float_display_precision renamed
brettelliot Nov 21, 2024
98f1fc4
fixed comment to describe what its doing
brettelliot Nov 21, 2024
478d150
add another tradier test, for lengths of 1
brettelliot Nov 21, 2024
1e1b5d2
add a test for alpaca data with a length of 1
brettelliot Nov 21, 2024
7502505
label what the test does
brettelliot Nov 22, 2024
ea3427b
disable my additional checks for missig data cause i can't make the t…
brettelliot Nov 22, 2024
e0703b9
example futures strategy + futures orders fix
Al4ise Nov 22, 2024
d6499b1
example forex strategy
Al4ise Nov 22, 2024
33d84a4
small fix for selling
Al4ise Nov 22, 2024
fd242f4
Merge remote-tracking branch 'origin/dev' into ib-retry-policy
Al4ise Nov 22, 2024
b7e67ad
cleanup
Al4ise Nov 22, 2024
574b3a8
cleaned test_get_historical_prices a bit
brettelliot Nov 22, 2024
631b943
Merge pull request #634 from Lumiwealth/ib-retry-policy
grzesir Nov 22, 2024
44bb1a9
deploy v3.8.12
grzesir Nov 22, 2024
59d2088
fixed futures example
grzesir Nov 22, 2024
6d0a85a
update comments on get_momentum signature
brettelliot Nov 22, 2024
2ace12b
Merge pull request #635 from Lumiwealth/fix-momentum-example
grzesir Nov 22, 2024
90d8449
bump version of lumiwealth-tradier
brettelliot Nov 25, 2024
66bf26e
fixes
Al4ise Nov 26, 2024
ccc09a4
Merge remote-tracking branch 'origin/dev' into ib-retry-policy
Al4ise Nov 26, 2024
c17a820
Merge pull request #637 from Lumiwealth/test-get-bars
grzesir Nov 26, 2024
04bf4ce
pull broker only takes 2 params.
brettelliot Nov 27, 2024
4748327
fixes
Al4ise Nov 27, 2024
650ad42
Merge remote-tracking branch 'origin/dev' into ib-retry-policy
Al4ise Nov 27, 2024
e8ec025
fix for order circle color
Al4ise Nov 27, 2024
5c58a74
comment out broken test
brettelliot Nov 28, 2024
9539132
Merge pull request #639 from Lumiwealth/drift-rebalancer-6
grzesir Nov 28, 2024
4067047
Merge pull request #638 from Lumiwealth/ib-retry-policy
grzesir Nov 28, 2024
5b46f04
deploy v3.8.13
grzesir Nov 28, 2024
7974087
potential fix for the send update to cloud function
Al4ise Nov 29, 2024
9c2ce7b
Merge remote-tracking branch 'origin/dev' into ib-retry-policy
Al4ise Nov 29, 2024
c0c6422
handle one more error IB
Al4ise Nov 29, 2024
449fdf3
Merge pull request #640 from Lumiwealth/ib-retry-policy
grzesir Nov 29, 2024
6dc59cf
deployed 3.8.14
grzesir Nov 29, 2024
c0bc567
bug fix for float in historical data
grzesir Nov 29, 2024
6ef0ae4
ib fixes + changes to submit_orders methods
Al4ise Dec 2, 2024
7851fe3
Merge remote-tracking branch 'origin/dev' into ib-retry-policy
Al4ise Dec 2, 2024
230f458
less error logging
Al4ise Dec 2, 2024
79d4a30
further cleanup of strategy classes
Al4ise Dec 3, 2024
0fdb71a
fix for tests?
Al4ise Dec 3, 2024
6ddee3f
IB Fix for hanging issue
Al4ise Dec 3, 2024
977d58c
quick fix
Al4ise Dec 3, 2024
b295196
Merge pull request #641 from Lumiwealth/float-in-historical-data-bug-fix
grzesir Dec 3, 2024
d16d093
Merge pull request #643 from Lumiwealth/ib-hang-fix
grzesir Dec 3, 2024
bbf9d19
Merge pull request #642 from Lumiwealth/ib-retry-policy
grzesir Dec 3, 2024
057a680
deploy v3.8.16
grzesir Dec 3, 2024
9a16d99
When rebalancing, sort the sells and buys by biggest drift first.
brettelliot Dec 4, 2024
0122f2d
update check for printing a warning about not rebalancing
brettelliot Dec 4, 2024
6958933
Use logger for everything instead of logging to discord
brettelliot Dec 5, 2024
4f5c7f9
remove logging of crash events
brettelliot Dec 5, 2024
5b3b42f
Fix for tradier?
Al4ise Dec 6, 2024
51c9b72
show approximately 99.4% less errors for IB
Al4ise Dec 6, 2024
78cef9a
implemented strategy.run_live() in the example strategies
Al4ise Dec 6, 2024
1460e79
Merge pull request #653 from Lumiwealth/drift-rebalancer-7
grzesir Dec 7, 2024
5056c03
edit readme
grzesir Dec 7, 2024
542f2b2
Update README.md
grzesir Dec 7, 2024
d9d5cfe
Merge pull request #654 from Lumiwealth/tradier-fix
grzesir Dec 7, 2024
19ed9dc
Merge pull request #655 from Lumiwealth/ib-retry-policy
grzesir Dec 7, 2024
9239262
deploy v3.8.17
grzesir Dec 7, 2024
7f52f76
cleaned up dependencies, python 3.13 support
Al4ise Dec 9, 2024
ff43148
Merge remote-tracking branch 'origin/dev' into m-dev
Al4ise Dec 9, 2024
f283b36
re-added pyarrow
Al4ise Dec 9, 2024
5af754f
Fix for Alpaca order tracking
Al4ise Dec 9, 2024
912eb7b
fixes for alpaca and IB
Al4ise Dec 10, 2024
af1a90c
Merge pull request #658 from Lumiwealth/3.13-support
grzesir Dec 11, 2024
f95160b
Merge pull request #660 from Lumiwealth/alpaca-fix
grzesir Dec 11, 2024
c029cad
deploy v3.8.18
grzesir Dec 11, 2024
b8da35a
backtest: When running a long backtest that goes across Daylight Savi…
davidlatte Dec 11, 2024
e494270
handle dates better in get_historical_prices and deploy
grzesir Dec 11, 2024
ef50e38
timezone bug fix
grzesir Dec 12, 2024
f22a0a0
Merge branch 'dev' into daylight_savings_backtest_fix
davidlatte Dec 12, 2024
2bd6634
backtest: When running a long backtest that goes across Daylight Savi…
davidlatte Dec 11, 2024
397363c
unittest: skipping ThetaData tests that aren't ready yet.
davidlatte Dec 12, 2024
6cb4be2
unittest: skipping ThetaData tests that aren't ready yet.
davidlatte Dec 12, 2024
785f195
Merge remote-tracking branch 'origin/daylight_savings_backtest_fix' i…
davidlatte Dec 12, 2024
8887e2a
Merge pull request #662 from Lumiwealth/daylight_savings_backtest_fix
davidlatte Dec 12, 2024
c561e31
less agressive trim on dependencies
Al4ise Dec 12, 2024
7ba58aa
added psycopg2-binary as dependency
grzesir Dec 12, 2024
a77ad9e
Merge branch 'dev' of https://github.com/Lumiwealth/lumibot into dev
grzesir Dec 12, 2024
162f373
Fix: Check timeInForce exists on Kraken API response.
Dec 14, 2024
4c422da
Merge pull request #664 from WilliamWhispell/dev
grzesir Dec 14, 2024
1b653c4
Update setup.py
Al4ise Dec 16, 2024
8d30de2
order: adding "cash_settled" as a valid fill type.
davidlatte Dec 16, 2024
cdcb8cd
Merge pull request #665 from Lumiwealth/order_cash_settled
grzesir Dec 17, 2024
67961f8
Merge branch 'dev' into 3.13-fix
grzesir Dec 17, 2024
091d580
Merge pull request #663 from Lumiwealth/3.13-fix
grzesir Dec 17, 2024
7224331
json.dumps fix
grzesir Dec 17, 2024
25d22b3
Merge branch 'dev' of https://github.com/Lumiwealth/lumibot into dev
grzesir Dec 17, 2024
9ca9484
fixes for docker messages + fixes for ib weekend maintenance errors
Al4ise Dec 17, 2024
a94fabd
Merge remote-tracking branch 'origin/dev' into ib-fixes-n+1
Al4ise Dec 17, 2024
3e426ff
fix for historical
Al4ise Dec 17, 2024
b7e8ada
Merge pull request #667 from Lumiwealth/ib-fixes-n+1
grzesir Dec 17, 2024
cac64a2
deploy 3.8.22
grzesir Dec 17, 2024
82945af
change warning to debug
brettelliot Dec 18, 2024
99f2f70
Merge pull request #668 from Lumiwealth/change-backup-warning-to-debug
grzesir Dec 18, 2024
f09e38d
added strategy_name to cloud update and deploy 3.8.23
grzesir Dec 22, 2024
5664f94
add broker name to cloud update and deploy
grzesir Dec 22, 2024
5bbfc67
Added ConfigsHelper to components
brettelliot Jan 6, 2025
a0711f4
move config to examples directory.
brettelliot Jan 6, 2025
4b48452
Merge pull request #675 from Lumiwealth/be-config-helper
grzesir Jan 7, 2025
fb217f4
added types to all strategy methods
grzesir Jan 12, 2025
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ test_bot.py
lumi_tradier
lumiwealth_tradier
ThetaTerminal.jar
pytest.ini

# Pypi deployment
build
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ To run this example strategy, click on the `Deploy to Render` button below to de

If you want to contribute to Lumibot, you can check how to get started below. We are always looking for contributors to help us out!

Here's a video to help you get started with contributing to Lumibot: [Watch The Video](https://youtu.be/Huz6VxqafZs)

**Steps to contribute:**

0. Watch the video: [Watch The Video](https://youtu.be/Huz6VxqafZs)
1. Clone the repository to your local machine
2. Create a new branch for your feature
3. Run `pip install -r requirements_dev.txt` to install the developer dependencies
Expand Down
10 changes: 9 additions & 1 deletion lumibot/backtesting/backtesting_broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from decimal import Decimal
from functools import wraps

import pandas as pd
import pytz

from lumibot.brokers import Broker
from lumibot.data_sources import DataSourceBacktesting
Expand Down Expand Up @@ -88,13 +88,19 @@ def get_historical_account_value(self):
def _update_datetime(self, update_dt, cash=None, portfolio_value=None):
"""Works with either timedelta or datetime input
and updates the datetime of the broker"""
tz = self.datetime.tzinfo
is_pytz = isinstance(tz, (pytz.tzinfo.StaticTzInfo, pytz.tzinfo.DstTzInfo))

if isinstance(update_dt, timedelta):
new_datetime = self.datetime + update_dt
elif isinstance(update_dt, int) or isinstance(update_dt, float):
new_datetime = self.datetime + timedelta(seconds=update_dt)
else:
new_datetime = update_dt

# This is needed to handle Daylight Savings Time changes
new_datetime = tz.normalize(new_datetime) if is_pytz else new_datetime

self.data_source._update_datetime(new_datetime, cash=cash, portfolio_value=portfolio_value)
if self.option_source:
self.option_source._update_datetime(new_datetime, cash=cash, portfolio_value=portfolio_value)
Expand Down Expand Up @@ -386,6 +392,8 @@ def _process_cash_settlement(self, order, price, quantity):

def submit_order(self, order):
"""Submit an order for an asset"""
self._conform_order(order)

# NOTE: This code is to address Tradier API requirements, they want is as "to_open" or "to_close" instead of just "buy" or "sell"
# If the order has a "buy_to_open" or "buy_to_close" side, then we should change it to "buy"
if order.is_buy_order():
Expand Down
31 changes: 29 additions & 2 deletions lumibot/brokers/alpaca.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from lumibot.data_sources import AlpacaData
from lumibot.entities import Asset, Order, Position
from lumibot.tools.helpers import has_more_than_n_decimal_places

from .broker import Broker

Expand Down Expand Up @@ -446,6 +447,7 @@ def _submit_order(self, order):
order.set_identifier(response.id)
order.status = response.status
order.update_raw(response)
self._unprocessed_orders.append(order)

except Exception as e:
order.set_error(e)
Expand All @@ -467,6 +469,32 @@ def _submit_order(self, order):

return order

def _conform_order(self, order):
"""Conform an order to Alpaca's requirements
See: https://docs.alpaca.markets/docs/orders-at-alpaca
"""
if order.asset.asset_type == "stock" and order.type == "limit":
"""
The minimum price variance exists for limit orders.
Orders received in excess of the minimum price variance will be rejected.
Limit price >=$1.00: Max Decimals = 2
Limit price <$1.00: Max Decimals = 4
"""
orig_price = order.limit_price
conformed = False
if order.limit_price >= 1.0 and has_more_than_n_decimal_places(order.limit_price, 2):
order.limit_price = round(order.limit_price, 2)
conformed = True
elif order.limit_price < 1.0 and has_more_than_n_decimal_places(order.limit_price, 4):
order.limit_price = round(order.limit_price, 4)
conformed = True

if conformed:
logging.warning(
f"Order {order} was changed to conform to Alpaca's requirements. "
f"The limit price was changed from {orig_price} to {order.limit_price}."
)

def cancel_order(self, order):
"""Cancel an order

Expand Down Expand Up @@ -520,14 +548,13 @@ def _run_stream(self):
"""

async def _trade_update(trade_update):
self._orders_queue.join()
try:
logged_order = trade_update.order
type_event = trade_update.event
identifier = logged_order.id
stored_order = self.get_tracked_order(identifier)
if stored_order is None:
logging.info(f"Untracked order {identifier} was logged by broker {self.name}")
logging.debug(f"Untracked order {identifier} was logged by broker {self.name}")
return False

price = trade_update.price
Expand Down
58 changes: 31 additions & 27 deletions lumibot/brokers/broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
from dateutil import tz
from termcolor import colored

from lumibot.data_sources import DataSource
from lumibot.entities import Asset, Order, Position
from lumibot.trading_builtins import SafeList
from ..data_sources import DataSource
from ..entities import Asset, Order, Position
from ..trading_builtins import SafeList


class CustomLoggerAdapter(logging.LoggerAdapter):
Expand Down Expand Up @@ -287,7 +287,7 @@ def sync_positions(self, strategy):
else:
# Add to positions in lumibot, position does not exist
# in lumibot.
if position.quantity != 0:
if position.quantity != 0.0:
self._filled_positions.append(position)

# Now iterate through lumibot positions.
Expand Down Expand Up @@ -566,28 +566,14 @@ def _wait_for_orders(self):

self._orders_queue.task_done()

def _submit_orders(self, orders) -> list[Order]:
with ThreadPoolExecutor(
max_workers=self.max_workers,
thread_name_prefix=f"{self.name}_submitting_orders",
) as executor:
tasks = []
for order in orders:
tasks.append(executor.submit(self._submit_order, order))

result = []
for task in as_completed(tasks):
result.append(task.result())

return result

# =========Internal functions==============

def _set_initial_positions(self, strategy):
"""Set initial positions"""
positions = self._pull_positions(strategy)
for pos in positions:
self._filled_positions.append(pos)
if pos.quantity != 0.0:
self._filled_positions.append(pos)

def _process_new_order(self, order):
# Check if this order already exists in self._new_orders based on the identifier
Expand Down Expand Up @@ -957,12 +943,30 @@ def _pull_all_orders(self, strategy_name, strategy_object):
return result

def submit_order(self, order):
"""Submit an order for an asset"""
"""Conform an order for an asset to broker constraints and submit it."""
self._conform_order(order)
self._submit_order(order)

def _conform_order(self, order):
"""Conform an order to broker constraints. Derived brokers should implement this method."""
pass

def submit_orders(self, orders, **kwargs):
"""Submit orders"""
self._submit_orders(orders, **kwargs)
if hasattr(self, '_submit_orders'):
self._submit_orders(orders, **kwargs)
else:
with ThreadPoolExecutor(
max_workers=self.max_workers,
thread_name_prefix=f"{self.name}_submitting_orders",
) as executor:
tasks = []
for order in orders:
tasks.append(executor.submit(self._submit_order, order))

result = []
for task in as_completed(tasks):
result.append(task.result())

def wait_for_order_registration(self, order):
"""Wait for the order to be registered by the broker"""
Expand Down Expand Up @@ -1200,21 +1204,21 @@ def _process_trade_event(self, stored_order, type_event, price=None, filled_quan
except ValueError:
raise error

if type_event == self.NEW_ORDER:
if Order.is_equivalent_status(type_event, self.NEW_ORDER):
stored_order = self._process_new_order(stored_order)
self._on_new_order(stored_order)
elif type_event == self.CANCELED_ORDER:
elif Order.is_equivalent_status(type_event, self.CANCELED_ORDER):
# Do not cancel or re-cancel already completed orders
if stored_order.is_active():
stored_order = self._process_canceled_order(stored_order)
self._on_canceled_order(stored_order)
elif type_event == self.PARTIALLY_FILLED_ORDER:
elif Order.is_equivalent_status(type_event, self.PARTIALLY_FILLED_ORDER):
stored_order, position = self._process_partially_filled_order(stored_order, price, filled_quantity)
self._on_partially_filled_order(position, stored_order, price, filled_quantity, multiplier)
elif type_event == self.FILLED_ORDER:
elif Order.is_equivalent_status(type_event, self.FILLED_ORDER):
position = self._process_filled_order(stored_order, price, filled_quantity)
self._on_filled_order(position, stored_order, price, filled_quantity, multiplier)
elif type_event == self.CASH_SETTLED:
elif Order.is_equivalent_status(type_event, self.CASH_SETTLED):
self._process_cash_settlement(stored_order, price, filled_quantity)
stored_order.type = self.CASH_SETTLED
else:
Expand Down
7 changes: 5 additions & 2 deletions lumibot/brokers/ccxt.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def _parse_broker_order(self, response, strategy_name, strategy_object=None):
response["side"],
limit_price=response["price"],
stop_price=response["stopPrice"],
time_in_force=response["timeInForce"].lower(),
time_in_force=response["timeInForce"].lower() if response["timeInForce"] else None,
quote=Asset(
symbol=pair[1],
asset_type="crypto",
Expand All @@ -324,7 +324,10 @@ def _pull_broker_order(self, identifier):
def _pull_broker_closed_orders(self):
params = {}

if self.is_margin_enabled():
if self.api.id == "kraken": # Check if the exchange is Kraken
logging.info("Detected Kraken exchange. Not sending params for closed orders.")
params = None # Ensure no parameters are sent
elif self.is_margin_enabled():
params["tradeType"] = "MARGIN_TRADE"

closed_orders = self.api.fetch_closed_orders(params)
Expand Down
6 changes: 4 additions & 2 deletions lumibot/brokers/interactive_brokers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging
import random
import time
from collections import defaultdict, deque
from collections import deque
from decimal import Decimal
from threading import Thread
import math
Expand Down Expand Up @@ -316,7 +316,7 @@ def _flatten_order(self, orders): # implement for stop loss.
"""Not used for Interactive Brokers. Just returns the orders."""
return orders

def submit_orders(self, orders, is_multileg=False, duration="day", price=None, **kwargs):
def _submit_orders(self, orders, is_multileg=False, duration="day", price=None, **kwargs):
if is_multileg:
multileg_order = OrderLum(orders[0].strategy)
multileg_order.order_class = OrderLum.OrderClass.MULTILEG
Expand All @@ -331,8 +331,10 @@ def submit_orders(self, orders, is_multileg=False, duration="day", price=None, *

# Submit the multileg order.
self._orders_queue.put(multileg_order)
return multileg_order
else:
self._orders_queue.put(orders)
return orders

def _submit_order(self, order):
"""Submit an order for an asset"""
Expand Down
Loading
Loading