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.
- Python SDK
- Node.js SDK
- Java SDK
- PHP SDK
configuration = upstox_client.Configuration(sandbox=True)
configuration.access_token = 'SANDBOX_ACCESS_TOKEN'
let sandboxClient = new UpstoxClient.ApiClient(true);
sandboxClient.authentications["OAUTH2"].accessToken = "SANDBOX_ACCESS_TOKEN";
boolean sandbox = true;
ApiClient sandboxClient = new ApiClient(sandbox);
OAuth OAUTH2 = (OAuth) sandboxClient.getAuthentication("OAUTH2");
OAUTH2.setAccessToken("SANDBOX_ACCESS_TOKEN");
Configuration.setDefaultApiClient(sandboxClient);
$config = Upstox\Client\Configuration::getDefaultConfiguration(sandbox:true)->setAccessToken("SANDBOX_ACCESS_TOKEN");
Complete example to Place an Order in Sandbox Modeβ
- Python SDK
- Node.js SDK
- Java SDK
- PHP SDK
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)
let UpstoxClient = require("upstox-js-sdk");
let sandboxClient = new UpstoxClient.ApiClient(true);
sandboxClient.authentications["OAUTH2"].accessToken = "SANDBOX_ACCESS_TOKEN";
let apiInstance = new UpstoxClient.OrderApiV3();
let body = new UpstoxClient.PlaceOrderV3Request(1,UpstoxClient.PlaceOrderV3Request.ProductEnum.D,
UpstoxClient.PlaceOrderV3Request.ValidityEnum.DAY, 0,"NSE_EQ|INE528G01035",UpstoxClient.PlaceOrderV3Request.OrderTypeEnum.MARKET,
UpstoxClient.PlaceOrderV3Request.TransactionTypeEnum.BUY,0,0,true);
let opt = {"slice": true}
apiInstance.placeOrder(body, opt, (error, data, response) => {
if (error) {
console.log("error->" + JSON.stringify(error));
} else {
console.log('API called successfully. Returned data: ' + JSON.stringify(data));
}
});
import com.upstox.ApiClient;
import com.upstox.ApiException;
import com.upstox.Configuration;
import com.upstox.api.*;
import com.upstox.auth.OAuth;
import io.swagger.client.api.OrderApiV3;
public class Main{
public static void main(String[] args) {
boolean sandbox = true;
ApiClient sandboxClient = new ApiClient(sandbox);
OAuth OAUTH2 = (OAuth) sandboxClient.getAuthentication("OAUTH2");
OAUTH2.setAccessToken("SANDBOX_ACCESS_TOKEN");
Configuration.setDefaultApiClient(sandboxClient);
OrderApiV3 orderApiV3 = new OrderApiV3();
PlaceOrderV3Request body = new PlaceOrderV3Request();
body.setQuantity(10);
body.setProduct(PlaceOrderV3Request.ProductEnum.D);
body.setValidity(PlaceOrderV3Request.ValidityEnum.DAY);
body.setPrice(9F);
body.setTag("string");
body.setInstrumentToken("NSE_EQ|INE669E01016");
body.orderType(PlaceOrderV3Request.OrderTypeEnum.LIMIT);
body.setTransactionType(PlaceOrderV3Request.TransactionTypeEnum.BUY);
body.setDisclosedQuantity(0);
body.setTriggerPrice(0F);
body.setIsAmo(false);
body.setSlice(true);
try {
PlaceOrderV3Response result = orderApiV3.placeOrder(body);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling OrderApi#placeOrder ");
e.printStackTrace();
}
}
}
$config = Upstox\Client\Configuration::getDefaultConfiguration(sandbox:true)->setAccessToken("SANDBOX_ACCESS_TOKEN");
$apiInstance = new Upstox\Client\Api\OrderApi(
new GuzzleHttp\Client(),
$config
);
$body = new \Upstox\Client\Model\PlaceOrderRequest();
$body->setQuantity(1);
$body->setProduct("D");
$body->setValidity("DAY");
$body->setPrice(0);
$body->setTag("string");
$body->setInstrumentToken("NSE_EQ|INE669E01016");
$body->setOrderType("MARKET");
$body->setTransactionType("BUY");
$body->setDisclosedQuantity(0);
$body->setTriggerPrice(0);
$body->setIsAmo(false);
try {
$result = $apiInstance->placeOrder($body,"2.0");
print($result);
} catch (Exception $e) {
print($e->getMessage());
}
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