Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
NelsonDane committed Feb 16, 2024
2 parents eec909c + 8ff00a0 commit 7d4153c
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 20 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/docker-build-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ on:

jobs:
call-workflow-dockerhub-build-push:
uses: NelsonDane/DockerHub-Actions/.github/workflows/dockerhub_build_push.yml@main
uses: NelsonDane/Custom-GitHub-Actions/.github/workflows/dockerhub-build-push.yml@e3876788a573bfb35bac32593c4075b87c37e774
with:
dockerhub_repo_name: auto-rsa
image_name: auto-rsa
image_tag: ${{ github.ref_name == 'main' && 'latest' || startsWith(github.ref_name, 'develop') && github.ref_name }}
should_push: ${{ github.ref_name == 'main' || startsWith(github.ref_name, 'develop') }}
platforms: linux/amd64,linux/arm64
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dockerhub-description.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:

jobs:
call-dockerhub-action:
uses: NelsonDane/DockerHub-Actions/.github/workflows/dockerhub-description.yml@main
uses: NelsonDane/Custom-GitHub-Actions/.github/workflows/dockerhub-description.yml@e3876788a573bfb35bac32593c4075b87c37e774
with:
dockerhub_repo_name: auto-rsa
secrets:
Expand Down
5 changes: 4 additions & 1 deletion firstradeAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ def firstrade_init(FIRSTRADE_EXTERNAL=None):
try:
account = account.split(":")
firstrade = ft_account.FTSession(
username=account[0], password=account[1], pin=account[2]
username=account[0],
password=account[1],
pin=account[2],
profile_path="./creds/",
)
account_info = ft_account.FTAccountData(firstrade)
print("Logged in to Firstrade!")
Expand Down
9 changes: 5 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
asyncio==3.4.3
discord.py==2.3.2
firstrade==0.0.12
GitPython==3.1.41
firstrade==0.0.14
GitPython==3.1.42
pyotp==2.9.0
python-dotenv==1.0.1
requests==2.31.0
-e git+https://github.com/NelsonDane/robin_stocks.git@f490a2eb0d5fc53afc93e077b3ea2a555124e105#egg=robin-stocks
schwab-api==0.3.9
schwab-api==0.3.10
selenium==4.17.2
tastytrade==6.6
setuptools==69.1.0
tastytrade==6.7
webdriver-manager==4.0.1
33 changes: 21 additions & 12 deletions tastyAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
OrderType,
PriceEffect,
)
from tastytrade.streamer import DXFeedStreamer
from tastytrade.streamer import DXLinkStreamer
from tastytrade.utils import TastytradeError

from helperAPI import Brokerage, maskString, printAndDiscord, printHoldings, stockOrder
Expand Down Expand Up @@ -136,10 +136,16 @@ async def tastytrade_execute(tt_o: Brokerage, orderObj: stockOrder, loop=None):
new_order = order_setup(
obj, order_type, stock_price, s, orderObj.get_amount()
)
placed_order = acct.place_order(
obj, new_order, dry_run=orderObj.get_dry()
)
order_status = placed_order.order.status.value
try:
placed_order = acct.place_order(
obj, new_order, dry_run=orderObj.get_dry()
)
order_status = placed_order.order.status.value
except Exception as e:
print(f"Error placing order: {e}")
if "preflight_check_failure" in str(e):
raise TastytradeError(e)
order_status = "Rejected"
# Check order status
if order_status in ["Received", "Routed"]:
message = f"{key} {print_account}: {orderObj.get_action()} {orderObj.get_amount()} of {s} Order: {placed_order.order.id} Status: {order_status}"
Expand All @@ -148,26 +154,28 @@ async def tastytrade_execute(tt_o: Brokerage, orderObj: stockOrder, loop=None):
printAndDiscord(message, loop=loop)
elif order_status == "Rejected":
# Retry with limit order
streamer = await DXFeedStreamer.create(obj)
stock_limit = await streamer.oneshot(EventType.PROFILE, [s])
stock_quote = await streamer.oneshot(EventType.QUOTE, [s])
streamer = await DXLinkStreamer.create(obj)
stock_limit = await streamer.subscribe(EventType.PROFILE, [s])
stock_quote = await streamer.subscribe(EventType.QUOTE, [s])
stock_limit = await streamer.get_event(EventType.PROFILE)
stock_quote = await streamer.get_event(EventType.QUOTE)
printAndDiscord(
f"{key} {print_account} Error: {order_status} Trying Limit order...",
loop=loop,
)
# Get limit price
if orderObj.get_action() == "buy":
stock_limit = D(stock_limit[0].highLimitPrice)
stock_limit = D(stock_limit.highLimitPrice)
stock_price = (
D(stock_quote[0].askPrice)
D(stock_quote.askPrice)
if stock_limit.is_nan()
else stock_limit
)
order_type = ["Market", "Debit", "Buy to Open"]
elif orderObj.get_action() == "sell":
stock_limit = D(stock_limit[0].lowLimitPrice)
stock_limit = D(stock_limit.lowLimitPrice)
stock_price = (
D(stock_quote[0].bidPrice)
D(stock_quote.bidPrice)
if stock_limit.is_nan()
else stock_limit
)
Expand All @@ -194,6 +202,7 @@ async def tastytrade_execute(tt_o: Brokerage, orderObj: stockOrder, loop=None):
)
except (TastytradeError, KeyError) as te:
printAndDiscord(f"{key} {print_account}: Error: {te}", loop=loop)
continue


def tastytrade_transaction(tt: Brokerage, orderObj: stockOrder, loop=None):
Expand Down

0 comments on commit 7d4153c

Please sign in to comment.