def get_action(req_body): # login if email and password are provided email, password = (req_body.get('email', None), req_body.get('password', None)) if email is not None and password is not None: client = ita.Account(email, password) # set default values if not specified and enums if (req_body['function'] == 'trade' or req_body['function'] == 'trade_option'): req_body['orderType'] = { 'buy': ita.Action.buy, 'sell': ita.Action.sell, 'short': ita.Action.short, 'cover': ita.Action.cover }[req_body['orderType']] req_body['priceType'] = req_body.get('priceType', 'Market') try: req_body['price'] = float(req_body['price']) except KeyError: req_body['price'] = False req_body['duration'] = { 'day_order': ita.Duration.day_order, 'good_cancel': ita.Duration.good_cancel }[req_body.get('duration', 'good_cancel')] # return closure for function being called return { 'get_quote': lambda: ita.get_quote(req_body['symbol']), 'get_portfolio_status': lambda: client.get_portfolio_status(), 'get_current_securities': lambda: client.get_current_securities(), 'get_open_trades': lambda: client.get_open_trades(), 'trade': lambda: (client.trade(req_body['symbol'], req_body['orderType'], int(req_body['quantity']), req_body['priceType'], req_body['price'], req_body['duration'])), 'trade_option': lambda: (client.trade_option( req_body['symbol'], req_body['optionType'], float(req_body['strikePrice']), int(req_body['expire_date']), int(req_body['quantity']), req_body['priceType'], req_body[ 'price'], req_body['duration'])) }[req_body['function']]
def felix(): client = ita.Account(request.json['email'], request.json['password']) shares = requests.get("http://yolo-on-fannie-mae.herokuapp.com/shares") if not shares.json(): client.trade("AMZN", ita.Action.buy, random.randint(1, 100)) else: tickers = [] for share in shares.json(): tickers.append(share['ticker']) buy_share = random.choice(tickers) client.trade(str(buy_share), ita.Action.buy, random.randint(1, 100)) return "show me da whey"
def alext(): client = ita.Account(str(request.json['email']), str(request.json['password'])) shares = requests.get("http://yolo-on-fannie-mae.herokuapp.com/shares") if not shares.json(): client.trade("SNAP", ita.Action.buy, random.randint(1, 100)) else: tickers = [] for share in shares.json(): tickers.append(share['ticker']) buy_share = random.choice(tickers) client.trade(str(buy_share), ita.Action.buy, random.randint(1, 100)) return "what is the website for amazon.ca"
#w[w['CODE'] == 'RSO'].loc[:,'LVL':'C'] # # if entries_file != '': try: long_entries = pd.read_csv(entries_file) except: print("E-File parsing error") sys.exit(2) else: print("No entries file specified!") sys.exit(3) password = getpass.getpass(prompt='Investopedia account password:'******'Logging in.....') client = ita.Account("*****@*****.**", password) PF_state = client.get_portfolio_status() portfolio = client.get_current_securities() PF = PortfolioMetrics() g_alloc = PF_state.account_val * max_value r_alloc = {} open_pos = {} actual_orders = [] total_exposed = 0 print("Initial alloc {:.2f}".format(g_alloc)) print("Total order to place {0}".format(len(long_entries)))
from InvestopediaApi import ita client = ita.Account("*****@*****.**", "8]ev}6-xgW7%") print(client.get_open_trades()) #print(client.get_current_securities()) #client.trade("GOOG", ita.Action.buy, 10) #client.trade("MSFT", ita.Action.sell, 9) #client.trade("TSLA", ita.Action.short, 8) #client.trade("CMI", ita.Action.cover, 5)
#!/usr/bin/env python import zipline from zipline.api import order, order_value, order_percent, record, symbol from datetime import datetime from threading import Timer import pandas as pd import quandl quandl.ApiConfig.api_key = "DEFAULT_KEY" from InvestopediaApi import ita client = ita.Account("*****@*****.**", "default password") import nlp def refresh(): buying_power = ita.Account.get_portfolio_status['buying_power'] for algo in algos: if shouldAct(algo['condition']['logic']): ticker = algo['action']['ticker'] target_change = algo['action']['amount'] unit = algo['action']['amount_unit'] # current_share_count current_quantity = client.get_current_securities[ticker].quanity price = ita.get_quote(ticker) long = algo['action']['position'] == 'long' if target_change > 0: if long: if current_amount < 0:
from InvestopediaApi import ita #Everything done through the Account client = ita.Account('*****@*****.**', '789kevv789') status = client.get_portfolio_status() print(status) # Important function: # ita.Account.get_portfolio_status # ita.Account.get_current_securities # ita.Account.get_open_trades # ita.get_quote("Stringticker") # Trading: # client.trade("ticker", action, INTamount)
def test_notify_invalid_login(self): with self.assertRaises(ita.LoginError) as context: ita.Account(test_username, 'invalidpassword') self.assertTrue("Login Error: Invalid Username or Password" in str( context.exception))
def test_valid_login(self): client = ita.Account(test_username, test_password) self.assertTrue(client.logged_in)