Giter VIP home page Giter VIP logo

Comments (16)

shlomiku avatar shlomiku commented on July 28, 2024 3

we will be releasing a fix soon (already in this PR if you want to try it out before we do: #24)

from alpaca-backtrader-api.

Nicholas-Schaub avatar Nicholas-Schaub commented on July 28, 2024 2

Hey all. Thought I would post my solution. I tried to make minimal changes to the code to get it working. I made 2 changes:

  1. In the trade API, I changed the polygon rest.py so that the method historic_agg is just a pass through to historic_agg_v2.
  2. I changed one line in alpacastore.py so that it always looks for a timestamp in the record dictionary.

I set it up so that every call to historic_agg still throws a deprecation warning so that people know that it is just getting passed through to historic_agg_v2.

My forks are here if you want to take a look at what/how I did it. I think it needs more work to be generalized, but the example runs now.

https://github.com/Nicholas-Schaub/alpaca-trade-api-python
https://github.com/Nicholas-Schaub/alpaca-backtrader-api

from alpaca-backtrader-api.

Nicholas-Schaub avatar Nicholas-Schaub commented on July 28, 2024 2

Sure. The way I did it was:

  1. Clone each repo
  2. pip install path/to/clone/directory (or pip3 depending on how you have your environment set up)

Note: This should uninstall what you currently have installed and install the cloned repo.

from alpaca-backtrader-api.

wstewarttennes avatar wstewarttennes commented on July 28, 2024 1

Oh sweet, thanks! I'll add that in. I haven't studied the Alpaca code very much so not sure what else needs to be done...just wanted to get it working asap.

from alpaca-backtrader-api.

cole-seph avatar cole-seph commented on July 28, 2024 1

@shlomikushchi for what it's worth, receiving the following errors when running your commit:
`RuntimeError: There is no current event loop in thread 'Thread-2'.

500 Server Error: Internal Server Error for url: https://api.polygon.io/v2/aggs/ticker/SPY/range/1/day/2015-01-01T00:00:00/2020-03-29T03:29:42.791724?unadjusted=False&apiKey=yaddayadda`
Pretty sure I've set everything correctly. I can run @Nicholas-Schaub 's forks just fine.

from alpaca-backtrader-api.

shlomiku avatar shlomiku commented on July 28, 2024 1

new version (v0.5) is on pypi and you could install it via pip. if there are no new problems with this issue, I will consider it resolved and close the issue. let me know if something is still not working.

from alpaca-backtrader-api.

AlienJazzCat avatar AlienJazzCat commented on July 28, 2024

Yep i was about to submit this as well..

alpacastore.py calls this: (comment is my own)

# needs to be v2
response = self.oapi.polygon.historic_agg(granularity,
              dataname,
              _from=start_dt,
              to=end_dt)

It should be calling historic_agg_v2. I'm tinkering with it, but will take a bit since the params and responses are different

from alpaca-backtrader-api.

wstewarttennes avatar wstewarttennes commented on July 28, 2024

I did the following and it's working (although few issues with some assets, not sure if related):

alpacastore.py
395: field = 'timestamp'
344: end_dt = dtend.strftime('%Y-%m-%d')
353: start_dt = dtkwargs['start'].strftime('%Y-%m-%d')

355: response = self.oapi.polygon.historic_agg_v2(dataname, 1,
granularity,
_from=start_dt,
to=end_dt)

I also reached out to the Polygon team, who said they would talk to the Alpaca team about it.

from alpaca-backtrader-api.

AlienJazzCat avatar AlienJazzCat commented on July 28, 2024

Nice..! Could try using the compression parameter instead of the 1 there.. pretty sure that's the typical backtrader variable for numeric portion of aggregation period

from alpaca-backtrader-api.

AlienJazzCat avatar AlienJazzCat commented on July 28, 2024

thank you too.. your date formatting saved me time :)

At a quick glance, it appears to be working, but i haven't had a chance to really see what differences there are in the 2 response types. But everything looks pretty sane with these changes

from alpaca-backtrader-api.

wstewarttennes avatar wstewarttennes commented on July 28, 2024

Glad I could help!

from alpaca-backtrader-api.

cole-seph avatar cole-seph commented on July 28, 2024

@Nicholas-Schaub sorry but could you point me in the direction of how I'd call these forks locally when running backtrader-alpaca scripts?
I tried something like this: pip3 install git+https://github.com/your-repo.git but am still getting 404's when running code
I know this is like Python 101..

from alpaca-backtrader-api.

jholland1 avatar jholland1 commented on July 28, 2024

Echoing @cole-seph, I also get the 500 Server Error:

500 Server Error: Internal Server Error for url: https://api.polygon.io/v2/aggs/ticker/VOO/range/1/minute/2020-02-20T00:00:00/2020-03-30T00:00:00?unadjusted=False&apiKey=##############

If I paste this into a browser I get the response:
{"error":"Could not parse from date. Use YYYY-MM-DD or Unix MS Timestamps","status":"ERROR"}

If I delete the T and the zeros manually in the url in the browser I get a response with data as expected:
https://api.polygon.io/v2/aggs/ticker/VOO/range/1/minute/2020-02-20/2020-03-30?unadjusted=False&apiKey=##############

I haven't been able to get @Nicholas-Schaub 's fork to work yet either but I will try and investigate more later.

from alpaca-backtrader-api.

wstewarttennes avatar wstewarttennes commented on July 28, 2024

I had to do the following to fix the above:
in alpacastore.py
344: end_dt = dtend.strftime('%Y-%m-%d')
353: start_dt = dtkwargs['start'].strftime('%Y-%m-%d')

seemed to work

from alpaca-backtrader-api.

jholland1 avatar jholland1 commented on July 28, 2024

@wstewarttennes Thanks! Think that has me working for now, our line numbers were slightly different but I think it's working. Appreciate the help everyone!

from alpaca-backtrader-api.

shlomiku avatar shlomiku commented on July 28, 2024

ok, I have fixed the issues as you pointed out. code is now in the master branch. you could pull it from there. let me know if there are still any issues.
new pypi version will be released soon

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.