Created
August 18, 2020 22:32
-
-
Save staccDOTsol/82c3f40e8ba2ac434b5ab54b55e369c0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from dydx.client import Client | |
import dydx.constants as consts | |
import dydx.util as utils | |
# create a new Python client with a private key (string or bytearray) | |
# Only one Python client is needed for both Solo and Perpetual API | |
client = Client( | |
private_key='', | |
node='https://mainnet.infura.io/v3/55458f59f7cf468994d636c99a959de6' | |
) | |
markets = client.get_perpetual_markets() | |
syms = [] | |
rates = [] | |
for m in markets['markets']: | |
if m['market'] == 'WETH-PUSD': | |
syms.append(m['market']) | |
rate = round(float(m['fundingRate']) * 8*60*60*100*3 * 10000)/ 10000 | |
# print(m['market'] + ' daily funding rate: ' + str(rate) + '%') | |
rates.append(rate) | |
t = 0 | |
c = 0 | |
for r in rates: | |
t = t + r | |
c = c + 1 | |
avg = t / c | |
#print('avg opp: ' + str(avg) + '%') | |
percs = {} | |
c = -1 | |
for r in rates: | |
c = c + 1 | |
percs[syms[c]] = round((r/t*100)*10000)/10000 | |
#print('\npercents of opps out of total opps:') | |
#print(percs) | |
pairs = client.get_pairs() | |
for m in pairs['markets']: | |
if m == 'WETH-USDC': | |
#print(pairs['markets'][m]) | |
a=1 | |
def get_bbo(market): | |
orderbook = client.get_orderbook( | |
market=market | |
) | |
hb = 0 | |
la = 9999999999999999 | |
for bid in orderbook['bids']: | |
if float(bid['price']) > hb: | |
hb = float(bid['price']) | |
for ask in orderbook['asks']: | |
if float(ask['price']) < la: | |
la = float(ask['price']) | |
bbo = {'ask': la * 10 ** 12, 'bid': hb * 10 ** 12, 'mid': (la * 10 ** 12 + hb * 10 ** 12) / 2} | |
return(bbo) | |
spot = get_bbo('WETH-USDC')['mid'] | |
perp = get_bbo('WETH-PUSD')['mid'] | |
arb = (perp / spot - 1) * 100 | |
arb=(round(arb* 10000)/ 10000) | |
print('Eth Perp Funding: ' + str(avg) + '%') | |
print('Eth Perp Premium vs Spot: ' + str(arb) + '%') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment