1. Go to this page and download the library: Download upstox/upstox-php-sdk library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Upstox\Client\Configuration;
use Upstox\Client\Api\OrderApiV3;
use Upstox\Client\Model\PlaceOrderV3Request;
$config = Configuration::getDefaultConfiguration()->setAccessToken('ACCESS_TOKEN');
$apiInstance = new OrderApiV3(new GuzzleHttp\Client(), $config);
$body = new PlaceOrderV3Request();
$body->setQuantity(1);
$body->setProduct("D");
$body->setValidity("DAY");
$body->setPrice(0);
$body->setInstrumentToken("NSE_EQ|INE528G01035");
$body->setOrderType("MARKET");
$body->setTransactionType("BUY");
$body->setDisclosedQuantity(0);
$body->setTriggerPrice(0);
$body->setIsAmo(false);
$body->setSlice(true);
try {
$result = $apiInstance->placeOrder($body, "web", "your-algo-name");
print($result);
} catch (Exception $e) {
echo "Exception when calling OrderApiV3->placeOrder: " . $e->getMessage() . "\n";
}
use Upstox\Client\Configuration;
use Upstox\Client\Feeder\MarketDataStreamerV3;
use Revolt\EventLoop;
function on_message($streamer, $data)
{
print($data);
}
$config = Configuration::getDefaultConfiguration()->setAccessToken(<ACCESS_TOKEN>);
$streamer = new MarketDataStreamerV3($config, ["NSE_INDEX|Nifty 50", "NSE_INDEX|Nifty Bank"], "full");
$streamer->on("message", 'on_message');
$streamer->connect();
EventLoop::run();
use Upstox\Client\Configuration;
use Upstox\Client\Feeder\MarketDataStreamerV3;
use Revolt\EventLoop;
function on_open($streamer)
{
print("Connection Established");
$streamer->subscribe(["NSE_INDEX|Nifty 50", "NSE_INDEX|Nifty Bank"], "full");
}
function on_message($streamer, $data)
{
print($data);
}
$config = Configuration::getDefaultConfiguration()->setAccessToken(<ACCESS_TOKEN>);
$streamer = new MarketDataStreamerV3($config);
$streamer->on("open", 'on_open');
$streamer->on("message", 'on_message');
$streamer->connect();
EventLoop::run();
use Upstox\Client\Configuration;
use Upstox\Client\Feeder\MarketDataStreamerV3;
use Revolt\EventLoop;
use function Amp\delay;
function on_open($streamer)
{
print("Connection Established");
$streamer->subscribe(["NSE_INDEX|Nifty 50"], "full");
delay(5);
$streamer->subscribe(["NSE_INDEX|Nifty Bank"], "full");
}
function on_message($streamer, $data)
{
print($data);
}
$config = Configuration::getDefaultConfiguration()->setAccessToken(<ACCESS_TOKEN>);
$streamer = new MarketDataStreamerV3($config);
$streamer->on("open", 'on_open');
$streamer->on("message", 'on_message');
$streamer->connect();
EventLoop::run();
use Upstox\Client\Configuration;
use Upstox\Client\Feeder\MarketDataStreamerV3;
use Revolt\EventLoop;
use function Amp\delay;
function on_open($streamer)
{
print("Connection Established");
$streamer->subscribe(["NSE_EQ|INE020B01018", "NSE_EQ|INE467B01029"], "full_d30");
delay(5);
$streamer->unsubscribe(["NSE_EQ|INE020B01018", "NSE_EQ|INE467B01029"]);
}
function on_message($streamer, $data)
{
print($data);
}
$config = Configuration::getDefaultConfiguration()->setAccessToken(<ACCESS_TOKEN>);
$streamer = new MarketDataStreamerV3($config);
$streamer->on("open", 'on_open');
$streamer->on("message", 'on_message');
$streamer->connect();
EventLoop::run();
use Upstox\Client\Configuration;
use Upstox\Client\Feeder\MarketDataStreamerV3;
use Revolt\EventLoop;
use function Amp\delay;
function on_open($streamer)
{
print("Connection Established");
$streamer->subscribe(["NSE_EQ|INE020B01018", "NSE_EQ|INE467B01029"], "full_d30");
delay(5);
$streamer->changeMode(
["NSE_EQ|INE020B01018", "NSE_EQ|INE467B01029"], "ltpc");
}
function on_message($streamer, $data)
{
print($data);
}
$config = Configuration::getDefaultConfiguration()->setAccessToken(<ACCESS_TOKEN>);
$streamer = new MarketDataStreamerV3($config);
$streamer->on("open", 'on_open');
$streamer->on("message", 'on_message');
$streamer->connect();
EventLoop::run();
use Upstox\Client\Configuration;
use Upstox\Client\Feeder\MarketDataStreamerV3;
use Revolt\EventLoop;
function on_reconnectstopped($streamer, $data)
{
print($data);
}
$config = Configuration::getDefaultConfiguration()->setAccessToken(<ACCESS_TOKEN>);
$streamer = new MarketDataStreamerV3($config);
$streamer->on("autoReconnectStopped", 'on_reconnectstopped');
$streamer->autoReconnect(false);
$streamer->connect();
EventLoop::run();
use Upstox\Client\Configuration;
use Upstox\Client\Feeder\MarketDataStreamerV3;
use Revolt\EventLoop;
$config = Configuration::getDefaultConfiguration()->setAccessToken(<ACCESS_TOKEN>);
$streamer = new MarketDataStreamerV3($config);
$streamer->autoReconnect(true, 10, 3);
$streamer->connect();
EventLoop::run();
use Upstox\Client\Configuration;
use Upstox\Client\Feeder\PortfolioDataStreamer;
use Revolt\EventLoop;
function on_message($streamer, $data)
{
print($data);
}
$config = Configuration::getDefaultConfiguration()->setAccessToken(<ACCESS_TOKEN>);
$streamer = new PortfolioDataStreamer($config);
$streamer->on("message", 'on_message');
$streamer->connect();
EventLoop::run();
use Upstox\Client\Configuration;
use Upstox\Client\Feeder\PortfolioDataStreamer;
use Revolt\EventLoop;
function on_message($streamer,$data)
{
print("on_message= " . ($data) . "\n");
}
$config = Upstox\Client\Configuration::getDefaultConfiguration()->setAccessToken(<ACCESS_TOKEN>);
$streamer = new PortfolioDataStreamer(
$config,
orderUpdate: true,
holdingUpdate: true,
positionUpdate: true,
gttUpdate: true
);
$streamer->on("message", 'on_message');
$streamer->connect();
EventLoop::run();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.