TheHardeep / fenix

A Python library for trading in the Indian Finance Sector with support for 15+ broker APIs.
GNU General Public License v3.0
19 stars 12 forks source link

Placing order #2

Closed rajkiranjeet closed 3 weeks ago

rajkiranjeet commented 1 month ago

i try to finvasia

Session Created Successfully Error creating session or placing order: Non-base32 digit found below is my code import pyotp from fenix.finvasia import finvasia

TOTP Secret and Credentials

totp_secret = "24242424"

Padding the secret if necessary

def pad_base32_secret(secret): missing_padding = len(secret) % 8 if missing_padding: secret += '=' * (8 - missing_padding) return secret

Pad the TOTP secret

padded_totp_secret = pad_base32_secret(totp_secret)

Generate TOTP Token

try: totp = pyotp.TOTP(padded_totp_secret) totp_token = totp.now() print(f"Generated TOTP Token: {totp_token}")

# Credentials for Finvasia
credentials = {
    "user_id": "FA9",
    "password": "",
    "api_key": "",
    "totp_token": totp_token,
    "imei": "abc1234",
    "vendor_code": "FA9_U"
}

# Step 1: Use Finvasia's create session method (if available)
# The session management will be internal to Finvasia
session = finvasia._session  # Use finvasia's session management
print("Session Created Successfully")

# Step 2: Create headers for the order
headers = finvasia.create_headers({
    "user_id": credentials["user_id"],
    "password": credentials["password"],
    "totpstr": credentials["totp_token"],  # Pass generated TOTP token
    "vendor_code": credentials["vendor_code"],
    "api_key": credentials["api_key"]
})

# Step 3: Place an order using the created session
order_response = finvasia.create_order_eq(
    exchange="NSE",
    symbol="RELIANCE",
    quantity=10,
    side="SELL",
    product="MIS",
    validity="DAY",
    variety="REGULAR",
    unique_id="NSEOrder",
    headers=headers,
    price=2840.0,
    trigger=2845.0
)

print("Order Response:")
print(order_response)

except Exception as e: print(f"Error creating session or placing order: {e}")

can u fnrm whats wrong also can we use this seession for websocket or geting LTP  ?
TheHardeep commented 4 weeks ago

you do not need to create the totp yourself, just add the totp_secret to the "totpstr" key in create_headers

rajkiranjeet commented 4 weeks ago

thanks wokring perfect but its ok for placing order hwo about live stream websocket if we get supertoken or session id something then we can mamage same seeion throughout process can u guide me about this

TheHardeep commented 3 weeks ago

This library does not include websockets for brokers, only REST APIs. Please keep your questions to REST APIs, you can follow the broker documentation for Websockets.