import error: cannot import name 'macd'
Opened this issue · 15 comments
Hey Jazz,
I ran into the same issue but found an article that said ta had changed is location
Use this at the top of your code instead:
from ta.trend import macd
sickk im gonna try that now, did you get your bot working?
I believe so, I've gotten to the point where:
123/124 124/124 Success. Watching 124 symbols. 2021-01-29 14:53:15,515 connected to: wss://paper-api.alpaca.markets/stream 2021-01-29 14:53:15,558 connected to: wss://socket.polygon.io/stocks
Just unsure if it's going to execute at all.
Hey @Jazz905 That error has to do with the newer V2 API. To save you some time you will need to change it to this:
While I would love to give you my complete code, I did alter a few things that I wish to gatekeep but these connection parts I am happy to help with.
for symbol in symbols: minute_history[symbol] = api.polygon.historic_agg_v2( timespan="minute", symbol='symbol', limit='1000', multiplier='1', _from='2021-01-01', to='2021-01-28' ).df
Also, you can close this issue too as it's been resolved.
no worries nick i understand,
i solved that one now im getting a cannot set a row with mismatched columns errorsm
btw is your trading now
Can you submit the full error for me to see?
It made a trade haha, so just seeing how it works throughout the day, my guess is there might be still some outdated parameters to go through. Trying to resurrect this repo, hopefully, the original owners see that.
i got it to work but now its stuck at watching 198 symbols.....
here my code;
import alpaca_trade_api as tradeapi
import requests
import time
from ta.trend import macd
import numpy as np
from datetime import datetime, timedelta
from pytz import timezone
Replace these with your API connection info from the dashboard
base_url = 'https://paper-api.alpaca.markets'
api_key_id = 'PKB7P2ZGYIY3M0RJ1WR6'
api_secret = 'u0BExec64UtD4dBrsxITGd5fS4fKfsnbwwNEHoLB'
api = tradeapi.REST(
base_url=base_url,
key_id=api_key_id,
secret_key=api_secret
)
session = requests.session()
We only consider stocks with per-share prices inside this range
min_share_price = 2.0
max_share_price = 13.0
Minimum previous-day dollar volume for a stock we might consider
min_last_dv = 500000
Stop limit to default to
default_stop = .95
How much of our portfolio to allocate to any one position
risk = 0.001
#add date to imports
from datetime import date, datetime, timedelta
def get_1000m_history_data(symbols):
print('Getting historical data...')
minute_history = {}
c = 0
today = date.today()
yesterday = date.today() - timedelta(days=1)
for symbol in symbols:
minute_history[symbol] = api.polygon.historic_agg_v2(
timespan="minute", symbol=symbol, limit=1000, multiplier=1, _from=yesterday.strftime("%Y-%m-%d"), to=today.strftime("%Y-%m-%d")
).df
if 'vwap' in minute_history[symbol]:
minute_history[symbol].drop('vwap', axis=1, inplace=True)
c += 1
print('{}/{}'.format(c, len(symbols)))
print('Success.')
return minute_history
def get_tickers():
print('Getting current ticker data...')
tickers = api.polygon.all_tickers()
Seems like we are stuck in the spot, curious if we can get it working, atleast the base algo working.
maybe none of the stocks are hitting the rules setup for trading?
i see the watching count going down, how do i change it to watch more stocks? i want to cover tsx nyse and nasdaq
is your code continually looping and adjusting?
Mine just runs through one and then sits at watching X symbols
@Jazz905 how you do today? Does your python script show you data throughout the whole day as it is running?
hey nick, no man mine was just stuck at watching stock... for like hrs
i did notice the stock count go down from 128 to like 100 after a few hrs, but on alpaca i dont see any trades being made, how did you do?
i might have to use blueshift on alpaca to try other python scripts
I still want to use this strategy but I think it needs more configuring then the template has. If I come across anything I'll be sure to post it.