Skip to content
This repository has been archived by the owner on Sep 3, 2022. It is now read-only.

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
aasseman committed Jul 5, 2021
0 parents commit afbd623
Show file tree
Hide file tree
Showing 21 changed files with 1,732 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
terraform
old_scripts
redis*
.vscode/
__pycache__/
241 changes: 241 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@

# Created by https://www.toptal.com/developers/gitignore/api/terraform,python,linux,macos,visualstudiocode
# Edit at https://www.toptal.com/developers/gitignore?templates=terraform,python,linux,macos,visualstudiocode

### Linux ###
*~

# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*

# KDE directory preferences
.directory

# Linux trash folder which might appear on any partition or disk
.Trash-*

# .nfs files are created when an open file is removed but is still being accessed
.nfs*

### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

### Terraform ###
# Local .terraform directories
**/.terraform/*

# .tfstate files
*.tfstate
*.tfstate.*

# Crash log files
crash.log

# Exclude all .tfvars files, which are likely to contain sentitive data, such as
# password, private keys, and other secrets. These should not be part of version
# control as they are data points which are potentially sensitive and subject
# to change depending on the environment.
#
*.tfvars

# Ignore override files as they are usually used to override resources locally and so
# are not checked in
override.tf
override.tf.json
*_override.tf
*_override.tf.json

# Include override files you do wish to add to version control using negated pattern
# !example_override.tf

# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
# example: *tfplan*

# Ignore CLI configuration files
.terraformrc
terraform.rc

### VisualStudioCode ###
.vscode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace

# Local History for Visual Studio Code
.history/

### VisualStudioCode Patch ###
# Ignore all local history of files
.history
.ionide

# End of https://www.toptal.com/developers/gitignore/api/terraform,python,linux,macos,visualstudiocode
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM python:3.9

WORKDIR /usr/local/src

# Copy code
COPY . .

# Don't use a virtualenv
ARG POETRY_VIRTUALENVS_CREATE=False

RUN pip install --upgrade pip \
&& pip install poetry \
&& poetry install --no-dev
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## Development

Requirements:

- poetry
- docker
- pyenv

### Installing dependencies

```sh
python -m poetry install
```

### Running environment

```sh
docker-compose up --build
```
13 changes: 13 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM python:3.9

WORKDIR /usr/local/src

# Copy code
COPY . .

# Don't use a virtualenv
ARG POETRY_VIRTUALENVS_CREATE=False

RUN pip install --upgrade pip \
&& pip install poetry \
&& poetry install --no-dev
31 changes: 31 additions & 0 deletions backend/backend.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import json

import database
from fastapi import FastAPI
from starlette.middleware.cors import CORSMiddleware

app = FastAPI()

DB = database.Database()


@app.get("/get_arb")
async def get_arb_from_redis():
return DB.grab_json()

@app.get("/get_legit")
async def get_legit_arb():
return DB.get_legit_arbs()

@app.get("/get_scam")
async def get_legit_arb():
return DB.get_scam_arbs()

app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)

49 changes: 49 additions & 0 deletions backend/database.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import json
from os import environ as env

from redis import Redis

ARB_OUTPUT = "output"
WORKER_PATHS = "paths"
LEGIT = "legit"
SCAM = "scam"

class Database:
def __init__(self):
redis_port = env.get("REDIS_PORT")
redis_host = env.get("REDIS_HOST")
if not redis_port:
raise ValueError("REDIS_PORT needs to be set")
if not redis_host:
raise ValueError("REDIS_HOST needs to be set")
self.redis: Redis = Redis(
host=redis_host, port=redis_port, db=0, decode_responses=True
)

def grab_json(self):
"""Grab the json"""
the_json = self.redis.get(ARB_OUTPUT)
return json.loads(the_json)

def get_legit_arbs(self, delete=False):
"""Retrieve legit arb list and clear it"""
legit_arbs = self._get_arbs(LEGIT)
if delete:
self.redis.delete(LEGIT)
return legit_arbs

def get_scam_arbs(self, delete=False):
"""Retrieve scam arb list and clear it"""
scam_arbs = self._get_arbs(SCAM)
if delete:
self.redis.delete(SCAM)
return scam_arbs.sort(key=lambda x: x["profitUSD"], reverse=True)


def _get_arbs(self, token):
if not self.redis.exists(token):
return []
arbs = self.redis.lrange(token, 0, -1)
arbs = [json.loads(x) for x in arbs]
arbs.sort(key=lambda x: x["profitUSD"], reverse=True)
return arbs
Loading

0 comments on commit afbd623

Please sign in to comment.