Bybit API (ErrCode: 10002) - algorithmic-trading

Just trying to interact with the API, but I am getting a specific error when trying the simplest tasks such as getting the balance.
Example Code
import API_Login as apiLogin
from pybit.usdt_perpetual import HTTP
apiKey = apiLogin.api_key
apisecret = apiLogin.api_secret
session = HTTP(
endpoint="https://api.bybit.com",
api_key= apiKey,
api_secret= apisecret)
session.get_wallet_balance(coin="USDT")
The error I receive:
2022-09-26 15:31:49 - pybit._http_manager - ERROR - invalid request, please check your timestamp and recv_window param.
req_timestamp: 1664231507914 server_timestamp: 1664231504913 recv_window: 5000 (ErrCode: 10002). Added 2.5 seconds to recv_window. 2 retries remain.
Error code 10002 is defined: Request not authorized - an API key is required and should be included in all requests.
But I know my API information is valid.

Figured out that my system clock was not synced properly. Hit the Sync Now button and it works perfectly.

Related

My test works in Jmeter but not in Azure Load Testing

I've defined a test on Jmeter which works correctly on Jmeter on my pc, but it doesn't work when I run it Azure Load Testing.
My test is very simple: it performs a POST request towards Azure AD (https://login.microsoftonline.com/TenantID/oauth2/token?api-version=1.0) with a body like the following one in order to retrieve a token:
"grant_type" = "client_credentials";
"resource" = "$resource";
"client_id" = "$APPID";
"client_secret" = "$ClientSecret"
JMeter parameters for the POST call
When I perform the call from my PC, it works and I'm then able to use the token to perform some other calls (not relevant here).
When I perform this single call on Azure Load Testing with my jmx file, the calls fails with a 400 (Bad request), as if my request was malformed.
When I download the results of the test, I get the following csv:
timeStamp elapsed label responseCode responseMessage threadName dataType success failureMessage bytes sentBytes grpThreads allThreads URL Latency IdleTime Connect
1.67602E+12 147 Get token 400 Bad Request 172.18.19.5-Setup Authentication 1-1 text FALSE 925 1119 1 1 https://login.microsoft.com/*tenantID*/oauth2/v2.0/token 144 0 107
where tenantID reflects the actual tenant ID.
In order to troubleshoot it, I've tried to replace the values of the tenand id with the values of client id, scope and secret and they show up correctly in the log file when I execute the test.
Also, in my AAD logs I don't see my login attempts, probably because of the 400 - Bad request code, as if my request was somehow malformed, so it doesn't get logged.
I've no idea how I could troubleshoot this further (e.g. can I somehow trace the parameters of the POST call Azure Load Testing is doing?). Any suggestions?
thanks for your help,
Marco

Google.apis returns error code 400 after creating maximum amount of service account keys

We are using Google.apis Version 1.36.1 SDK in order to create service account keys for GCP Service accounts.
When we reach maximum amount of keys (10) instead of getting a valid error message / error code we recieve a general 400 error code with a "Precondition check failed." message.
We used to get error code 429 indicating we have reached maximum amount of keys.
Current GoogleApiException object :
Google.GoogleApiException: Google.Apis.Requests.RequestError
Precondition check failed. [400]
Errors [
Message[Precondition check failed.] Location[ - ] Reason[failedPrecondition] Domain[global]
]
The current return code does not provide us with enough information, Is there any other way for us to know the reason of the failure ?
This error message is also related to limits. You can take the official documentation for the Classroom API as an example.
I have found myself in a similar situation where we were deleting service account keys to immediately create new ones. We were getting the same error because there is a delay on the system where it can take from 60-90 seconds to delete the key for you to be able to create it again.

JMeter - Execute HTTP Request until Response Headers matches

I'm new with JMeter and I'm working with a script for checking the cache, the scenario was to:
do a GET request
verify that it has been cached
do a DELETE request
verify that the cache has been deleted
However since there are three instances in the environment I'm working on my script is having intermittent failures because of the different x-internal-service-host being returned.
My test results looks like this:
do a GET request (x-internal-service-host returned is
c3c8021a51a9:8080 - PASS)
verify that it has been cached
(x-internal-service-host returned is 4eb7ac9d4a76:8080 - FAILED
because the call made was for c3c8021a51a9:8080)
do a DELETE
request (x-internal-service-host returned
is c3c8021a51a9:8080 - PASS)
verify that the cache has been deleted
(request x-internal-service-host returned is c3c8021a51a9:8080 -
FAILED because the delete was made for 4eb7ac9d4a76:8080)
I'm thinking of extracting the Response Header x-internal-service-host in step 1 but I'm not sure how to proceed once extracted, is it possible to send a GET request until the Response Header extracted matches the Response Header result for steps 2 to 4 or is there a better way to do this?

Getting 401 Unauthorized error when threads in JMeter increase

I am running a JMeter script, where I get the Access Token which I use it for my HTTP Request Samplers (By using Bearer ${AccessToken} in Header Manager of each Request). My HTTP Requests are being categorized into multiple Simple Controllers.
There are 70 HTTP GET Requests and ONE Thread takes around 20 seconds to execute them all.
Now when my no. of threads increase, say 3 onwards, then I start getting 401 Errors
({
"statusCode": 401,
"error": "Unauthorized",
"message": "Bad token",
"attributes": {
"error": "Bad token"
}
})
for a few requests. But eventually 401 errors start getting high as no. of Threads increase, keeping Ramp Up time low. for eg: for 5 Requests Ramp Up time = 30 sec.
JMeter Script snapshot
I have checked, my Access Token call always return a different token which is used per new THREAD. so not sure where the issue is :(
So far I have not used any think times, maybe that is one of the issue, but not sure.
By looking at your http get response , The issue is caused most likely due to incorrect value of AccessToken.
Make sure you are passing correct AccessToken to get response.
IF you have a recorded script log, check where this access token originating from and make sure your regular expression extractor is extracting it correctly.
For more information on extracting variables and reusing it in the script you can read this article.

Outlook REST API 410 Error: SyncStateNotFound

I get a 410 when syncing messages:
{\"code\":\"SyncStateNotFound\",\"message\":\"The sync state
generation is not found; generation=1;[highest=4][4][2][3].\"}
This only occurs when syncing messages for select mailfolders on select accounts. It occurs when making a post-initial sync using the relevant delta token. I can recreate this via making
GET https://outlook.office365.com/api/v2.0/me/MailFolders('{folder_id}')/messages/?$deltaToken={delta_token}
In Microsoft's Outlook Sandbox.
Here are the literal steps it takes to reproduce deterministically:
1) Initial Message Sync:
GET https://outlook.office365.com/api/v2.0/me/MailFolders('{folder_id}')/messages
2) Sync with initial delta token:
GET https://outlook.office365.com/api/v2.0/me/MailFolders('{folder_id}')/messages/?$deltaToken={delta_token}
3) Sync with skip token until delta token:
GET https://outlook.office365.com/api/v2.0/me/MailFolders('{folder_id}')/messages/?$skipToken={skip_token}
4) ERROR OCCURS HERE: Mailfolder receives update, so I re-sync messages with delta token from (3). The call below throws a 410 and I can't sync messages.
GET https://outlook.office365.com/api/v2.0/me/MailFolders('{folder_id}')/messages/?$deltaToken={delta_token}
To reiterate: I've isolated this to just testing in the Outlook sandbox, and it still occurs. Testing as in making the GET call to sync (i.e., make perform (2)) using the deltaToken from (3) and its corresponding folderId as query parameters.
Dumb Mistake: Passed in initial delta token as opposed to current.

Resources