Skip to main content

Polygon API Access

Project description

Polygon API Access

A library for accessing the POLYGON API securely without exposing the Polygon API key.

Installation

pip install polygon-api-access

Get started

How to securely access the Polygon API without exposing the Polygon API key.

First import class portfolio and then use the library Polygon API Access to instantiate it.

Example provided while using the access method to display results for different currencies.

from polygon_api_access import PolygonAPIAccess
import os

class portfolio(object):
    def __init__(self,from_,to):
        # Initialize the 'From' currency amont to 1
        self.amount = 1
        self.curr2 = 0
        self.from_ = from_
        self.to = to
        # We want to keep track of state, to see what our next trade should be
        self.Prev_Action_was_Buy = False
    
    # This defines a function to buy the 'To' currency. It will always buy the max amount, in whole number
    # increments
    def buy_curr(self, price):
        if self.amount >= 1:
            num_to_buy = floor(self.amount)
            self.amount -= num_to_buy
            self.Prev_Action_was_Buy = True
            self.curr2 += num_to_buy*price
            print("Bought %d worth of the target currency (%s). Our current profits and losses in the original currency (%s) are: %f." % (num_to_buy,self.to,self.from_,(self.amount-1)))
        else:
            print("There was not enough of the original currency (%s) to make another buy." % self.from_)
    # This defines a function to sell the 'To' currency. It will always sell the max amount, in a whole number
    # increments
    def sell_curr(self, price):
        if self.curr2 >= 1:
            num_to_sell = floor(self.curr2)
            self.amount += num_to_sell * (1/price)
            self.Prev_Action_was_Buy = False
            self.curr2 -= num_to_sell
            print("Sold %d worth of the target currency (%s). Our current profits and losses in the original currency (%s) are: %f." % (num_to_sell,self.to,self.from_,(self.amount-1)))
        else:
            print("There was not enough of the target currency (%s) to make another sell." % self.to)   

polygonAPIAccess = PolygonAPIAccess()

currency_pairs = [["AUD","USD",[],portfolio("AUD","USD")]]

polygonAPIAccess = PolygonAPIAccess(os.getcwd(), "final.db")

print(polygonAPIAccess.access(currency_pairs))

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

polygon-api-access-0.1.11.tar.gz (5.5 kB view details)

Uploaded Source

File details

Details for the file polygon-api-access-0.1.11.tar.gz.

File metadata

  • Download URL: polygon-api-access-0.1.11.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.7.1

File hashes

Hashes for polygon-api-access-0.1.11.tar.gz
Algorithm Hash digest
SHA256 7045280a07530cc730d1bacc7ad0f1d6ae55220887ea0812a30ffa6fb68b62bc
MD5 f08f21837397b326907c5027a810589c
BLAKE2b-256 00d9bd2d6890f2411cb194869307d25fc47e2d141114700aef9c32341d73bd07

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page