Skip to content

Adding new apis #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions test/SDK Tests/charge.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import upstox_client
from upstox_client.rest import ApiException
import const_file
configuration = upstox_client.Configuration()
configuration.access_token = const_file.access_token
api_version = '2.0'


api_instance = upstox_client.ChargeApi(upstox_client.ApiClient(configuration))
instrument_token = 'NSE_EQ|INE669E01016'
quantity = 10
product = 'D'
transaction_type = 'BUY'
price = 13.4


try:
# Brokerage details
api_response = api_instance.get_brokerage(instrument_token, quantity, product, transaction_type, price, api_version)
print(api_response)
except ApiException as e:
print("Exception when calling ChargeApi->get_brokerage: %s\n" % e)
1 change: 1 addition & 0 deletions test/SDK Tests/const_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
access_token = "access_token"
41 changes: 41 additions & 0 deletions test/SDK Tests/historical_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import upstox_client
from upstox_client.rest import ApiException

api_version = '2.0'

api_instance = upstox_client.HistoryApi()
instrument_key = 'NSE_EQ|INE669E01016'
interval = '1minute'
to_date = '2023-11-13'
from_date = '2023-11-12'
try:
api_response = api_instance.get_historical_candle_data1(instrument_key, interval, to_date,from_date, api_version)
print(api_response)
except ApiException as e:
print("Exception when calling HistoryApi->get_historical_candle_data: %s\n" % e)

api_version = '2.0'

api_instance = upstox_client.HistoryApi()
instrument_key = 'NSE_EQ|INE669E01016'
interval = 'month'
to_date = '2023-11-13'

try:
api_response = api_instance.get_historical_candle_data(instrument_key, interval, to_date, api_version)
print(api_response)
except ApiException as e:
print("Exception when calling HistoryApi->get_historical_candle_data: %s\n" % e)


api_version = '2.0'

api_instance = upstox_client.HistoryApi()
instrument_key = 'NSE_EQ|INE669E01016'
interval = '1minute'
try:

api_response = api_instance.get_intra_day_candle_data(instrument_key,interval,api_version)
print(api_response)
except ApiException as e:
print("Exception when calling HistoryApi->get_historical_candle_data: %s\n" % e)
31 changes: 31 additions & 0 deletions test/SDK Tests/market_information.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import upstox_client
from upstox_client.rest import ApiException
import const_file
configuration = upstox_client.Configuration()
configuration.access_token = const_file.access_token

api_instance = upstox_client.MarketHolidaysAndTimingsApi(upstox_client.ApiClient(configuration))

try:
api_response = api_instance.get_holidays()
print(api_response)
except ApiException as e:
print("Exception when calling MarketHolidaysAndTimingsApi: %s\n" %e)

try:
api_response = api_instance.get_holiday("2024-01-22")
print(api_response)
except ApiException as e:
print("Exception when calling MarketHolidaysAndTimingsApi: %s\n" %e)

try:
api_response = api_instance.get_exchange_timings("2024-01-22")
print(api_response)
except ApiException as e:
print("Exception when calling MarketHolidaysAndTimingsApi: %s\n" %e)

try:
api_response = api_instance.get_market_status("NSE")
print(api_response)
except ApiException as e:
print("Exception when calling MarketHolidaysAndTimingsApi: %s\n" %e)
36 changes: 36 additions & 0 deletions test/SDK Tests/market_quote.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import upstox_client
from upstox_client.rest import ApiException
import const_file
configuration = upstox_client.Configuration()
configuration.access_token = const_file.access_token
api_version = '2.0'

symbol = 'NSE_EQ|INE669E01016'
api_instance = upstox_client.MarketQuoteApi(upstox_client.ApiClient(configuration))


try:
api_response = api_instance.get_full_market_quote(symbol, api_version)
print(api_response)
except ApiException as e:
print("Exception when calling MarketQuoteApi->get_full_market_quote: %s\n" % e)

symbol = 'NSE_EQ|INE669E01016'
api_instance = upstox_client.MarketQuoteApi(upstox_client.ApiClient(configuration))


try:
api_response = api_instance.ltp(symbol, api_version)
print(api_response)
except ApiException as e:
print("Exception when calling MarketQuoteApi->get_full_market_quote: %s\n" % e)

symbol = 'NSE_EQ|INE669E01016'
api_instance = upstox_client.MarketQuoteApi(upstox_client.ApiClient(configuration))
interval='1d'

try:
api_response = api_instance.get_market_quote_ohlc(symbol,interval,api_version)
print(api_response)
except ApiException as e:
print("Exception when calling MarketQuoteApi->get_full_market_quote: %s\n" % e)
19 changes: 19 additions & 0 deletions test/SDK Tests/option_chain.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import upstox_client
from upstox_client.rest import ApiException
import const_file
configuration = upstox_client.Configuration()
configuration.access_token = const_file.access_token

api_instance = upstox_client.OptionsApi(upstox_client.ApiClient(configuration))

try:
api_response = api_instance.get_option_contracts("NSE_INDEX|Nifty 50")
print(api_response)
except ApiException as e:
print("Exception when calling MarketHolidaysAndTimingsApi: %s\n" %e)

try:
api_response = api_instance.get_put_call_option_chain("NSE_INDEX|Nifty 50", "2024-03-21")
print(api_response)
except ApiException as e:
print("Exception when calling MarketHolidaysAndTimingsApi: %s\n" %e)
88 changes: 88 additions & 0 deletions test/SDK Tests/order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import upstox_client
from upstox_client.rest import ApiException
import const_file
configuration = upstox_client.Configuration()
configuration.access_token = const_file.access_token
# api_instance = upstox_client.OrderApi(upstox_client.ApiClient(configuration))
# body = upstox_client.PlaceOrderRequest(1, "D", "DAY", 0.0, "string", "NSE_EQ|INE528G01035", "MARKET", "BUY", 0, 0.0, False)
# api_version = '2.0'
# try:
# api_response = api_instance.place_order(body, api_version)
# print(api_response)
# except ApiException as e:
# print("Exception when calling OrderApi->place_order: %s\n" % e)

# api_instance = upstox_client.OrderApi(upstox_client.ApiClient(configuration))
# body = upstox_client.PlaceOrderRequest(1, "D", "DAY", 20.0, "string", "NSE_EQ|INE528G01035", "LIMIT", "BUY", 0, 20.1, False)
# api_version = '2.0'
# try:
# api_response = api_instance.place_order(body, api_version)
# print(api_response)
# except ApiException as e:
# print("Exception when calling OrderApi->place_order: %s\n" % e)

# api_instance = upstox_client.OrderApi(upstox_client.ApiClient(configuration))
# body = upstox_client.ModifyOrderRequest(2, "DAY", 0, "231222010275930", "MARKET", 0, 0)
# api_version = '2.0' # str | API Version Header
#
# try:
# # Modify order
# api_response = api_instance.modify_order(body, api_version)
# print(api_response)
# except ApiException as e:
# print("Exception when calling OrderApi->modify_order: %s\n" % e)

#
# api_instance = upstox_client.OrderApi(upstox_client.ApiClient(configuration))
# order_id = '240318010654488'
# api_version = '2.0'
#
# try:
# # Cancel order
# api_response = api_instance.cancel_order(order_id, api_version)
# print(api_response)
# except ApiException as e:
# print("Exception when calling OrderApi->cancel_order: %s\n" % e)

# api_instance = upstox_client.OrderApi(upstox_client.ApiClient(configuration))
# api_version = '2.0'
# try:
# # Get order book
# api_response = api_instance.get_order_book(api_version)
# print(api_response)
# except ApiException as e:
# print("Exception when calling OrderApi->get_order_book: %s\n" % e)


# api_instance = upstox_client.OrderApi(upstox_client.ApiClient(configuration))
# api_version = '2.0'
# order_id = '240318010654488'
#
# try:
# api_response = api_instance.get_order_details(api_version, order_id=order_id)
# print(api_response)
# except ApiException as e:
# print("Exception when calling OrderApi->get_order_details: %s\n" % e)

# api_instance = upstox_client.OrderApi(upstox_client.ApiClient(configuration))
# api_version = '2.0'
#
# try:
# # Get trades
# api_response = api_instance.get_trade_history(api_version)
# print(api_response)
# except ApiException as e:
# print("Exception when calling OrderApi->get_trade_history: %s\n" % e)
#

api_instance = upstox_client.OrderApi(upstox_client.ApiClient(configuration))
order_id = '240318010654488'
api_version = '2.0'

try:
# Get trades for order
api_response = api_instance.get_trades_by_order(order_id, api_version)
print(api_response)
except ApiException as e:
print("Exception when calling OrderApi->get_trades_by_order: %s\n" % e)

32 changes: 32 additions & 0 deletions test/SDK Tests/portfolio.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import upstox_client
from upstox_client.rest import ApiException
import const_file
configuration = upstox_client.Configuration()
configuration.access_token = const_file.access_token

api_instance = upstox_client.PortfolioApi(upstox_client.ApiClient(configuration))
body = upstox_client.ConvertPositionRequest(instrument_token= "NSE_EQ|INE528G01035",quantity=1,new_product="I",old_product="D",transaction_type="BUY")
api_version = '2.0'

try:
# Convert Positions
api_response = api_instance.convert_positions(body, api_version)
print(api_response)
except ApiException as e:
print("Exception when calling PortfolioApi->convert_positions: %s\n" % e)

api_instance = upstox_client.PortfolioApi(upstox_client.ApiClient(configuration))

try:
api_response = api_instance.get_holdings(api_version)
print(api_response)
except ApiException as e:
print("Exception when calling ChargeApi->get_brokerage: %s\n" % e)

api_instance = upstox_client.PortfolioApi(upstox_client.ApiClient(configuration))

try:
api_response = api_instance.get_positions(api_version)
print(api_response)
except ApiException as e:
print("Exception when calling ChargeApi->get_brokerage: %s\n" % e)
49 changes: 49 additions & 0 deletions test/SDK Tests/trade_profit_loss.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import upstox_client
from upstox_client.rest import ApiException
import const_file
configuration = upstox_client.Configuration()
configuration.access_token = const_file.access_token

api_instance = upstox_client.TradeProfitAndLossApi(upstox_client.ApiClient(configuration))
segment = 'EQ'
financial_year = '2324' # str | Financial year for which data has been requested. Concatenation of last 2 digits of from year and to year Sample:for 2021-2022, financial_year will be 2122
api_version = '2.0' # str | API Version Header
from_date = '02-04-2023' # str | Date from which data needs to be fetched. from_date and to_date should fall under the same financial year as mentioned in financial_year attribute. Date in dd-mm-yyyy format (optional)
to_date = '20-03-2024' # str | Date till which data needs to be fetched. from_date and to_date should fall under the same financial year as mentioned in financial_year attribute. Date in dd-mm-yyyy format (optional)

try:
# Get Trade-wise Profit and Loss Report Data
api_response = api_instance.get_trade_wise_profit_and_loss_meta_data(segment, financial_year, api_version, from_date=from_date, to_date=to_date)
print(api_response)
except ApiException as e:
print("Exception when calling TradeProfitAndLossApi->get_trade_wise_profit_and_loss_data: %s\n" % e)

api_instance = upstox_client.TradeProfitAndLossApi(upstox_client.ApiClient(configuration))
segment = 'EQ'
financial_year = '2324' # str | Financial year for which data has been requested. Concatenation of last 2 digits of from year and to year Sample:for 2021-2022, financial_year will be 2122
page_number = 1
page_size = 4
api_version = '2.0' # str | API Version Header
from_date = '02-04-2023' # str | Date from which data needs to be fetched. from_date and to_date should fall under the same financial year as mentioned in financial_year attribute. Date in dd-mm-yyyy format (optional)
to_date = '20-03-2024' # str | Date till which data needs to be fetched. from_date and to_date should fall under the same financial year as mentioned in financial_year attribute. Date in dd-mm-yyyy format (optional)

try:
# Get Trade-wise Profit and Loss Report Data
api_response = api_instance.get_trade_wise_profit_and_loss_data(segment, financial_year, page_number, page_size, api_version, from_date=from_date, to_date=to_date)
print(api_response)
except ApiException as e:
print("Exception when calling TradeProfitAndLossApi->get_trade_wise_profit_and_loss_data: %s\n" % e)

api_instance = upstox_client.TradeProfitAndLossApi(upstox_client.ApiClient(configuration))
segment = 'EQ'
financial_year = '2324' # str | Financial year for which data has been requested. Concatenation of last 2 digits of from year and to year Sample:for 2021-2022, financial_year will be 2122
api_version = '2.0' # str | API Version Header
from_date = '02-04-2023' # str | Date from which data needs to be fetched. from_date and to_date should fall under the same financial year as mentioned in financial_year attribute. Date in dd-mm-yyyy format (optional)
to_date = '20-03-2024' # str | Date till which data needs to be fetched. from_date and to_date should fall under the same financial year as mentioned in financial_year attribute. Date in dd-mm-yyyy format (optional)

try:
# Get Trade-wise Profit and Loss Report Data
api_response = api_instance.get_profit_and_loss_charges(segment, financial_year, api_version, from_date=from_date, to_date=to_date)
print(api_response)
except ApiException as e:
print("Exception when calling TradeProfitAndLossApi->get_trade_wise_profit_and_loss_data: %s\n" % e)
23 changes: 23 additions & 0 deletions test/SDK Tests/user.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import upstox_client
from upstox_client.rest import ApiException
import const_file

configuration = upstox_client.Configuration()
configuration.access_token = const_file.access_token
api_version = '2.0'

api_instance = upstox_client.UserApi(upstox_client.ApiClient(configuration))

try:
# Get User Fund And Margin
api_response = api_instance.get_profile(api_version)
print(api_response)
except ApiException as e:
print("Exception when calling UserApi->get_user_fund_margin: %s\n" % e)

try:
# Get User Fund And Margin
api_response = api_instance.get_user_fund_margin(api_version)
print(api_response)
except ApiException as e:
print("Exception when calling UserApi->get_user_fund_margin: %s\n" % e)
Loading
Loading