Skip to main content

Building with Sandbox Mode

We recommend using Sandbox Mode for building and testing your apps, as it offers greater flexibility bypassing trading window limitations. This allows for seamless testing without real-market constraints.

πŸ”— Learn more about sandbox benefits: Sandbox Documentation

Steps to Use Sandbox Mode in the SDK​

Step 1: Create a Sandbox Access Token​

To use the sandbox environment, you must first create a sandbox app. If you haven’t created one yet, follow the instructions to set up your app and generate a sandbox access token.

πŸ”— Create a Sandbox App & Generate Token: Sandbox Access Token Guide

Step 2: Initialize a Sandbox Instance​

Once you have the sandbox access token, you can create a sandbox instance in your preferred programming language. For SDK users, switching between sandbox and live mode is effortless - just toggle a configuration setting.

configuration = upstox_client.Configuration(sandbox=True)
configuration.access_token = 'SANDBOX_ACCESS_TOKEN'

Complete example to Place an Order in Sandbox Mode​

import upstox_client
from upstox_client.rest import ApiException

configuration = upstox_client.Configuration(sandbox=True)
configuration.access_token = 'SANDBOX_ACCESS_TOKEN'

api_instance = upstox_client.OrderApiV3(upstox_client.ApiClient(configuration))
body = upstox_client.PlaceOrderV3Request(quantity=1, product="D",validity="DAY", price=9.12, tag="string", instrument_token="NSE_EQ|INE669E01016", order_type="LIMIT",
transaction_type="BUY", disclosed_quantity=0, trigger_price=0.0, is_amo=True, slice=True)

try:
api_response = api_instance.place_order(body)
print(api_response)
except ApiException as e:
print("Exception when calling OrderApi->place_order: %s\n" % e)
NOTE

We are actively expanding the suite of Sandbox APIs to enable seamless integration without market restrictions. This is a work in progress, and we aim to include all APIs over time. If an API is not yet available in Sandbox, please switch to live mode for full functionality.

For a list of APIs available in sandbox mode, refer to:
πŸ”— Sandbox-Enabled APIs