Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR for OB task #1

Closed
wants to merge 91 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
23bfb9c
OB code commit
Carti23 Jan 5, 2024
58abd16
update the OB code
Carti23 Jan 5, 2024
b1a1c61
Update requirements.txt
Carti23 Jan 5, 2024
26d7a38
Update order_books.py
Carti23 Jan 5, 2024
1d28a23
Add /data_folder to .gitignore
Carti23 Jan 12, 2024
6ada4a7
update the code for OB task
Carti23 Jan 12, 2024
b3b6875
fixed merge conflict
dryad Jan 12, 2024
a54096f
updated the OB code
Carti23 Jan 21, 2024
4b6984b
refactoring
Carti23 Jan 22, 2024
f368a5e
replace txt to json
Carti23 Jan 22, 2024
772f5e6
updated the OB sctructure
Carti23 Jan 24, 2024
32b6951
fix(root): linting
Romakl Jan 24, 2024
34b98e4
fix(exchanges): fixed data_saver
Romakl Jan 24, 2024
8c0ac7c
fix(exchanges): fixed data_saver and exchange_manager to save data pr…
Romakl Jan 24, 2024
bdb9a11
fix(exchanges): fixed constants structure
Romakl Jan 25, 2024
740970d
chore(exchanges): still fixing code logic
Romakl Jan 25, 2024
0e14e96
refactoring(exchanges): made a refactoring for code logic
Carti23 Jan 25, 2024
d41f5e2
chore(exchanges): lint and fixed imports
Romakl Jan 25, 2024
0ae0e78
deleted limit(exchange_manager.py): deleted the parameter limit from …
Carti23 Jan 25, 2024
0b348f8
fixed (managers/, data_fetcher, data_filter) delete the _handle_error…
Carti23 Jan 25, 2024
2868c0a
added func (exchanghe_manager.py): added the function select_otm_opti…
Carti23 Jan 26, 2024
ed98d5b
added the func(exchange_manager.py): added section 5 from Filtering (…
Carti23 Jan 26, 2024
15a6978
added the func(exchange_manager.py): added section 6 from Filtering (…
Carti23 Jan 26, 2024
17ec36d
updated (constants/utils.py): added new constant
Carti23 Jan 26, 2024
6ff1f79
created new file (preprocessing.py): created new file with preprocess…
Carti23 Jan 26, 2024
c05dc77
updated (exchange_manage.py): updated the code
Carti23 Jan 26, 2024
d0ba3b0
added bybit (main.py): added the bybit exchange import
Carti23 Jan 26, 2024
8ac668c
chore(exchanges): fixed imports, added comments for readability, adde…
Romakl Jan 28, 2024
e495c4e
chore(exchanges): remove .env and added LICENCE
Romakl Jan 28, 2024
70c859f
fix(root): linting and added CI
Romakl Jan 28, 2024
64f4c99
fixdqwd(root): linting and added CI
Romakl Jan 28, 2024
f3bb245
fixdqwd(root): fixed imports and added more tests
Romakl Jan 28, 2024
5bb70ab
feat(exchanges): added implied_variance formula
Romakl Jan 28, 2024
472f16b
feat(exchanges): big refactor of code to simplify our life
Romakl Jan 28, 2024
e168ac2
fix(root): commented code to avoid CI fails
Romakl Jan 28, 2024
90bed2b
Merge branch 'main' into OB_branch
Carti23 Jan 29, 2024
9b6c9f9
added init.py (exchanges, managers, tests): created new file __init__.py
Carti23 Jan 29, 2024
1142283
feat(exchanges): lint and added all formulas to calculate
Romakl Jan 30, 2024
98ad3ab
added the formuals (exchange_manager.py): implemented some formulas i…
Carti23 Feb 1, 2024
ce4b934
fix(exchanges): fixed imports
Romakl Feb 1, 2024
488b74d
feat(exchanges): added handlers
Romakl Feb 1, 2024
bbd7899
fix(exchanges): fixing logic
Romakl Feb 1, 2024
e5a5b75
fixed logic (exchanges): working on fixing the logic
Carti23 Feb 2, 2024
94a9eef
changed the logic (exchange): change the logic for options, futures
Carti23 Feb 2, 2024
def5585
fix(exchanges): fixing consilidate data, fixing formulas and so on
Romakl Feb 2, 2024
b08e7eb
added near/next term (handlers/option): added the option_type(next_te…
Carti23 Feb 2, 2024
a82916a
eliminate (handlers/option): eliminate invalid quotes
Carti23 Feb 2, 2024
52f0761
fixed (handlers/option): eliminate invalid quotes
Carti23 Feb 2, 2024
6c34174
added functionality (handlers/): added functions (yield_curve, intere…
Carti23 Feb 2, 2024
9cc254a
fixed (handlers/future.py): fixed the time_to_maturity
Carti23 Feb 2, 2024
dd21e0d
added (handlers/future): added interpolate_yield_curve -> still need …
Carti23 Feb 2, 2024
89301a3
changed logic (exchange): changed the logic for the code
Carti23 Feb 3, 2024
c724e60
fix(exchanges): fixed merge logic
Romakl Feb 4, 2024
5520ecb
fix(exchanges): fixed bid, ask price fetching
Romakl Feb 4, 2024
e2572c7
changed logic (exchange): changed the logic for the code
Carti23 Feb 4, 2024
ff1c339
fixed saving (handlers/future): fixed the format of saving the data f…
Carti23 Feb 5, 2024
64dbbab
fix(exchanges): fixed logic a little bit
Romakl Feb 5, 2024
cd7ff74
added new funcs (exchanges/): added the new fucntionality
Carti23 Feb 5, 2024
8f8f3c4
fixed (exchanges/filtering.py): fixed the fucntion calculate_Fimp
Carti23 Feb 5, 2024
22f006e
fixed (exchanges/filtering.py): fixed the fucntion set_ATM_strike
Carti23 Feb 5, 2024
e0655e1
fixed (exchanges/filtering.py): fixed the fucntions select_OTM_options
Carti23 Feb 6, 2024
3b9f1ef
fix(exchanges): still fixing exhanges logic
Romakl Feb 6, 2024
7b62371
chore(exchanges): still working on data structure
Romakl Feb 7, 2024
5f77088
chore(exchanges): added okx market, need to implement binance and spe…
Romakl Feb 8, 2024
244610f
chore(exchanges): added binance fetcher
Romakl Feb 9, 2024
f0678e2
chore(exchanges): added binance fetcher
Romakl Feb 9, 2024
f8a8759
chore(exchanges): standartalized data, added future fetcher
Romakl Feb 10, 2024
44497b1
chore(exchanges): still working with ccxt
Romakl Feb 10, 2024
dbdc6a3
fix(exchanges): added better logic for deribit
Romakl Feb 14, 2024
39a8a86
chore(exchanges): working with okx data
Romakl Feb 16, 2024
7283485
Merge remote-tracking branch 'origin/OB_branch' into OB_branch
Romakl Feb 16, 2024
184f339
chore(exchanges): working with okx data
Romakl Feb 16, 2024
01ccc4c
chore(exchanges): working with okx data
Romakl Feb 19, 2024
88777a0
chore(exchanges): working with okx data
Romakl Feb 19, 2024
440e51d
chore(exchanges): working with okx data
Romakl Feb 19, 2024
492bf51
chore(exchanges): working with okx data
Romakl Feb 23, 2024
cf1d98c
chore(exchanges): working with okx data
Romakl Feb 26, 2024
e2addba
chore(exchanges): working with binance forward_price logic
Romakl Feb 29, 2024
61f933a
chore(exchanges): working with interpolated_forward_price
Romakl Mar 3, 2024
e46ef41
feat(exchanges): added yield_curve
Romakl Mar 7, 2024
e01eb08
feat(exchanges): consolidate data
Romakl Mar 10, 2024
4e83e7f
feat(exchanges): consolidate data
Romakl Mar 11, 2024
ab88755
feat(exchanges): calculate_forward_and_atm
Romakl Mar 11, 2024
b82413b
feat(exchanges): implemented calculate_raw_implied_variance
Romakl Mar 13, 2024
5a4805d
fix(exchanges): forgot to commit some part of code
Romakl Mar 13, 2024
1f2cea8
fix(exchanges): filtering
Romakl Mar 18, 2024
8113af6
fix(exchanges): interpolate
Romakl Mar 18, 2024
40576bc
fix(exchanges): calculate_wij
Romakl Mar 19, 2024
8df6f9d
fix(exchanges): calculate_sigma_it_squared
Romakl Mar 20, 2024
a026670
fix(exchanges): calculate_sigma_it_squared
Romakl Mar 22, 2024
8d01768
fix(exchanges): fixing all mess
Romakl Mar 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Python Linting

on: [push, pull_request]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.11'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 black

- name: Check with Flake8
run: flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics

- name: Format code with Black
run: black --check .
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
exchanges/data_folder
exchanges/constants/.env
/venv
__pycache__/
.env
exchanges/*.json
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions all_feeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
Test = test_feed.Test
MCAP1000 = mcap1000.MCAP1000

#NOTE: this is a dict of all feed classes that SIWA can run, keyed by feed name
# NOTE: this is a dict of all feed classes that SIWA can run, keyed by feed name
# this is used in endpoint.py to route requests to the correct feed
#
#TO ENABLE OR DISABLE A FEED, ADD OR REMOVE IT FROM THIS DICT
# TO ENABLE OR DISABLE A FEED, ADD OR REMOVE IT FROM THIS DICT
all_feeds = {
Test.NAME: Test,
MCAP1000.NAME: MCAP1000,
}
}
10 changes: 5 additions & 5 deletions apis/coingecko.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class CoinGeckoAPI(CryptoAPI):
extract_market_cap(data: Dict[str, Any]) -> Dict[float, Dict[str, str]]:
Extracts market cap data from API response.
"""

VS_CURRENCY = "usd"
ORDER = "market_cap_desc"
PAGE = 1
Expand All @@ -31,8 +32,7 @@ def __init__(self) -> None:
Constructs all the necessary attributes for the CoinGeckoAPI object.
"""
super().__init__(
url="https://api.coingecko.com/api/v3/coins/markets",
source='coingecko'
url="https://api.coingecko.com/api/v3/coins/markets", source="coingecko"
)

@utils.handle_request_errors
Expand Down Expand Up @@ -92,7 +92,7 @@ def get_market_caps_of_list(self, tokens: List[str]) -> Dict[str, float]:
"""
market_caps = {}

tokens_comma_sep = ','.join(tokens)
tokens_comma_sep = ",".join(tokens)

parameters = {
"vs_currency": self.VS_CURRENCY,
Expand All @@ -107,7 +107,7 @@ def get_market_caps_of_list(self, tokens: List[str]) -> Dict[str, float]:
name = d.get(self.NAME_KEY)
last_updated = d.get(self.LAST_UPDATED_KEY)
market_caps[market_cap] = {
'name': name,
'last_updated': last_updated,
"name": name,
"last_updated": last_updated,
}
return market_caps
32 changes: 12 additions & 20 deletions apis/coinmarketcap.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ def __init__(self) -> None:
"""
Constructs all the necessary attributes for the CoinMarketCapAPI object.
"""
source = 'coinmarketcap'
source = "coinmarketcap"
super().__init__(
url="https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest",
source=source
source=source,
)
self.headers = {
self.CMC_PRO_API_KEY: self.get_api_key(source),
Expand All @@ -53,12 +53,8 @@ def get_data(self, N: int) -> Dict[str, Any]:
Returns:
Dict[str, Any]: A dictionary with data fetched from API.
"""
parameters = {
self.LIMIT: N
}
response = requests.get(
self.url, headers=self.headers, params=parameters
)
parameters = {self.LIMIT: N}
response = requests.get(self.url, headers=self.headers, params=parameters)
data = response.json()
return data

Expand Down Expand Up @@ -96,12 +92,8 @@ def get_market_cap_of_token(self, id: int) -> Dict[str, float]:
Dict[str, float]: A dictionary with market cap as keys and other metadata as values.
"""
url = "https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest"
parameters = {
self.ID: id
}
response = requests.get(
url, headers=self.headers, params=parameters
)
parameters = {self.ID: id}
response = requests.get(url, headers=self.headers, params=parameters)
data = response.json()

market_cap_data = {}
Expand All @@ -111,9 +103,9 @@ def get_market_cap_of_token(self, id: int) -> Dict[str, float]:
last_updated = token_data[self.LAST_UPDATED]
market_cap = token_data[self.QUOTE][self.USD][self.MARKET_CAP]
market_cap_data = {
'name': name,
'market_cap': market_cap,
'last_updated': last_updated,
"name": name,
"market_cap": market_cap,
"last_updated": last_updated,
}
return market_cap_data

Expand All @@ -131,9 +123,9 @@ def get_market_caps_of_list(self, ids: List[int]) -> Dict[str, Dict[str, Any]]:
for id in ids:
mcap_data = self.get_market_cap_of_token(id)
if mcap_data:
market_caps[mcap_data['market_cap']] = {
'name': mcap_data['name'],
'last_updated': mcap_data['last_updated']
market_caps[mcap_data["market_cap"]] = {
"name": mcap_data["name"],
"last_updated": mcap_data["last_updated"],
}
time.sleep(0.2) # To prevent hitting API rate limits

Expand Down
20 changes: 11 additions & 9 deletions apis/coinpaprika.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ def __init__(self) -> None:
"""
Constructs all the necessary attributes for the CoinPaprikaAPI object.
"""
self.ohlc_url = "https://api.coinpaprika.com/v1/coins/{coin_id}/ohlcv/latest" # noqa E501
self.ohlc_url = (
"https://api.coinpaprika.com/v1/coins/{coin_id}/ohlcv/latest" # noqa E501
)
super().__init__(
url="https://api.coinpaprika.com/v1/coins",
source='coinpaprika'
url="https://api.coinpaprika.com/v1/coins", source="coinpaprika"
)

@utils.handle_request_errors
Expand All @@ -49,17 +50,18 @@ def get_data(self, N: int) -> List[Dict[str, Any]]:
data = response.json()
else:
raise requests.exceptions.RequestException(
f"Received status code {response.status_code} "
f"for URL: {self.url}"
f"Received status code {response.status_code} " f"for URL: {self.url}"
)
# Sorting the coins by market cap
# Also filtering out coins with rank 0 (junk values in API response)
filtered_data = [coin for coin in data if coin['rank'] != 0]
sorted_data = sorted(filtered_data, key=lambda coin: coin['rank'])[:N]
filtered_data = [coin for coin in data if coin["rank"] != 0]
sorted_data = sorted(filtered_data, key=lambda coin: coin["rank"])[:N]
return sorted_data

@utils.handle_request_errors
def extract_market_cap(self, data: List[Dict[str, Any]]) -> Dict[float, Dict[str, Any]]:
def extract_market_cap(
self, data: List[Dict[str, Any]]
) -> Dict[float, Dict[str, Any]]:
"""
Extracts market cap data from API response.

Expand Down Expand Up @@ -87,7 +89,7 @@ def extract_market_cap(self, data: List[Dict[str, Any]]) -> Dict[float, Dict[str

name = coin["name"]
last_updated = 0 # Updated every 5 mins as per docs: https://api.coinpaprika.com/#tag/Coins/paths/~1coins~1%7Bcoin_id%7D~1ohlcv~1today~1/get # noqa E501
market_cap = coin_info[0]['market_cap']
market_cap = coin_info[0]["market_cap"]
market_data[market_cap] = {
"name": name,
"last_updated": last_updated,
Expand Down
10 changes: 3 additions & 7 deletions apis/crypto_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class CryptoAPI:
Abstract method to extract market cap data.
"""

API_KEYS_FILE = 'api_keys.json'
API_KEYS_FILE = "api_keys.json"

def __init__(self, url: str, source: str) -> None:
"""
Expand Down Expand Up @@ -52,9 +52,7 @@ def fetch_mcap_by_list(self, tokens: List[str]) -> Dict[str, float]:

# Store market data in the database
utils.create_market_cap_database()
utils.store_market_cap_data(
market_data=market_data, source=self.source
)
utils.store_market_cap_data(market_data=market_data, source=self.source)
return market_data

def fetch_mcap_by_rank(self, N: int) -> dict:
Expand All @@ -77,9 +75,7 @@ def fetch_mcap_by_rank(self, N: int) -> dict:

# Store market data in the database
utils.create_market_cap_database()
utils.store_market_cap_data(
market_data=market_data, source=self.source
)
utils.store_market_cap_data(market_data=market_data, source=self.source)
return market_data

def get_data(self, N: int) -> Any:
Expand Down
11 changes: 5 additions & 6 deletions apis/cryptocompare.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def __init__(self) -> None:
"""
super().__init__(
url="https://min-api.cryptocompare.com/data/top/mktcapfull",
source='cryptocompare'
source="cryptocompare",
)

@utils.handle_request_errors
Expand Down Expand Up @@ -66,8 +66,7 @@ def get_data(self, N: int, buffer: int = 2) -> Dict[str, Any]:
data = response.json()
else:
raise requests.exceptions.RequestException(
f"Received status code {response.status_code} "
f"for URL: {self.url}"
f"Received status code {response.status_code} " f"for URL: {self.url}"
)
missing_count = 0
for coin in data[self.DATA]:
Expand Down Expand Up @@ -118,7 +117,7 @@ def get_market_caps_of_list(self, tokens: List[str]) -> Dict[str, Dict[str, Any]
"""
url = "https://min-api.cryptocompare.com/data/pricemultifull"
tokens_upper = [token.upper() for token in tokens]
tokens_comma_sep = ','.join(tokens_upper)
tokens_comma_sep = ",".join(tokens_upper)
parameters = {
self.FSYMS: tokens_comma_sep,
self.TSYMS: self.USD,
Expand All @@ -133,7 +132,7 @@ def get_market_caps_of_list(self, tokens: List[str]) -> Dict[str, Dict[str, Any]
market_cap = data[self.RAW][token][self.USD][self.MKTCAP]
last_updated = data[self.RAW][token][self.USD][self.LAST_UPDATE]
market_caps[market_cap] = {
'name': token,
'last_updated': last_updated,
"name": token,
"last_updated": last_updated,
}
return market_caps
Loading
Loading