Git Product home page Git Product logo

public-invest-api's People

Contributors

cfomodz avatar deepsource-autofix[bot] avatar drcrinkle avatar nelsondane avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

public-invest-api's Issues

Multi login

So I have 2 py files and 1 is where I have my account so I made my wife an account and when I go to the api and setup a py for her since its in the same laptop it is saying that

{"code":null,"message":"Invalid credentials."}
Traceback (most recent call last):
File "C:\Users\thesy\Documents\Python\Public\public2.py", line 4, in
public.login(
File "C:\Users\thesy\AppData\Local\Programs\Python\Python312\Lib\site-packages\public_invest_api\public.py", line 80, in login
raise Exception("Login failed, check credentials")
Exception: Login failed, check credentials

This is my code right now ( i took off the login info)

import sys
import yfinance as yf
from public_invest_api import Public

Function to get the current price of a stock using yfinance

def get_current_price(stock_symbol):
stock_data = yf.Ticker(stock_symbol)
current_price = stock_data.history(period="1d")["Close"].iloc[-1]
return current_price

public = Public()
public.login(
username='@gmail.com',
password='',
wait_for_2fa=True # When logging in for the first time, you need to wait for the SMS code
)

Ask whether to buy or sell

while True:
action = input("Enter '1' to BUY or '2' to SELL: ")
if action == '1':
action = 'BUY'
break
elif action == '2':
action = 'SELL'
break
else:
print("Invalid input. Please enter '1' to BUY or '2' to SELL.")

Assuming you have user input for symbol and quantity

stock_symbol = input("Enter the stock ticker: ")
quantity = int(input("Enter the quantity: "))

Get the current price of the stock

current_price = get_current_price(stock_symbol)

Adjust price by rounding up and adding 1 cent

current_price += 0.001
current_price = round(current_price, 2)

Place order

order = public.place_order(
symbol=stock_symbol,
quantity=quantity,
side=action,
order_type='LIMIT',
limit_price=current_price,
time_in_force='DAY', # 'GTC' or 'IOC' or 'FOK'
is_dry_run=False, # If True, it will not actually place the order
tip=0 # The amount to tip Public.com
)

print(order)

Utils file

Are you intentionally trying to not have a utils.py or some other sort of collection of shortcut/pattern functions and instead leaving it up to each person to craft what they need?

I don't mind cleaning mine up and committing it for you to consider, I just didn't want to waste the time if it's intentional; like maybe if you didn't want it to be 'too easy' for someone to stumble into yolo'ing SPY puts.

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.