示例#1
0
 def __init__(self, *args, **kwargs):
     self.api = ccxt.deribit()
     super().__init__(*args, **kwargs)
     instrument_name = {
         'instrument_name': self.market,
     }
     currency = {'currency': self.market[:3]}
     self.position = self.api.private_get_get_position(instrument_name)
     self.account = self.api.private_get_get_account_summary(currency)
示例#2
0
 def ex_api(self):
     if self.ex == "ftx":
         exchange = ccxt.ftx({
             'apiKey': self.apiKey,
             'secret': self.secret,
             'enableRateLimit': True
         })
     elif self.ex == "deribit":
         exchange = ccxt.deribit({
             'apiKey': self.apiKey,
             'secret': self.secret,
             'enableRateLimit': True,
             "urls": {
                 "api": "https://test.deribit.com"
             }
         })
     return exchange
示例#3
0
import ccxt
import random
import numpy as np
import pandas as pd
import datetime as dt
from math import exp, sqrt
from py_vollib.black_scholes_merton.implied_volatility import implied_volatility

from resources import pricing

dbt = ccxt.deribit()


def get_iv(row, side):
    try:
        iv = implied_volatility(
            row['{}_price'.format(side)] * row['index_price'],
            row['index_price'], row['strike'], row['until_expiry'],
            row['interest_rate'], row['q'], row['flag'])
        iv = round(100 * iv, 2)
    except Exception as e:
        print(e)
        iv = np.nan
    return iv


def get_iv_custom(row, side):
    try:
        if not np.isnan(row['mid_price']):
            iv = pricing.get_implied_vol(
                row['{}_price'.format(side)] * row['index_price'],
示例#4
0
import ccxt
import credentials
import time
# import pandas as pd
import numpy as np
import sys

exchange = ccxt.deribit({
    'apiKey': credentials.client_id,
    'secret': credentials.client_secret
})
# _perpetual = 'BTC-PERPETUAL'
# _sep = 'BTC-25SEP20'
# _dec = 'BTC-25DEC20'
# _mar = 'BTC-26MAR21'
# delay = 1
#
#
# def order_book(_symbol):
#     count_loop = 1
#     while True:
#         orderBook = exchange.fetch_order_book(_symbol, 5)
#         orderBook_bid = orderBook['bids']
#         orderBook_ask = orderBook['asks']
#         list_bid = pd.DataFrame(orderBook_bid)
#         list_ask = pd.DataFrame(orderBook_ask)
#         list_bid.rename(columns={0: 'Price', 1: 'Size'}, inplace=True)
#         list_ask.rename(columns={0: 'Price', 1: 'Size'}, inplace=True)
#         # print("Ask")
#         # print(list_ask)
#         time.sleep(delay)
示例#5
0
    # id_index = pandas.concat(raw_index_pnl)
    # id_trend = pandas.concat(raw_bt_pnl)

    # trade_count = pandas.Series(raw_bt_count)
    # daily_w1 = pandas.DataFrame(raw_index_w1)
    # rolling_w1 = daily_w1.rolling(20).mean()
    # daily_spot = pandas.DataFrame([i.sum().rename(i.index[0].date()) for i in raw_spot_pnl])
    # daily_index = pandas.DataFrame([i.sum().rename(i.index[0].date()) for i in raw_index_pnl])
    # daily_trend = pandas.DataFrame([i.sum().rename(i.index[0]) for i in raw_bt_pnl])
    #
    # agg_trend = daily_trend.mul(daily_w1.shift(1).fillna(1 / daily_w1.shape[1])).sum(axis=1)
    # print(pandas.Series({'ret': agg_trend.mean() * 260,
    #                      'vol': agg_trend.std() * (260 ** 0.5),
    #                      'sharpe': agg_trend.mean() / agg_trend.std() * (260 ** 0.5),
    #                      'neg_days': len(agg_trend[agg_trend < 0]),
    #                      'total_days': len(agg_trend),
    #                      'mdd': (1 - agg_trend.cumsum().div(agg_trend.cumsum().cummax())).max(),
    #                      'daily_trade_count': trade_count.mean()}))
    # agg_trend.cumsum().plot()
    with open('pickle', 'rb') as f:
        import pickle
        agg_trend = pickle.load(f)
    retu = (agg_trend.cumsum() / 50 + 1).pct_change()
    fig = pf.create_returns_tear_sheet(retu, return_fig=True)
    fig.savefig('/Users/sweetdreams/code/fintend/alpha/alpha.png')
    plt.show()

import ccxt

d = ccxt.deribit().fetch_ohlcv