Configuring client¶
In our examples, credentials are loaded from a JSON file. However, there are multiple ways to configure LimeClient and you can use any of the ways you like.
Initializing the client is a one-time job so there are no default values. You must explicitly set all settings, including urls. That way you can easily change between paper trading and live accounts.
Using credentials in json file (used in examples)
Structure of JSON file is:
{
"username": "<your_username>",
"password": "<your_password>",
"client_id": "<client_id>",
"client_secret": "<client_secret>",
"grant_type": "password",
"base_url": "https://api.lime.co",
"auth_url": "https://auth.lime.co"
}
1from lime_trader import LimeClient
2
3client = LimeClient.from_file("credentials.json")
Using json string. This might be useful if you don’t want to use a file with credentials or you want to inject credentials using an environment variable:
Using JSON string directly:
1from lime_trader import LimeClient
2
3client = LimeClient.from_json("""{
4 "username": "<your_username>",
5 "password": "<your_password>",
6 "client_id": "<client_id>",
7 "client_secret": "<client_secret>",
8 "grant_type": "password",
9 "base_url": "https://api.lime.co",
10 "auth_url": "https://auth.lime.co"
11}""")
Using JSON from environment:
1import os
2from lime_trader import LimeClient
3
4json_str = os.environ.get("LIME_JSON_CREDENTIALS")
5client = LimeClient.from_json(json_str)
Using Python dictionary. If you are fetching credentials from some credentials store or getting them from an external source, you can construct them as a Python dictionary:
1from lime_trader import LimeClient
2
3def get_credentials():
4 return {
5 "username": "<your_username>",
6 "password": "<your_password>",
7 "client_id": "<client_id>",
8 "client_secret": "<client_secret>",
9 "grant_type": "password",
10 "base_url": "https://api.lime.co",
11 "auth_url": "https://auth.lime.co"
12 }
13
14credentials = get_credentials()
15client = LimeClient.from_dict(credentials)
From environment. If you are injecting credentials as environment variables you can use the from_env method to initialize client:
The following environment variables must be set for client to initialize properly:
LIME_SDK_USERNAME - username
LIME_SDK_PASSWORD - password
LIME_SDK_CLIENT_ID - client id
LIME_SDK_CLIENT_SECRET - client secret
LIME_SDK_GRANT_TYPE - grant type. Usually password
LIME_SDK_BASE_URL - base url for the Lime REST API
LIME_SDK_AUTH_URL - url for the Lime Authorization server
1from lime_trader import LimeClient
2
3client = LimeClient.from_env()
From .env file. If you are loading credentials from an .env file you can use the from_env_file method. An ENV file is a file that contains key value pairs. Example with required keys:
LIME_SDK_USERNAME=username
LIME_SDK_PASSWORD=password
LIME_SDK_CLIENT_ID=client_id
LIME_SDK_CLIENT_SECRET=secret
LIME_SDK_GRANT_TYPE=password
LIME_SDK_BASE_URL=https://api.lime.co
LIME_SDK_AUTH_URL=https://auth.lime.co
1from lime_trader import LimeClient
2
3client = LimeClient.from_env_file(".env")
Instantiate it yourself. If none of the above methods work for you, you can always create a credentials object and instantiate client yourself:
1from lime_trader import LimeClient
2
3cr = Credentials(username="your_username", password="your_password",
4 client_id="your_client_id",
5 client_secret="your_client_password",
6 grant_type="password")
7client = LimeClient(base_url="https://api.lime.co/",
8 credentials=cr,
9 auth_url="https://auth.lime.co")