Giter VIP home page Giter VIP logo

Comments (14)

jtbales avatar jtbales commented on July 28, 2024 1

The comment with the log date of May 27 did not.

But the message with log date of May 28 DID as you can see from this Heroku build log from that day.

...
-----> Installing requirements with pip
Collecting git+https://github.com/alpacahq/alpaca-backtrader-api (from -r /tmp/build_608a0f8986b36a309c9a5ecf5f4d9061/requirements.txt (line 7))
  Cloning https://github.com/alpacahq/alpaca-backtrader-api to /tmp/pip-req-build-7xz30v8i
  Running command git clone -q https://github.com/alpacahq/alpaca-backtrader-api /tmp/pip-req-build-7xz30v8i
...

I haven't seen this error in a while. I will response ASAP if I get it again. I've added a lot more logging and I run the app every market day now.

from alpaca-backtrader-api.

shlomiku avatar shlomiku commented on July 28, 2024 1

a fix for this issue is available in the master branch.
install it like this: pip install -U git+https://github.com/alpacahq/alpaca-backtrader-api
let me know id this still happens

from alpaca-backtrader-api.

jtbales avatar jtbales commented on July 28, 2024 1

Just tested it and that did the trick, thanks

from alpaca-backtrader-api.

jtbales avatar jtbales commented on July 28, 2024

This happened today as well and I updated using the lasted from git+https://github.com/alpacahq/alpaca-backtrader-api

from alpaca-backtrader-api.

shlomiku avatar shlomiku commented on July 28, 2024

does this happen often? do you have a piece of code I could execute and reproduce it?

from alpaca-backtrader-api.

jtbales avatar jtbales commented on July 28, 2024

I tried the new branch and it still happened.

It seems to happen sometimes after I execute an order.

Here's the code, just a bracket order

if self.is_within_trading_period and (not self.p.live or realtime_tick): 
    for ticker in self.getdatanames(): 
        if self.pivots.lines.has_retracement_target and self.signal_2to1_target and self.new_high:  
            profit_target = self.pivots.lines.retracement_target_upper * 1.0 
            buy_price = (profit_target - self.data.close) * 0.005 + self.data.close
            stop_loss = self.pivots.lines.retracement_target_lower * 1.0 
            brackets = self.buy_bracket(limitprice=profit_target, price=buy_price, stopprice=stop_loss)

            if self.p.live:
                print(f"buy_bracket - limitprice={profit_target:.3f}, price={buy_price:.3f}, stopprice={stop_loss:.3f}")

from alpaca-backtrader-api.

jtbales avatar jtbales commented on July 28, 2024

Sometimes it happens when simply starting the app like this

May 28 09:49:03 heroku/worker.1 Restarting
May 28 09:49:03 heroku/worker.1 State changed from up to starting
May 28 09:49:04 heroku/worker.1 Stopping all processes with SIGTERM
May 28 09:49:05 heroku/worker.1 Process exited with status 143
May 28 09:49:11 heroku/worker.1 Starting process with command `python3 ./main.py`
May 28 09:49:12 heroku/worker.1 State changed from starting to up
May 28 09:49:18 app/worker.1 Starting Portfolio Value: 99966.72
May 28 09:49:18 app/worker.1 Starting Cash Value: 0.00
May 28 09:49:30 app/worker.1 Exception in thread Thread-1:
May 28 09:49:30 app/worker.1 Traceback (most recent call last):
May 28 09:49:30 app/worker.1   File "/app/.heroku/python/lib/python3.6/threading.py", line 916, in _bootstrap_inner
May 28 09:49:30 app/worker.1     self.run()
May 28 09:49:30 app/worker.1   File "/app/.heroku/python/lib/python3.6/threading.py", line 864, in run
May 28 09:49:30 app/worker.1     self._target(*self._args, **self._kwargs)
May 28 09:49:30 app/worker.1   File "/app/.heroku/python/lib/python3.6/site-packages/alpaca_backtrader_api/alpacastore.py", line 328, in _t_streaming_listener
May 28 09:49:30 app/worker.1     self._transaction(trans)
May 28 09:49:30 app/worker.1   File "/app/.heroku/python/lib/python3.6/site-packages/alpaca_backtrader_api/alpacastore.py", line 655, in _transaction
May 28 09:49:30 app/worker.1     oid = trans['id']
May 28 09:49:30 app/worker.1 TypeError: 'Entity' object is not subscriptable

from alpaca-backtrader-api.

shlomiku avatar shlomiku commented on July 28, 2024

so the bracket order support was added 4 days ago. are you running with the latest code?

from alpaca-backtrader-api.

jtbales avatar jtbales commented on July 28, 2024

I got the error a couple more times today.

Here's the best example. Executed a close order for 1 share on AMRH. Submitted order, Accepted order (first time I've actually seen an Accepted order even though they fill), then it errors.

Jun 02 10:18:05 ('Closing: AMRH') 
Jun 02 10:18:05 ('notify_order Status: Submitted, Ref 2',)
Jun 02 10:18:05 ('notify_order Status: Accepted, Ref 2',)
Jun 02 10:18:06 Exception in thread Thread-1:
Jun 02 10:18:06 Traceback (most recent call last):
Jun 02 10:18:06   File "/app/.heroku/python/lib/python3.7/threading.py", line 926, in _bootstrap_inner
Jun 02 10:18:06     self.run()
Jun 02 10:18:06   File "/app/.heroku/python/lib/python3.7/threading.py", line 870, in run
Jun 02 10:18:06     self._target(*self._args, **self._kwargs)
Jun 02 10:18:06   File "/app/.heroku/python/lib/python3.7/site-packages/alpaca_backtrader_api/alpacastore.py", line 328, in _t_streaming_listener
Jun 02 10:18:06     self._transaction(trans)
Jun 02 10:18:06   File "/app/.heroku/python/lib/python3.7/site-packages/alpaca_backtrader_api/alpacastore.py", line 655, in _transaction
Jun 02 10:18:06     oid = trans['id']
Jun 02 10:18:06 TypeError: 'Entity' object is not subscriptable

The closing code is simple

            for ticker in self.getdatanames(): 
                if self.getpositionbyname(ticker):
                    self.print_live(f"Closing: {ticker}", when)
                    self.close(data=ticker)

Looking at my Alpaca feed it successfully closed. But subscribing to updates on the order fails.

This may be the cause of the oddities in this other issue https://github.com/alpacahq/alpaca-backtrader-api/issues/57

from alpaca-backtrader-api.

jtbales avatar jtbales commented on July 28, 2024

I switched to just doing simple buy, sell, and close orders instead of bracket orders and saw those errors today.

from alpaca-backtrader-api.

shlomiku avatar shlomiku commented on July 28, 2024

give me an example of what you did, I will try to execute it locally

from alpaca-backtrader-api.

jtbales avatar jtbales commented on July 28, 2024

It's pretty simple in this case, I suppose you could replicate it by buying on Alpaca manually, then in your code, simply check if you have a position and if you do, close the position (like the code above).

Keep doing that till you see an error.

from alpaca-backtrader-api.

jtbales avatar jtbales commented on July 28, 2024
import backtrader as bt

class JustClose(bt.Strategy):
    def next(self):
        for ticker in self.getdatanames():
            if self.getpositionbyname(ticker):
                print(f"Closing: {ticker}")

                self.close(data=ticker)
            else:
                print(f"Nothing to close for: {ticker}")

Quickly returns

Account Status: ACTIVE
Getting Data for SAVA
Starting Portfolio Value: 99995.77
Starting Cash Value: 0.00
Closing: SAVA
Closing: SAVA
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 926, in _bootstrap_inner
    self.run()
  File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.7/site-packages/alpaca_backtrader_api/alpacastore.py", line 328, in _t_streaming_listener
    self._transaction(trans)
  File "/usr/local/lib/python3.7/site-packages/alpaca_backtrader_api/alpacastore.py", line 655, in _transaction
    oid = trans['id']
TypeError: 'Entity' object is not subscriptable

Closing: SAVA
Closing: SAVA
Closing: SAVA
Closing: SAVA
Closing: SAVA
Closing: SAVA

from alpaca-backtrader-api.

shlomiku avatar shlomiku commented on July 28, 2024

great, let's close this issue

from alpaca-backtrader-api.

Related Issues (20)

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.