Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get stuck with the Error 401 at the creating driftClient step #138

Open
albertwong08 opened this issue Mar 10, 2024 · 0 comments
Open

Get stuck with the Error 401 at the creating driftClient step #138

albertwong08 opened this issue Mar 10, 2024 · 0 comments

Comments

@albertwong08
Copy link

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():

#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.

Please help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant