Added api structure calls for Flux and Presearch

This commit is contained in:
2023-05-18 21:39:15 -04:00
parent 5453ef1041
commit c1af0c7c89
5 changed files with 78 additions and 0 deletions

5
.gitignore vendored Normal file
View File

@@ -0,0 +1,5 @@
#ignore the .env
*.env
#and that csv
*.csv

0
__init__.py Normal file
View File

Binary file not shown.

33
api.py Normal file
View File

@@ -0,0 +1,33 @@
from flask import Flask
from flask_restful import Resource, Api, reqparse
import pandas as pd
import ast
from re import search
import sys
sys.path.append("C:/Users/jerick/Documents/Development/databroker")
from getPrices import fluxPrice, prePrice
app = Flask(__name__)
api = Api(app)
class Crypto(Resource):
def get(self):
#initialize empty dict
priceDict = {}
#Flux
flux = fluxPrice()
priceDict.update({'Flux': flux})
#Presearch
pre = prePrice()
priceDict.update({'Presearch': pre})
#print (priceDict)
data = priceDict
return {'data': data}, 200
api.add_resource(Crypto, '/crypto')
if __name__ == '__main__':
app.run()

40
getPrices.py Normal file
View File

@@ -0,0 +1,40 @@
#Checks price of flux
import requests
def fluxPrice():
#URL to send the request to
url = 'https://api.kucoin.com/api/v1/market/orderbook/level1?symbol=FLUX-USDT'
headers = ''
#Looks only for the price data
params = {'price': ''}
#result calculcation
result = requests.get(url=url, params=params)
jsonResult = result.json()
#fluxPrice =
#Finds the json data with the "data" category, then looks for "price"
price = jsonResult["data"]["price"]
#Maps to a dict that will be returned to the API
#price = {'Flux': price}
#print(price)
return price
def prePrice():
#URL to send the request to
url = 'https://api.kucoin.com/api/v1/market/orderbook/level1?symbol=PRE-USDT'
headers = ''
#Looks only for the price data
params = {'price': ''}
#result calculcation
result = requests.get(url=url, params=params)
jsonResult = result.json()
#fluxPrice =
#Finds the json data with the "data" category, then looks for "price"
price = jsonResult["data"]["price"]
#Maps to a dict that will be returned to the API
#price = {'Flux': price}
#print(price)
return price