def shared_coin(instance, pid, N, t, broadcast, receive): ''' A dummy version of the Shared Coin :param pid: my id number :param N: the number of parties :param t: the number of byzantine parties :param broadcast: broadcast channel :param receive: receive channel :return: yield values b ''' received = defaultdict(set) outputQueue = defaultdict(lambda: Queue(1)) PK, SKs = getKeys() def _recv(): while True: # New shares for some round r (i, (r, sig)) = receive() assert i in range(N) assert r >= 0 received[r].add((i, serialize(sig))) # After reaching the threshold, compute the output and # make it available locally if len(received[r]) == t + 1: h = PK.hash_message(str((r, instance))) def tmpFunc(r, t): combine_and_verify( h, dict( tuple((t, deserialize1(sig)) for t, sig in received[r])[:t + 1])) outputQueue[r].put(ord(serialize(h)[0]) & 1) # explicitly convert to int Greenlet(tmpFunc, r, t).start() greenletPacker(Greenlet(_recv), 'shared_coin_dummy', (pid, N, t, broadcast, receive)).start() def getCoin(round): broadcast((round, SKs[pid].sign(PK.hash_message(str( (round, instance)))))) # I have to do mapping to 1..l return outputQueue[round].get() return getCoin
def shared_coin(instance, pid, N, t, broadcast, receive): ''' A dummy version of the Shared Coin :param pid: my id number :param N: the number of parties :param t: the number of byzantine parties :param broadcast: broadcast channel :param receive: receive channel :return: yield values b ''' received = defaultdict(set) outputQueue = defaultdict(lambda: Queue(1)) PK, SKs = getKeys() def _recv(): while True: # New shares for some round r (i, (r, sig)) = receive() assert i in range(N) assert r >= 0 received[r].add((i, serialize(sig))) # After reaching the threshold, compute the output and # make it available locally if len(received[r]) == t + 1: h = PK.hash_message(str((r, instance))) def tmpFunc(r, t): combine_and_verify(h, dict(tuple((t, deserialize1(sig)) for t, sig in received[r])[:t+1])) outputQueue[r].put(ord(serialize(h)[0]) & 1) # explicitly convert to int Greenlet( tmpFunc, r, t ).start() greenletPacker(Greenlet(_recv), 'shared_coin_dummy', (pid, N, t, broadcast, receive)).start() def getCoin(round): broadcast((round, SKs[pid].sign(PK.hash_message(str((round,instance)))))) # I have to do mapping to 1..l return outputQueue[round].get() return getCoin
from alpha_vantage.timeseries import TimeSeries import matplotlib.pyplot as plt from utils import getKeys api_key = getKeys()["alpha_vantage_key"] def getIntraDay(ticker: str, interval="1min", full=False): """ Gets intra day data. :param ticker: e.g. TSLA :param interval: 1min, 5min, 15min, 30min, 60min :return: Pandas Dataframe """ ts = TimeSeries(key=api_key, output_format='pandas') data, meta_data = ts.get_intraday(symbol=ticker, interval=interval, outputsize='full') data = data.rename( columns={ "1. open": "Open", "2. high": "High", "3. low": "Low", "4. close": "Close", "5. volume": "Volume" }) return data def main():
from typing import List import requests import json from utils import getKeys td_consumer_key = getKeys()["td_consumer_key"] def getCurrentQuotes(tickers: List): params = {"apikey": td_consumer_key, "symbol": tickers} endpoint = "https://api.tdameritrade.com/v1/marketdata/quotes" page = requests.get(url=endpoint, params=params) content = json.loads(page.content) return content def getPriceHistory(ticker: str, periodType="day", period=1, frequency=1, frequencyType="minute"): """ Returns price history in candles (open, high, low, close). To get back candles for the last two days, and get candles for every minute: periodType="day", period=2, frequency=1, frequencyType="minute".
valid[name] = features print("Train and Valid set loaded") keyWords = utils.load_keyWords() groundTruth = utils.load_truth() print("ground truth loaded") ################ # 3. One example ################ print("STEP 3: Find a keyword in the data set") word = random.choice(keyWords) # word = "i-m-m-e-d-i-a-t-e-l-y" examples = utils.getKeys(word, groundTruth) print(word) print(examples) i = 0 for example in examples: if i < 2: # stored word image image = Image.open("words/" + str(example) + ".png") image.show() # gray scale image image = utils.greyMatrix("words/" + str(example) + ".png") utils.showNpArray(image) # resized image image = utils.resizeArray(image) utils.showNpArray(image)
from utils import getKeys from questrade_api import Questrade from datetime import datetime questrade_token = getKeys()["questrade_token"] def main(): # If using a new token: # q = Questrade(refresh_token=questrade_token) # otherwise... q = Questrade() # First, we need to find the ID of the symbol. id = q.symbols_search(prefix="SPY")["symbols"][0]["symbolId"] # Then we can get some candles. startTime = datetime(year=2020, month=10, day=2, hour=12, minute=0).astimezone().isoformat('T') endTime = datetime(year=2020, month=10, day=2, hour=12, minute=10).astimezone().isoformat('T') candles = q.markets_candles(id, interval='OneMinute', startTime=startTime, endTime=endTime) print("Done!") if __name__ == '__main__': main()
import requests from utils import getKeys tiingo_token = getKeys()["tiingo_token"] def main(): headers = { "Content-Type": "application/json", "Authorization": "Token " + tiingo_token } requestResponse = requests.get("https://api.tiingo.com/iex/SPY/prices?"\ "startDate=2016-12-17&endDate=2016-12-20&resampleFreq=5min", headers=headers) print(requestResponse.json()) if __name__ == "__main__": main()