Jugaad Trader - Upstox documentation

Initialize

Using credentials configuration

If you have saved your user id, password using jtrader upstox savecreds, use below method-

from jugaad_trader import Upstox
u = Upstox()
u.load_creds()

Credentials in python code

You can directly provide user id, password at the time of initialization, as below

from jugaad_trader import Upstox
u = Upstox(client_id="CLIENT_ID",
            password="PASSWORD",
            twofa="TWOFA")

Logging In

Next step is to log in-

status = u.login()
print(status)

Output-

{'timestamp': xxxxxxxxxx,
 'response_type': 'client_login2fa',
 'guid': 'xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx',
 'data': {'success': True,
  'statusCode': 20,
  'message': '2FA Successful',
  'login_key': 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'}}

Get order book

orders = u.get_order_history()
print(orders['data'])

Output

{'ORDER-NUMBER': [
    {
    'cta': [2],
    'ctr':148,
    'client_id':'CLIENT-ID',
    'exchange':'NSE_EQ',
    'token':'3045',
    'product':'OCO',
    'order_type':'L',
    'duration':'DAY',
    'price': '203.00',
    'trigger_price': '0',
    'quantity': 1,
    'disclosed_quantity': 0,
    'side': 'B',
    'avg_price': '0',
    'traded_quantity': 0,
    'pending_quantity': 0,
    'message': 'The markets are closed. Kindly place this order during market hours.',
    'exchange_order_id': '',
    'syom_order_id': 'NA',
    'order_number': 'ORDER-NUMBER',
    'timestamp': 'xx/xx/2020,xx:xx:xx',
    'exchange_timestamp': '--',
    'status': 'rejected',
    'time_in_micro': 'xxxxxxxxxxxx',
    'is_amo': False,
    'order_complexity': 'OCO',
    'request_id': '1',
    'valid_date': '--',
    'tag': 'JWEB|UNDEFINED',
    'comments': 'PLACE ORDER :: xxxx|NSE_EQ|3045|EQ|I|203|1|B|OCO|WEB|IP-xxx-xx-xx-xx|xxxxxxxxxx',
    'fill_id': '',
    'original_message': 'ADAPTER is down',
    '_amo': False
    }]}

You can see the order status as rejected, because I had placed the order outside trading hours.

Get Positions

positions = u.get_positions()
print(positions['data])

Output-

[]

As I dont have any active positions, I’m notting getting an empty list. If you have active positions, you should get relevant position data.

Get Holdings

holdings = u.get_holdings(series="EQ", product="D")
print(holdings['data'])

Output-

[]

Place order

Work in progress: Currently this function places the order and waits indefinitely for response. please track this issue for resolution.

params = {'exchange': 'NSE_EQ',
            'token': '3045',
            'symbol': 'SBIN',
            'series': 'EQ',
            'is_amo': False,
            'order_complexity': 'OCO',
            'order_type': 'L',
            'product': 'I',
            'duration': 'DAY',
            'transaction_type': 'B',
            'price': '203',
            'trigger_price': '0',
            'disclosed_quantity': '0',
            'quantity': '1',
            'square_off': '1',
            'stop_loss': '1',
            'trailing_ticks': '0'}
u.place_order(**params)

Back to jugaad-trader home