#Connect to the drift API
env = "mainnet"
config = configs[env]
secret = os.getenv("SOL_PWORD")
keypair = load_keypair(secret)
wallet = Wallet(keypair)
connection = AsyncClient(config.default_http)
drift_client = DriftClient(connection,wallet,env)
print("client created")
await drift_client.add_user(0)
await drift_client.subscribe()
#tx_sig = await drift_client.initialize_user()
#Get the amount before deposit
user = drift_client.get_user()
SOL_amount = user.get_token_amount(0)
print(f"SOL amount before deposit:{SOL_amount}")
print("Try to deposit some SOL")
spot_market_index = 1 #SOL
amount_in_spot_market_precision = drift_client.convert_to_spot_precision(spot_market_index, 0.05) # $100
try:
tx_sig_and_slot = await drift_client.deposit(
amount_in_spot_market_precision,
spot_market_index
)
print(f"Deposited successfully: {tx_sig_and_slot.tx_sig}")
except Exception as e:
print(f"Failed to deposit: {e}")
#Get the amount after deposit
user = drift_client.get_user();
SOL_amount = user.get_token_amount(0)
print(f"SOL amount after deposit:{SOL_amount}")`
However, it throws exception at the "await drift_client.subscribe()".
I looked into the error returned. It is due to the HTTP 401 response error at function find_all_market_and_oracles under config.py.
I tried the client setup steps listed at the following page: https://drift-2.gitbook.io/driftpy-for-dummies/setup
Here is my code: `async def test_drift():
However, it throws exception at the "await drift_client.subscribe()". I looked into the error returned. It is due to the HTTP 401 response error at function find_all_market_and_oracles under config.py.
Please help.