Giter Site home page Giter Site logo

looptrader's Introduction


LoopTrader
LoopTrader

An extensible options trading bot built on top of Python.

DescriptionInstallationUsageContributingLicense

Description

The goal for LoopTrader is to provide a flexible engine for running one or more option trading strategies in real-time against provided broker API's. The Key Features include:

  • Simple to setup and run multiple trading bots
  • Extensibility for various brokers, trading strategies, and logging patterns
  • Local storage for trades and orders (In Progress)
  • Support for notifications and interactions through tools like Telegram

LoopTrader is very much a work in progress and is currently not feature complete. See the Issues for what remains open, or to make a suggestion.

Installation

Getting up and running with LoopTrader is just a few commands:

# Clone LoopTrader
git clone https://github.com/pattertj/LoopTrader.git

# Install dependencies
pipenv install --dev

# Setup pre-commit and pre-push hooks
pipenv run pre-commit install -t pre-commit
pipenv run pre-commit install -t pre-push

More detailed instructions on specific components can be found in the wiki.

Usage

Currently all configuration of LoopTrader is done in the code when creating the bot in main.py, the .env, and config.yaml file. A sample .env and .yaml file are provided, but should be renamed to ".env" and "config.yaml" respectively, with the configuration variables populated.

Contributing

Start contributing right now:

Open an issue

If you've found a problem, you can open an issue!

Solve an issue

If you have a solution to one of the open issues, you will need to fork the repository and submit a pull request.

Credits

Big thanks to the great people on Discord. You know who you are.

License

GNU General Public License v3.0


GitHub @pattertj

looptrader's People

Contributors

dependabot[bot] avatar pattertj avatar sourcery-ai[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

looptrader's Issues

Killswitch does not work during order loop.

Describe the bug
Kill switch does not work accurately when the bot is running and placing orders.

To Reproduce
To test the bot, and order, I commented out the logic inside the cspByDeltaStrategy.py as follows. Once the bot was started, it places orders and cancelled orders, looked for new strike/delta as designed. Sending a killswitch message did not result in bot stopping at any point in time.

If this is working correctly in other environment, it is likely that it is working after the bot has placed the order, and does not have to be in a loop to put another one (and go into place -> cancel -> place sequence). As killswitch is designed to kill the bot under extraordinary circumstances, such as market conditions, it would be ideal to be able to kill the bot between these loops.

Core Strategy Process

def process_strategy(self):
    """Main entry point to the strategy."""
    logger.debug("processstrategy")

    # Get current datetime
    now = dt.datetime.now().astimezone(dt.timezone.utc)
    '''
    # Check if should be sleeping
    if now < self.sleepuntil:
        logger.debug("Markets Closed. Sleeping until {}".format(self.sleepuntil))
        return
    '''
    # Check market hours
    hours = self.get_market_session_loop(dt.datetime.now())

    if hours is None:
        logger.error("Failed to get market hours, exiting and retrying.")
        return
    '''
    # If the next market session is not today, wait for it
    if hours.start.day != now.day:
        self.sleepuntil = (
            hours.start
            + dt.timedelta(minutes=self.minutesafteropendelay)
            - dt.timedelta(minutes=5)
        )
        logger.info(
            "Markets are closed until {}. Sleeping until {}".format(
                hours.start, self.sleepuntil
            )
        )
        return
    '''
    self.process_open_market(hours.end, now)
    '''
    # If Pre-Market
    if now < hours.start + dt.timedelta(minutes=self.minutesafteropendelay):
        self.process_pre_market()

    # If In-Market
    elif (
        hours.start + dt.timedelta(minutes=self.minutesafteropendelay)
        < now
        < hours.end
    ):
        self.process_open_market(hours.end, now)

    # If After-Hours
    elif hours.end < now:
        self.process_after_hours(hours.end, now)
    '''
# Process Market
def process_pre_market(self):
    """Pre-Market Trading Logic"""
    logger.debug("Processing Pre-Market.")

    # Get Next Open
    nextmarketsession = self.get_market_session_loop(dt.datetime.now())

    # Set sleepuntil
    self.sleepuntil = (
        nextmarketsession.start
        + dt.timedelta(minutes=self.minutesafteropendelay)
        - dt.timedelta(minutes=5)
    )

    logger.info(
        "Markets are closed until {}. Sleeping until {}".format(
            nextmarketsession.start
            + dt.timedelta(minutes=self.minutesafteropendelay),
            self.sleepuntil,
        )
    )

Bot stops processing upon error

Describe the bug
I put an order for XSP in order to test this out. The 70% PT would have resulted in non-zero limitPrice. This caused the bot to stop responding, while the bot was running.

To Reproduce
Take a smaller delta on XSP and put an order, which would result in non-zero order for limit/closing price.

Expected behavior
Bot should continue processing despite error.

Log
Grabbing new access token...
ERROR - Failed to place order.
Traceback (most recent call last):
File "/home/azureuser/LoopTrader/looptrader/basetypes/Broker/tdaBroker.py", line 260, in place_order
orderresponse = self.getsession().place_order(
File "/home/azureuser/.local/lib/python3.9/site-packages/td/client.py", line 1925, in place_order
return self._make_request(method='post', endpoint=endpoint, mode='json', json=order, order_details=True)
File "/home/azureuser/.local/lib/python3.9/site-packages/td/client.py", line 617, in _make_request
raise NotNulError(message=response.text)
td.exceptions.NotNulError: {
"error" : "non-zero limitPrice is required when orderType is Limit or Stop Limit"
}
Traceback (most recent call last):
File "/home/azureuser/LoopTrader/looptrader/main.py", line 39, in
bot.process_strategies()
File "/home/azureuser/LoopTrader/looptrader/basetypes/Mediator/botMediator.py", line 72, in process_strategies
strategy.process_strategy()
File "/home/azureuser/LoopTrader/looptrader/basetypes/Strategy/cspByDeltaStrategy.py", line 102, in process_strategy
self.process_open_market(hours.end, now)
File "/home/azureuser/LoopTrader/looptrader/basetypes/Strategy/cspByDeltaStrategy.py", line 142, in process_open_market
self.place_new_orders_loop()
File "/home/azureuser/LoopTrader/looptrader/basetypes/Strategy/cspByDeltaStrategy.py", line 430, in place_new_orders_loop
neworder = self.build_new_order()
File "/home/azureuser/LoopTrader/looptrader/basetypes/Strategy/cspByDeltaStrategy.py", line 295, in build_new_order
int(position.symbol[-4:])
ValueError: invalid literal for int() with base 10: 'P413'

Exception Error in telegramNotifier.py

Describe the bug
Getting an Exception Error when running main.py when it gets to line 35 of telegramNotifier.py

Error as follows:

init() missing 1 required positional argument: 'update_queue'

I'm running Python 3.9 on a Windows 10 device using Visual Studio Code to debug and have python_telegram_bot==13.5 installed.

400 Error Bad Request: Input Date is not Acceptable When Running Bot After Hours

Describe the bug

"status":400,"error":"Bad Request","message":"Input date is not acceptable.","path":"/markethours-v1/markets/"}

###################

Error Output Below

###################

File "C:\Users\philz\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\td\client.py", line 617, in _make_request
raise NotNulError(message=response.text)
td.exceptions.NotNulError: {"timestamp":"2021-05-07","status":400,"error":"Bad Request","message":"Input date is not acceptable.","path":"/markethours-v1/markets/"}
ERROR - Failed to get market hours, exiting and retrying.
ERROR - Failed to get market hours for ['OPTION'] on 2021-05-06 23:08:22.796997.
Traceback (most recent call last):
File "C:\Users\Public\LoopTrader-main\BaseTypes\Broker\tdaBroker.py", line 303, in get_market_hours
hours = self.getsession().get_market_hours(markets=markets, date=str(request.datetime))
File "C:\Users\philz\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\td\client.py", line 980, in get_market_hours
return self._make_request(method='get', endpoint=endpoint, params=params)
File "C:\Users\philz\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\td\client.py", line 617, in _make_request
raise NotNulError(message=response.text)
td.exceptions.NotNulError: {"timestamp":"2021-05-07","status":400,"error":"Bad Request","message":"Input date is not acceptable.","path":"/markethours-v1/markets/"}
ERROR - Failed to get market hours, exiting and retrying.

To Reproduce
Steps to reproduce the behavior:

  1. Launch main.py via Visual Studio Code / monitor output
  2. The above output was generated when running the bot at 11:08 PM Pacific Time
    autotrader.log

Expected behavior

Telegram reports the bot has started and I can pull balances and orders no problem.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

Windows 10

Credential file not generated

Describe the bug
Credential file does not generate. Most likely will not refresh after expiration. Running the application does not prompt the OATH authentication.

To Reproduce
Start the app.
{'credential_path': '/Users/s_pant/Desktop/backupmeup/autotrader/LoopTrader/td_session.json',
'message': 'The credential file does not contain expiration times for your '
'tokens, please go through the oAuth process.'}
{'credential_path': '/Users/s_pant/Desktop/backupmeup/autotrader/LoopTrader/td_session.json',
'message': 'The credential file does not contain expiration times for your '
'tokens, please go through the oAuth process.'}
{'credential_path': '/Users/s_pant/Desktop/backupmeup/autotrader/LoopTrader/td_session.json',
'message': 'The credential file does not contain expiration times for your '
'tokens, please go through the oAuth process.'}
{'credential_path': '/Users/s_pant/Desktop/backupmeup/autotrader/LoopTrader/td_session.json',
'message': 'The credential file does not contain expiration times for your '
'tokens, please go through the oAuth process.'}

Expected behavior
A login oath authentication prompt from which the credential file would be populated.

Credential path in .env is as follows:
CREDENTIALS_PATH= "/Users/s_pant/Desktop/backupmeup/autotrader/LoopTrader/td_session.json"

When this file is generated using the API (by writing the sample app), the app works.

Error on MacOS/Ubuntu Server

As soon as the new instance is started, the telegram gets 4 notifications, and fails with the following error.

2021-05-29 21:33:15,220 - sqliteDatabase.py - pre_flight_db_check() - INFO - Positions Table Created.
2021-05-29 21:33:15,221 - sqliteDatabase.py - pre_flight_db_check() - INFO - Orders Table Created.
2021-05-29 21:33:15,222 - sqliteDatabase.py - pre_flight_db_check() - INFO - Strategies Table Created.
2021-05-29 21:33:15,222 - sqliteDatabase.py - pre_flight_db_check() - INFO - Pre-Flight Checks Complete.
2021-05-29 21:33:16,316 - cspByDeltaStrategy.py - process_strategy() - DEBUG - processstrategy
2021-05-29 21:33:16,316 - cspByDeltaStrategy.py - get_market_session_loop() - DEBUG - get_market_session_loop
2021-05-29 21:33:16,678 - cspByDeltaStrategy.py - get_market_session_loop() - DEBUG - get_market_session_loop
2021-05-29 21:33:16,959 - cspByDeltaStrategy.py - get_market_session_loop() - DEBUG - get_market_session_loop
2021-05-29 21:33:17,250 - cspByDeltaStrategy.py - get_market_session_loop() - DEBUG - get_market_session_loop
2021-05-29 21:33:17,555 - cspByDeltaStrategy.py - process_strategy() - INFO - Markets are closed until 2021-06-01 13:30:00+00:00. Sleeping until 2021-06-01 13:28:00+00:00
2021-05-29 21:33:17,555 - botMediator.py - process_strategies() - INFO - Sleeping...
2021-05-29 21:33:38,427 - telegramnotifier.py - reply_text() - ERROR - Telegram failed to reply.
Traceback (most recent call last):
File "/Users/s_pant/Desktop/backupmeup/autotrader/LoopTrader/looptrader/basetypes/Notifier/telegramnotifier.py", line 357, in reply_text
message.reply_text(
File "/usr/local/lib/python3.9/site-packages/telegram/message.py", line 689, in reply_text
return self.bot.send_message(
File "/usr/local/lib/python3.9/site-packages/telegram/bot.py", line 127, in decorator
result = func(*args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/telegram/bot.py", line 475, in send_message
return self._message( # type: ignore[return-value]
File "/usr/local/lib/python3.9/site-packages/telegram/bot.py", line 296, in _message
result = self._post(endpoint, data, timeout=timeout, api_kwargs=api_kwargs)
File "/usr/local/lib/python3.9/site-packages/telegram/bot.py", line 259, in _post
return self.request.post(
File "/usr/local/lib/python3.9/site-packages/telegram/utils/request.py", line 349, in post
result = self._request_wrapper(
File "/usr/local/lib/python3.9/site-packages/telegram/utils/request.py", line 272, in _request_wrapper
raise BadRequest(message)
telegram.error.BadRequest: Can't parse entities: character '.' is reserved and must be escaped with the preceding ''
2021-05-29 21:34:15,797 - cspByDeltaStrategy.py - process_strategy() - DEBUG - processstrategy
2021-05-29 21:34:15,797 - cspByDeltaStrategy.py - process_strategy() - DEBUG - Markets Closed. Sleeping until 2021-06-01 13:28:00+00:00
2021-05-29 21:34:15,798 - botMediator.py - process_strategies() - INFO - Sleeping...
2021-05-29 21:35:15,801 - cspByDeltaStrategy.py - process_strategy() - DEBUG - processstrategy
2021-05-29 21:35:15,801 - cspByDeltaStrategy.py - process_strategy() - DEBUG - Markets Closed. Sleeping until 2021-06-01 13:28:00+00:00
2021-05-29 21:35:15,801 - botMediator.py - process_strategies() - INFO - Sleeping...
2021-05-29 21:36:15,801 - cspByDeltaStrategy.py - process_strategy() - DEBUG - processstrategy
2021-05-29 21:36:15,801 - cspByDeltaStrategy.py - process_strategy() - DEBUG - Markets Closed. Sleeping until 2021-06-01 13:28:00+00:00
2021-05-29 21:36:15,801 - botMediator.py - process_strategies() - INFO - Sleeping...
2021-05-29 21:41:56,416 - sqliteDatabase.py - pre_flight_db_check() - INFO - Pre-Flight Checks Complete.
2021-05-29 21:41:57,476 - cspByDeltaStrategy.py - process_strategy() - DEBUG - processstrategy
2021-05-29 21:41:57,476 - cspByDeltaStrategy.py - get_market_session_loop() - DEBUG - get_market_session_loop
2021-05-29 21:41:58,095 - cspByDeltaStrategy.py - get_market_session_loop() - DEBUG - get_market_session_loop
2021-05-29 21:41:58,578 - cspByDeltaStrategy.py - get_market_session_loop() - DEBUG - get_market_session_loop
2021-05-29 21:41:59,160 - cspByDeltaStrategy.py - get_market_session_loop() - DEBUG - get_market_session_loop
2021-05-29 21:41:59,891 - cspByDeltaStrategy.py - process_strategy() - INFO - Markets are closed until 2021-06-01 13:30:00+00:00. Sleeping until 2021-06-01 13:28:00+00:00
2021-05-29 21:41:59,891 - botMediator.py - process_strategies() - INFO - Sleeping...
2021-05-29 21:42:54,124 - sqliteDatabase.py - pre_flight_db_check() - INFO - Pre-Flight Checks Complete.
2021-05-29 21:42:55,140 - cspByDeltaStrategy.py - process_strategy() - DEBUG - processstrategy
2021-05-29 21:42:55,140 - cspByDeltaStrategy.py - get_market_session_loop() - DEBUG - get_market_session_loop
2021-05-29 21:42:55,475 - cspByDeltaStrategy.py - get_market_session_loop() - DEBUG - get_market_session_loop
2021-05-29 21:42:55,804 - cspByDeltaStrategy.py - get_market_session_loop() - DEBUG - get_market_session_loop
2021-05-29 21:42:56,117 - cspByDeltaStrategy.py - get_market_session_loop() - DEBUG - get_market_session_loop
2021-05-29 21:42:56,409 - cspByDeltaStrategy.py - process_strategy() - INFO - Markets are closed until 2021-06-01 13:30:00+00:00. Sleeping until 2021-06-01 13:28:00+00:00
2021-05-29 21:42:56,409 - botMediator.py - process_strategies() - INFO - Sleeping...
2021-05-29 21:43:32,940 - telegramnotifier.py - error() - WARNING - Update "None" caused error "Conflict: terminated by other getUpdates request; make sure that only one bot instance is running"
2021-05-29 21:43:38,167 - telegramnotifier.py - error() - WARNING - Update "None" caused error "Conflict: terminated by other getUpdates request; make sure that only one bot instance is running"
2021-05-29 21:43:44,413 - telegramnotifier.py - error() - WARNING - Update "None" caused error "Conflict: terminated by other getUpdates request; make sure that only one bot instance is running"
2021-05-29 21:43:52,119 - telegramnotifier.py - error() - WARNING - Update "None" caused error "Conflict: terminated by other getUpdates request; make sure that only one bot instance is running"
2021-05-29 21:43:54,605 - cspByDeltaStrategy.py - process_strategy() - DEBUG - processstrategy
2021-05-29 21:43:54,605 - cspByDeltaStrategy.py - process_strategy() - DEBUG - Markets Closed. Sleeping until 2021-06-01 13:28:00+00:00
2021-05-29 21:43:54,605 - botMediator.py - process_strategies() - INFO - Sleeping...
2021-05-29 21:43:59,090 - telegramnotifier.py - error() - WARNING - Update "None" caused error "Conflict: terminated by other getUpdates request; make sure that only one bot instance is running"
2021-05-29 21:44:09,498 - telegramnotifier.py - error() - WARNING - Update "None" caused error "Conflict: terminated by other getUpdates request; make sure that only one bot instance is running"
2021-05-29 21:44:24,912 - telegramnotifier.py - error() - WARNING - Update "None" caused error "Conflict: terminated by other getUpdates request; make sure that only one bot instance is running"

tdaBroker.py - build_account_position() - ERROR - No strike price found for [TICKER]

Describe the bug
2021-06-07 16:30:34,903 - cspByDeltaStrategy.py - process_closing_orders() - DEBUG - process_closing_orders
2021-06-07 16:30:34,903 - cspByDeltaStrategy.py - build_closing_orders() - DEBUG - build_closing_orders
2021-06-07 16:30:35,662 - tdaBroker.py - build_account_position() - ERROR - No strike price found for CRSR
2021-06-07 16:30:35,663 - tdaBroker.py - build_account_position() - ERROR - No strike price found for CRSR_071621C35
2021-06-07 16:30:35,663 - cspByDeltaStrategy.py - check_for_closing_orders() - DEBUG - check_for_closing_orders
2021-06-07 16:30:35,663 - botMediator.py - process_strategies() - INFO - Sleeping...

ERROR - No strike price found for CRSR
ERROR - No strike price found for CRSR_071621C35
ERROR - No strike price found for CRSR
ERROR - No strike price found for CRSR_071621C35
ERROR - No strike price found for CRSR
ERROR - No strike price found for CRSR_071621C35
ERROR - No strike price found for CRSR
ERROR - No strike price found for CRSR_071621C35
ERROR - No strike price found for CRSR
ERROR - No strike price found for CRSR_071621C35
ERROR - No strike price found for CRSR
ERROR - No strike price found for CRSR_071621C35
ERROR - No strike price found for CRSR
ERROR - No strike price found for CRSR_071621C35

To Reproduce
Start the bot where other positions are present.

Expected behavior
This behavior changed in the latest update. If other positions are open for puts, it spawns an error as described above. The bot was previously able to calculate the strike prices with no errors.

Document classes

Follow a pattern similar to abstractStrategy.py... needs research on best practices.

Add a bot kill switch

There are a few approach options. I have a second long-running process that listens for telegram messages. If it gets a "stop" command it updates a flag on disk (database, file, whatever). When my main process runs it checks the flag. Fairly similar to what you're saying.

In general you need a communication channel (telegram, email, whatever) and either actively listen to it OR have pending instructions queue up somewhere that you check periodically.

Fix 55 Maintainability, 2 Style, 1 Complexity issues in BaseTypes\Broker\tdaBroker.py

CodeFactor found multiple issues:

Either all return statements in a function should return an expression, or none of them should.

Attribute 'orders' defined outside init

Catching too general exception Exception

Too many branches (15/12)

Unnecessary parens after 'if' keyword

Variable name "e" doesn't conform to snake_case naming style

Module name "tdaBroker" doesn't conform to snake_case naming style

Too many statements (54/50)

Line too long (152/120)

Line too long (156/120)

Line too long (130/120)

Line too long (133/120)

Line too long (131/120)

Line too long (136/120)

Line too long (137/120)

Line too long (139/120)

Line too long (127/120)

Line too long (128/120)

Line too long (132/120)

Line too long (124/120)

Redefining built-in 'type'

Missing class docstring

Missing module docstring

Complex Method

Bot Crash Issue

Describe the bug
Currently in testing mode, so running XSP instead of SPX:
It is 8:53 PM UTC. The bot seems to have stopped on its own, and this has happened a few times. Bot does tend to reply to commands.

To Reproduce
Modify the SPX to XSP (this should have no impact).
Since the position is XSP, it put an order for 0.05 close after the position was opened. The buy to close log is attached. Once the 0.05 order was placed, I modified the order to 0.03.

Expected behavior
Bot to continue processing, as once the BUY_TO_CLOSE order is placed by the bot, it should not have any impact whether the user goes and manually modifies the order on TDA/TOS.

Log

autotrader.log is as follows (tail end of it).
2021-06-04 13:41:45,161 - tdaBroker.py - place_order() - INFO - Your order being placed is: OrderedDict([('orderStrategyType', 'SINGLE'), ('orderType', 'LIMIT'), ('session', 'NORMAL'), ('duration', 'GOOD_TILL_CANCEL'), ('price', '0.05'), ('orderLegCollection', [{'instruction': 'BUY_TO_CLOSE', 'quantity': 1.0, 'instrument': {'assetType': 'OPTION', 'symbol': 'XSP_060721P413'}}])])
2021-06-04 13:41:45,413 - tdaBroker.py - place_order() - INFO - Order 4485468214 Placed
2021-06-04 13:41:45,413 - botMediator.py - process_strategies() - INFO - Sleeping...
2021-06-04 13:42:12,453 - cspByDeltaStrategy.py - process_strategy() - DEBUG - processstrategy
2021-06-04 13:42:12,454 - cspByDeltaStrategy.py - get_market_session_loop() - DEBUG - get_market_session_loop
2021-06-04 13:42:12,715 - cspByDeltaStrategy.py - process_open_market() - DEBUG - Processing Open-Market
2021-06-04 13:42:12,715 - cspByDeltaStrategy.py - process_expiring_positions() - DEBUG - process_expiring_positions
2021-06-04 13:42:12,715 - cspByDeltaStrategy.py - build_new_order() - DEBUG - build_new_order

Bot was started as nohup python

nohup log as follows: two separate instances of bot crashing and not responding is below.

Grabbing new access token...
Grabbing new access token...
Grabbing new access token...
Traceback (most recent call last):
File "/home/azureuser/LoopTrader/looptrader/main.py", line 39, in
bot.process_strategies()
File "/home/azureuser/LoopTrader/looptrader/basetypes/Mediator/botMediator.py", line 72, in process_strategies
strategy.process_strategy()
File "/home/azureuser/LoopTrader/looptrader/basetypes/Strategy/cspByDeltaStrategy.py", line 102, in process_strategy
self.process_open_market(hours.end, now)
File "/home/azureuser/LoopTrader/looptrader/basetypes/Strategy/cspByDeltaStrategy.py", line 142, in process_open_market
self.place_new_orders_loop()
File "/home/azureuser/LoopTrader/looptrader/basetypes/Strategy/cspByDeltaStrategy.py", line 430, in place_new_orders_loop
neworder = self.build_new_order()
File "/home/azureuser/LoopTrader/looptrader/basetypes/Strategy/cspByDeltaStrategy.py", line 295, in build_new_order
int(position.symbol[-4:])
ValueError: invalid literal for int() with base 10: 'P410'
Traceback (most recent call last):
File "/home/azureuser/LoopTrader/looptrader/main.py", line 39, in
bot.process_strategies()
File "/home/azureuser/LoopTrader/looptrader/basetypes/Mediator/botMediator.py", line 72, in process_strategies
strategy.process_strategy()
File "/home/azureuser/LoopTrader/looptrader/basetypes/Strategy/cspByDeltaStrategy.py", line 102, in process_strategy
self.process_open_market(hours.end, now)
File "/home/azureuser/LoopTrader/looptrader/basetypes/Strategy/cspByDeltaStrategy.py", line 142, in process_open_market
self.place_new_orders_loop()
File "/home/azureuser/LoopTrader/looptrader/basetypes/Strategy/cspByDeltaStrategy.py", line 430, in place_new_orders_loop
neworder = self.build_new_order()
File "/home/azureuser/LoopTrader/looptrader/basetypes/Strategy/cspByDeltaStrategy.py", line 295, in build_new_order
int(position.symbol[-4:])
ValueError: invalid literal for int() with base 10: 'P413'

Add Strangle Strategy

Is your feature request related to a problem? Please describe.
Add support for Strangles.

getenv does not work on a mac

Describe the bug
On MacOS, configured .env file, tried multiple permissions for the .env file, and ran it from shell as well as under virtual environment. It indicates that it is still not able to read the variables from the .env file.

To Reproduce
Create a sample .env file on MacOS and run the scripts as described on the documentation.

Expected behavior
OS independent way of reading .env files.

Desktop (please complete the following information):

  • OS: MacOS
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Fix
Add the dependency for dotenv on the pip file.
from dotenv import load_env
load_dotenv()

Help Command from Telegram bot

Describe the bug
When a help command is sent from telegram, it results in the following error.
telegram.error.BadRequest: Can't parse entities: character '.' is reserved and must be escaped with the preceding ''

To Reproduce
Send /help from telegram

Expected behavior
Send a message about the list of commands as described in:
Welcome to LoopTrader, I'm a Telegram bot here to help you manage your LoopTrader! There are a few things I can do: \r\n\n - Push Notifications will alert you to alerts you setup in your LoopTrader. \r\n - /killswitch will shutdown your LoopTrader\. \r\n - /account will display your latest account details. \r\n - /orders will display your open Orders. \r\n - /positions will show your open Positions\.

Implement Sqlite local db

Should include positions, orders, and strategies.

Positions should have one strategy and one or more orders.

Orders should have one position and one strategy.

Problems to decide on still:

  • how to connect a strategy in code with a database record for a strategy?
  • possible solution is to have a user select strategies from the DB or create new instances of strategies... Telegram?
  • Should strategies be in a key value pair DB for maximum flexibility? Positions and orders seem best suited to traditional table structures.

Help Command

Describe the bug
/account will display your latest account details. does not display any results.

To Reproduce
send /account via telegram

Fix
Change to /balances instead.

Killswitch results in error message related to escape character

def killswitch(self, update: Update, context: CallbackContext):
    """Method to handle the /killswitch command"""
    request = baseRR.SetKillSwitchRequestMessage(True)
    self.mediator.set_kill_switch(request)
    self.reply_text(
        r"Kill switch, flipped. Awaiting confirmation...",
        update.message,
        None,
        ParseMode.MARKDOWN_V2,
    )

The parsemode can to be sent as ParseMode.HTML or escape characters if MARKDOWN_V2 is used.

telegram-python-api-version

You need to specify the telegram-python-api version to 13.15 or earlier or update the version to 20.0 or later in your project.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.