Skip to main content

Official Python SDK for Pocketful APIs

Project description

Pocketfulapi-Python Library

Pocketfulapi-python is a Python library designed for traders and investors who want to streamline their workflow by automating or programmatically handling their trading activities on Pocketful. This library offers all the methods required for interacting with the trading APIs, and includes various features such as placing orders, fetching market data, and perform various other tasks crucial for managing a stock portfolio.

Features

  1. Place Orders: Easily place buy and sell orders for different instruments.
  2. Fetch Holdings: Retrieve current holdings in the portfolio.
  3. Fetch Positions: Get an overview of positions.
  4. Check Funds: Check the available balance in your trading account.
  5. Websockets: Fetch real-time data for different instruments

Installation

You can clone the repository using the below commands, make sure you have python installed on your system to use this library.

git clone https://github.com/pocketful-tech/Pocketfulapi-python.git
cd Pocketfulapi-python
pip install -r requirements.txt

Usage

Here’s a basic example of how to use the library, we have added this file in the repository:

from PocketfulAPI.pocketful import Pocketful

clientId = "<clientId>"            # pocketful account Client Id
accessToken = "<accessToken>"    # generate your access token from "https://api.pocketful.in/login"


# Create an Instance of Pocketful class, with that instance you can call all the methods required for trading, see pocketful docs for detailed documentation
pocket=Pocketful(clientId, accessToken)

data=pocket.getProfile()
print(data)

# Comment and uncomment the code accordingly to understand all the methods properly

# data=pocket.getPendingOrder()
# print(data)

# data=pocket.getCompletedOrder()
# print(data)

# data=pocket.getTradeBook()
# print(data)

# data = pocket.getOrderHistory("<oms_order_id>")
# print(data)


# getDematHoldings=pocket.getDematHoldings()
# print(getDematHoldings)

# getPositionsNetwise=pocket.getPositionsNetwise()
# print(getPositionsNetwise)


# getPositionsDaywise=pocket.getPositionsDaywise()
# print(getPositionsDaywise)




# createBasket=pocket.createBasket({"login_id":clientId,"name":"pocketful001","type":"NORMAL","product_type":"ALL","order_type":"ALL"})
# print(createBasket)

# data = pocket.addInstrumentToBasket({
#         "basket_id": "eb3d2244-af73-4f05-a70b-a3518b4d321d",
#         "name": "pocketful001",
#         "order_info": {
#             "client_id": "<client id>",
#             "disclosedQuantity": 0,
#             "exchange": "NSE",
#             "execution_type": "REGULAR",
#             "instrument_token": 14366,
#             "order_side": "BUY",
#             "order_type": "MARKET",
#             "price": 0,
#             "product": "MIS",
#             "quantity": 1,
#             "series": "EQ",
#             "trading_symbol": "IDEA-EQ",
#             "trigger_price": 0,
#             "underlying_token": "14366",
#             "validity": "DAY",
#             "user_order_id": 10002
#         }
#      }
# )



# fetchBasket=pocket.fetchBasket()
# print(fetchBasket)

# renameBasket=pocket.renameBasket({"basket_id":"6bc753e5-b7d1-4ebb-94ac-36c751cedfbd","name":"yash"})
# print(renameBasket)

# deleteBasket=pocket.deleteBasket({"BasketId":"6bc753e5-b7d1-4ebb-94ac-36c751cedfbd","BasketName":"yash"})
# print(deleteBasket)

## !! Place Buy order
# placeOrder=pocket.placeOrder({
#     "exchange": "NSE",
#     "instrument_token": "14366",
#     "client_id": clientId,
#     "order_type": "MARKET",
#     "amo": True,
#     "price": 13,"quantity": 1,
#     "disclosed_quantity": 0,
#     "validity": "DAY",
#     "product": "CNC",
#     "order_side": "BUY",
#     "device": "WEB",
#     "user_order_id": 10002,
#     "trigger_price": 0,
#     "execution_type": "AMO"
#     })
# print(placeOrder)



# !! SELL order
# placeOrder=pocket.placeOrder({

#     "exchange": "NSE",
#     "instrument_token": "10666",
#     "client_id": "clintId",
#     "order_type": "MARKET",
#     "amo": False,
#     "price": 34.8,
#     "quantity": 1,
#     "disclosed_quantity": 0,
#     "validity": "DAY",
#     "product": "MIS",
#     "order_side": "SELL",
#     "device": "WEB",
#     "user_order_id": 10002,
#     "trigger_price": 0,
#     "execution_type": "REGULAR"

#     })
# print(placeOrder)


# # 



# # !! Condition BO  ordering

# conditional_order=pocket.placeConditionalOrder( {
#     "client_id": "clintId",
#     "device": "WEB",
#     "disclosed_quantity": 0,
#     "exchange": "NSE",
#     "execution_type": "CO",
#     "instrument_token": "10666",
#     "is_trailing": True,
#     "order_side": "BUY",
#     "order_type": "LIMIT",
#     "price": 77.9,
#     "product": "MIS",
#     "quantity": 1,
#     "square_off_value": 1,
#     "stop_loss_value": 1,
#     "trailing_stop_loss": "0.05",
#     "trigger_price": 0,
#     "user_order_id": 10002,
#     "validity": "DAY"
# })

# print(conditional_order)

# sellconditional_order=pocket.placeConditionalOrder( {
#     "client_id": "clintId",
#     "device": "WEB",
#     "disclosed_quantity": 0,
#     "exchange": "NSE",
#     "execution_type": "BO",
#     "instrument_token": "10666",
#     "is_trailing": True,
#     "order_side": "SELL",
#     "order_type": "LIMIT",
#     "price": 77.9,
#     "product": "MIS",
#     "quantity": 1,
#     "square_off_value": 1,
#     "stop_loss_value": 1,
#     "trailing_stop_loss": "0.05",
#     "trigger_price": 0,
#     "user_order_id": 10002,
#     "validity": "DAY"
# })

# print(sellconditional_order)


# modifyConditionalOrder=pocket.modifyConditionalOrder( {"exchange":"NSE","instrument_token":10666,"client_id":"","order_type":"LIMIT","price":80.9,"quantity":1,"disclosed_quantity":0,"validity":"DAY","product":"MIS","oms_order_id":"20231211-1762","exchange_order_id":"1200000019706097","filled_quantity":0,"remaining_quantity":1,"last_activity_reference":1386762580344098300,"trigger_price":0,"stop_loss_value":1,"square_off_value":"2","trailing_stop_loss":0,"is_trailing":False,"execution_type":"BO"})

# print(modifyConditionalOrder)


# cancelConditionalOrder=pocket.cancelConditionalOrder({"oms_order_id":"20231211-1897","execution_type":"BO","exchange_order_id":"1200000022379287","leg_order_indicator":"ENTRY","status":"MODIFY_CONFIRMED","client_id":clientId})
# print(cancelConditionalOrder)



# data=pocket.getFunds()
# print(data)


# data=pocket.getMarketdata("NFO","45835")   
# print(data)

# data=pocket.getFNOdata("NFO","45835")   
# print(data)


# ltp=pocket.getLtp("BFO",845835)
# print("ltp ",ltp)

# ltp=pocket.getLtp("NSE","45827")
# print("ltp ",ltp)


# data=pocket.getMarketdata("NSE","3045") 
# print(data)

# data=pocket.getClosePrice("NSE","3045")
# print(data)

# data=pocket.getOptionChain(3045,6,data["data"])
# print(data)





# ## <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< WebSocket >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>


# from PocketfulAPI.pacefinwebsocket import PocketfulSocket
# import time


# client_id = "<client_id>"
# access_token = "<access_Token>"

# conn = PocketfulSocket(client_id,access_token)

# ws_status = conn.run_socket()


# exchange_code = {
#     "NSE" : 1,
#     "NFO" : 2,
#     "CDS" : 3,
#     "MCX" : 4,
#     "BSE" : 6,
#     "BFO" : 7
# }


# marketdata_payload= {'exchangeCode': 4, 'instrumentToken': 428177}
# conn.subscribe_detailed_marketdata(marketdata_payload)

# snapquotedata_payload = {'exchangeCode': 1, 'instrumentToken': 3045}
# conn.subscribe_snapquote_data(snapquotedata_payload,)


# # For subscribe Multiple token 
# # For subscribe Multiple token 
# conn.subscribe_multiple_detailed_marketdata(
#         [

#             {'exchangeCode': 2, 'instrumentToken': 35648},
#             {'exchangeCode': 2, 'instrumentToken': 35649},
#             {'exchangeCode': 2, 'instrumentToken': 35650},
#             {'exchangeCode': 2, 'instrumentToken': 35651},


#         ]
#     )



# i =0
# while True:
#     time.sleep(1)
#     detailed_market_data = conn.read_detailed_marketdata()
#     print("detailed_market_data ", detailed_market_data)

    

#     # print("multiple channels subscribed ....")

#     detailed_market_data = conn.read_multiple_detailed_marketdata()
#     print( detailed_market_data )


#     # snapquote_data = conn.read_snapquote_data()
#     # print(detailed_market_data)
#     i = i + 1
#     print("==================================")
#     if i > 5:
#         print("unsubscribe marketdata")
#         conn.unsubscribe_detailed_marketdata(marketdata_payload)
#         print("unsubscribe snapquote")
#         conn.unsubscribe_detailed_marketdata(snapquotedata_payload)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pocketful-0.1.1.tar.gz (15.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pocketful-0.1.1-py3-none-any.whl (14.1 kB view details)

Uploaded Python 3

File details

Details for the file pocketful-0.1.1.tar.gz.

File metadata

  • Download URL: pocketful-0.1.1.tar.gz
  • Upload date:
  • Size: 15.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.5

File hashes

Hashes for pocketful-0.1.1.tar.gz
Algorithm Hash digest
SHA256 534edcf26e0151dea44efa9e7feb4540ce359c9c62be4c80790c2371bbb20756
MD5 91d229ab2eba9481a98037b218f76a8a
BLAKE2b-256 046cfb49d12382418e34776e018387355d4aea20f3f637b1b73714ad3e6ff5ce

See more details on using hashes here.

File details

Details for the file pocketful-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: pocketful-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 14.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.5

File hashes

Hashes for pocketful-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6401bf37db051d8615500116188be93f9ca439839278496aa8cf06774d375966
MD5 862b067a956d63075d640ab6a93f86f0
BLAKE2b-256 fc00dec224ff5f3f23e9f5064ec1cd6620115c4ed65532dc92ad48581536aa06

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page