(20241230) Paper Trading auth added.

This commit is contained in:
2024-12-30 11:43:15 +05:30
parent e3d71965bb
commit e2976f0dfc
5 changed files with 298 additions and 6 deletions
@@ -163,8 +163,41 @@ async def request_oauth_authorization_url(
)
# Start by assuming failure:
success = False
auth_url = None
# ┏┓ ┏┓ ┏┳┓ ┓•
# ┣ ┏┓┏┓ ┃┃┏┓┏┓┏┓┏┓ ┃ ┏┓┏┓┏┫┓┏┓┏┓
# ┻ ┗┛┛ ┣┛┗┻┣┛┗ ┛ ┻ ┛ ┗┻┗┻┗┛┗┗┫
# ┛ ┛
if inbound_data.client == "paperTrading":
# Immediately save the details against that token id:
success = await current_app.paper_trading_controller.set_token_direct(
sql_conn = current_app.sql_writer,
mongo_data_conn = current_app.data_mongo,
auth_token = CoreAuthTokenModel(
serviceType = "stockTrading",
client = inbound_data.client,
authType = "auth",
user = kwargs["session_info"],
clientUserId = {
"username": inbound_data.auth.username
},
auth = inbound_data.auth.model_dump(),
status = "active",
syncFreq = 1500
),
token_notes = {
"username": inbound_data.auth.username
},
session_token = inbound_headers["X-Session-Token"]
)
# Check if things were successful:
if not success: auth_url = None
# ┏┓ ┏┓ ┓┓ ┓┏┓•
# ┣ ┏┓┏┓ ┏┛┏┓┏┓┏┓┏┫┣┓┏┓ ┃┫ ┓╋┏┓
# ┻ ┗┛┛ ┗┛┗ ┛ ┗┛┗┻┛┗┗┻ ┛┗┛┗┗┗
@@ -214,8 +247,8 @@ async def request_oauth_authorization_url(
# Done here:
return ResponseModel(
status_code = StatusCodes.OK if auth_url else StatusCodes.FAILED,
http_code = HttpCodes.SUCCESS if auth_url else HttpCodes.INTERNAL_SERVER_ERROR,
status_code = StatusCodes.OK if success else StatusCodes.FAILED,
http_code = HttpCodes.SUCCESS if success else HttpCodes.INTERNAL_SERVER_ERROR,
data = {
"client": inbound_data.client,
"authorizationUrl": auth_url
+7
View File
@@ -82,6 +82,7 @@ from controllers_v2.message.sms.savvy_bulk_sms_kenya import SavvyBulkSMSKenyaCon
# ---
from controllers_v2.finstitutions.trading.all_trading import AllTradingController
from controllers_v2.finstitutions.trading.zerodha_kite import ZerodhaKiteTradingController
from controllers_v2.finstitutions.trading.paper_trading import PaperTradingController
# ---
from controllers_v2.finstitutions.payments.all_payments import AllPaymentsController
from controllers_v2.finstitutions.payments.safaricom_mpesa_express import SafaricomMPesaExpressPaymentsController
@@ -466,6 +467,12 @@ async def app_startup(**kwargs):
alert_url = current_app.script_data["alerts"]["url"],
debug = enable_debugging
)
current_app.paper_trading_controller = PaperTradingController(
cache = current_app.module_cache,
http_client = current_app.http_client,
alert_url = current_app.script_data["alerts"]["url"],
debug = enable_debugging
)
# Finstitutions / Payments Controllers:
current_app.payments_controller = AllPaymentsController(