import time
import os
import sys 
current_dir = os.path.dirname(os.path.abspath(__file__))
dm_dir = os.path.dirname(current_dir)
pkg_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
sys.path.append(pkg_dir)
from influxdb_client.influxdb_client_host_1 import InfluxClientHost1
from influxdb_client.influxdb_client_host_2 import InfluxClientHost2
from influxdb_client.influxdb_client_qa_host_1 import InfluxClientHostQA1
from api_deribit.DeribitRestApi import RestClient

host_1 = InfluxClientHostQA1()
host_2 = InfluxClientHost2()

deribit_api = RestClient()

measurement = "exchange_open_interest"


# Deribit
contract_names = [i['instrumentName'] for i in deribit_api.getinstruments()]
btc_contract_names = [i for i in contract_names if "BTC" in i]
eth_contract_names = [i for i in contract_names if "ETH" in i]

def write_open_interest_data(measurement):
    for cn in eth_contract_names:
        fields = {}
        # perpetual swap 
        if "PERPETUAL" in cn:
            summary_data = deribit_api.getsummary(cn)
import datetime
import os 
import sys 
current_dir = os.path.dirname(os.path.abspath(__file__))
import multiprocessing
import json
from time import sleep

sys.path.append(os.path.dirname(os.path.dirname(current_dir)))
from influxdb_client.influxdb_client_host_1 import InfluxClientHost1
from api_deribit.DeribitRestApi import RestClient
from utility.error_logger_writer import logger


db = InfluxClientHost1()
deribit = RestClient()
measurement = "deribit_tickers"

def symbol_eth():
    symbols = [i['instrumentName'] for i in deribit.getinstruments()]
    btc_symbols = [symb for symb in symbols  if "ETH" in symb]
    return btc_symbols


def write_ticker_data(measurement,d):
    fields = {}
    try:
        fields.update({"askPrice":float(d["askPrice"])})
    except: 
        fields.update({"askPrice":None})
    try: