import os
import time
import requests
import socket
import json
import websocket
import threading

current_dir = os.path.dirname(os.path.abspath(__file__))
pkg_dir = os.path.dirname(current_dir)
sys.path.append(pkg_dir)
from influxdb_client.influxdb_client_host_1 import InfluxClientHost1
from influxdb_client.influxdb_client_host_2 import InfluxClientHost2
from utility.error_logger_writer import logger

host_1 = InfluxClientHost1()
host_2 = InfluxClientHost2()

# Global Default Variables
app_id = '256'
#app_id = '2bd36ad5581c4ff0b9914641a40480316ab28105'
auth_url = 'https://api.refinitiv.com:443/auth/oauth2/v1/token'
discovery_url = 'https://api.refinitiv.com/streaming/pricing/v1/'
password = '******'
position = ''
sts_token = ''
refresh_token = ''
user = '******'
clientid = '2bd36ad5581c4ff0b9914641a40480316ab28105'
client_secret = ''
scope = 'trapi'
import traceback
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})