tamuseanmiller / alpaca-stock-trading-bot

📈 Q-Learning and Sentiment Analysis Stock Trade Bot Powered by Alpaca
GNU General Public License v3.0
42 stars 13 forks source link

I made a run file #6

Closed GitHubEmploy closed 3 years ago

GitHubEmploy commented 3 years ago

Hey, I really like your bot, so I decided to make a run file for it. I made 2, an EvalRunFile, and TrainRunFile. The eval run file is used to run the code, and the train run file is used to train it in a continuous loop. EvalRunFile.py

import os
os.environ['TF_MIN_GPU_MULTIPROCESSOR_COUNT'] = '2'
os.environ['APCA_API_BASE_URL'] = 'https://paper-api.alpaca.markets'
os.environ['APCA_API_KEY_ID'] = 'APIKEY'
os.environ['APCA_API_SECRET_KEY'] = 'SECRETAPIKEY'
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = 'C:/Users/Mohit/PycharmProjects/SuperAIPR/newslstmstockbot/keys.json'
from bs4 import BeautifulSoup
import requests
import os
import time

def findGainingStocks():
    url = 'https://finance.yahoo.com/gainers'
    resp = requests.get(url)
    html = resp.content
    soup = BeautifulSoup(html, 'html.parser')
    tr_tags = soup.find_all('tr')
    td_tags = [tag.find('td') for tag in tr_tags]
    refresh = soup.find_all('meta', attrs={'http-equiv': 'refresh'})
    print(refresh)
    symbols = [tag.find('a').text for tag in td_tags if
               tag != None and '=' not in tag.find('a').text and '^' not in tag.find('a').text]
    # for s in symbols:
    # print('kool')
    global newsymbols
    newsymbols = symbols[0]
    return newsymbols

print('eval wth "Flair Custom Module", or eval with "Natural Language Understanding by Google"? Answer 1 or 2')
var = int(input())
print('With AI an recomended stock, or your own stock? Answer 1 or 2')
varvar = int(input())
if varvar == 2:
    print('What stock would you like to use?, (TYPE ONLY STOCK NAME, NO SPACES!)')
    varvarvar = str(input())
if var == 1:
    if varvar == 1:
        findGainingStocks()
        print('Trading stock', newsymbols)
        time.sleep(5)
        os.system(
            'python eval.py test --window-size=10 --model-name=model_AMD_alpha --run-bot=y --stock-name=' + newsymbols + ' --debug')
    if varvar == 2:
        os.system(
            'python eval.py test --window-size=10 --model-name=model_AMD_alpha --run-bot=y --stock-name=' + varvarvar + ' --debug')
if var == 2:
    if varvar == 1:
        findGainingStocks()
        print('Trading stock', newsymbols)
        time.sleep(5)
        os.system(
            'python eval.py test --window-size=10 --model-name=model_AMD_alpha --run-bot=y --stock-name=' + newsymbols + ' --natural-lang --debug')
    if varvar == 2:
        os.system(
            'python eval.py test --window-size=10 --model-name=model_AMD_alpha --run-bot=y --stock-name=' + varvarvar + ' --natural-lang --debug')

Now TrainRunFile.py

import os
os.environ['APCA_API_BASE_URL'] = 'https://paper-api.alpaca.markets'
os.environ['APCA_API_KEY_ID'] = 'KEYID'
os.environ['APCA_API_SECRET_KEY'] = 'SECRETKEYID'
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = 'C:/Users/Mohit/PycharmProjects/SuperAIPR/newslstmstockbot/keys.json'
varvar = 0
while True:
    print('Loop has been completed', varvar,'time(s)')
    os.system('python train.py')

This isn't really an issue, just more of an improvement.

GitHubEmploy commented 3 years ago

I was hoping you could give me permission to upload files so I may add these run files to your code.

tamuseanmiller commented 3 years ago

I love it! Just submit a pull request with the files and I'll take a closer look.

GitHubEmploy commented 3 years ago

Hmmm... I'm kinda new to pull requests, and I am unsure how to do one. I did one to the best of my ability, tho tell me if I did anything wrong.

tamuseanmiller commented 3 years ago

I don't see a PR made, check this out for reference to learn how to create a pull request.

Just make sure to have it compare to the master branch and not the integration branch

GitHubEmploy commented 3 years ago

Ah, I see. But then I would need access to a version to first add my files and then push it to the repository.

tamuseanmiller commented 3 years ago

Ah, I see. But then I would need access to a version to first add my files and then push it to the repository.

Just fork the repo to your own account.

GitHubEmploy commented 3 years ago

Okay, I think I made one properly to the best of my ability, due to that, I think that I will close this now.