Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
55 changes: 55 additions & 0 deletions components/aave_repayment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
class AaveRepayMent:
def repay_to_aave(self, price_open_close, borrow_pcg, buffer=0.01):
staked_asset_percentage = 0.1
price_repay_debt = price_open_close * (
1 - (staked_asset_percentage * borrow_pcg * (1 + buffer))
)
return price_repay_debt

def partial_repay_to_aave(
self,
price_open_close,
lending_rate,
collateral,
asset_market_price,
borrowing_rate,
total_staked_asset,
):
lending_fee = lending_rate * collateral * asset_market_price
staked_asset_percentage = 0.1
borrow_loan_percentage = 0.25
current_debt_in_usd = (
total_staked_asset * staked_asset_percentage * price_open_close
)
borrowing_fees = borrowing_rate * current_debt_in_usd
if borrowing_fees > lending_fee:
price_repay_partial_aave = price_open_close * (
(borrowing_rate * borrow_loan_percentage)
/ (lending_rate * staked_asset_percentage)
)
position_size = (
(lending_rate / borrowing_rate)
* staked_asset_percentage
* total_staked_asset
* asset_market_price
) - current_debt_in_usd
position_size = position_size / (asset_market_price - price_open_close)
return {
"repay_price": price_repay_partial_aave,
"position_size": position_size,
}


if __name__ == "__main__":
a = AaveRepayMent()
a = a.partial_repay_to_aave(
price_open_close=996,
lending_rate=0.0108,
collateral=9,
asset_market_price=770,
borrowing_rate=0.0229,
total_staked_asset=10,
)
# {'repay_price': 586.0468106995884, 'position_size': -14.989935030354667}
# a = a.repay_to_aave(price_open_close=996.4709841514826,borrow_pcg=0.25)
print(a)
21 changes: 15 additions & 6 deletions components/dydx_order_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ def calculate_open_close_price(self, asset_pair, eth_order_size, symbol):
ema_data = self.firebase_data_manager_obj.fetch_data(
collection_name="ema_data", document_name=symbol
)

ema = ema_data.get("ema")
# K must change ,K being variable will cover price movement
# within 30s under normal market conditions
Expand Down Expand Up @@ -319,7 +318,9 @@ def open_order_on_dydx(self, order_details):
symbol=order_details["binance_asset_pair"],
status=is_position_open,
)
print(f"DydxOrderManager:: {order_details['asset_pair']} - Short position is open")
print(
f"DydxOrderManager:: {order_details['asset_pair']} - Short position is open"
)
else:
print(
f"DydxOrderManager:: { order_details['asset_pair']} {asset_trigger_price} is less than market price {asset_market_price}"
Expand Down Expand Up @@ -369,20 +370,28 @@ def close_order_on_dydx(self, order_details):
status=is_position_open,
)

print(f"class::DydxOrderManager {order_details['asset_pair']} - Short position is closed")
print(
f"class::DydxOrderManager {order_details['asset_pair']} - Short position is closed"
)
else:
print(
f"DydxOrderManager:: {order_details['asset_pair']} trigger price {asset_trigger_price} is greater than market price {asset_market_price}"
)
else:
if asset_trigger_price < asset_market_price:
print(f"DydxOrderManager:: {order_details['asset_pair']} short position is closed")
print(
f"DydxOrderManager:: {order_details['asset_pair']} short position is closed"
)
else:
print(
f"DydxOrderManager::{order_details['asset_pair']} trigger price {asset_trigger_price} is less than market price {asset_market_price}"
)


if __name__ == "__main__":
a = DydxOrderManager(None)
a.market_volatility("ETHBUSD")
a = DydxOrderManager(asset_dydx_instance["ETH-USD"])
a = a.calculate_open_close_price(
asset_pair="ETH-USD", eth_order_size=10, symbol="ETHBUSD"
)
print(a)
# print(a.market_volatility(symbol="ETHBUSD"))
6 changes: 3 additions & 3 deletions components/price_floor_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ def set_price_floor(self, asset_name, number_of_days=30):
prices.append(asset_price_data["prices"][i][1])
prices.sort(reverse=True)
asset_peak_price = prices[0]
current_price_floor = asset_peak_price * 0.60
#TODO: if perivous_price_floor < current_price_floor : update the price floor, else don't update
current_price_floor = asset_peak_price * 0.60
# TODO: if perivous_price_floor < current_price_floor : update the price floor, else don't update
# get price floor
firebase_data_manager_obj.store_data(
data={
Expand Down Expand Up @@ -55,4 +55,4 @@ def get_assets_price_floors(self):

if __name__ == "__main__":
a = PriceFloorManager()
print(a.set_price_floor('bitcoin'))
print(a.set_price_floor("bitcoin"))
10 changes: 10 additions & 0 deletions services/binance_client/binance_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from binance.client import Client as Client_binance
from settings_config import dydx_instances

"""class :: BinanceClient - is used to get price data for assets"""


class BinanceClient(object):
def __init__(self):
Expand All @@ -12,6 +14,14 @@ def __init__(self):
api_key=self.binance_api_key, api_secret=self.binance_api_secret
)

"""
method :: price_data_per_interval - is used to get the price data for an interval.
params :: symbol - symbole of the asset - ETHBUSD,BTCBUSD.
params :: start_time - start time for an interval.
params :: end_time - end time for an interval.
return :: array of price data.
"""

def price_data_per_interval(self, symbol, start_time, end_time):
data = self.client.get_historical_klines(
symbol=symbol,
Expand Down