Skip to content
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

[Bug]: dotenv should not be initialized by alpaca #283

Open
2 tasks done
parris opened this issue Jan 25, 2025 · 0 comments
Open
2 tasks done

[Bug]: dotenv should not be initialized by alpaca #283

parris opened this issue Jan 25, 2025 · 0 comments

Comments

@parris
Copy link

parris commented Jan 25, 2025

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

When loading the alpaca-trade-api dotenv is called on the first line of dist/alpaca-trade-api.js

This means if you have a custom dotenv setup eg. different tokens for dev vs prod or multiple dotenv files you aren't able to guarantee a specific configuration. Depending on module load order, alpaca sometimes has won out. This has caused me to patch alpaca and delete that line.

My pnpm patch for reference

diff --git a/dist/alpaca-trade-api.js b/dist/alpaca-trade-api.js
index 85b69008eebcbd434a24cb01b53ebdb655d8fc2b..af8fcb41dd42096be2b66cda8b307fabb37e3f07 100644
--- a/dist/alpaca-trade-api.js
+++ b/dist/alpaca-trade-api.js
@@ -1,5 +1,5 @@
 "use strict";
-require("dotenv").config();
+// require("dotenv").config();
 const api = require("./api");
 const account = require("./resources/account");
 const position = require("./resources/position");

Expected Behavior

When I load alpaca, I can use my own method to load in environment variables and init them into alpaca. At minimum some way to disable this behavior would be great.

SDK Version I encountered this issue in

"@alpacahq/alpaca-trade-api": "^3.1.3"

Steps To Reproduce

1. Create a package with a 2 dotenv files, load them in a custom way eg:

import dotenv from "dotenv";

if (process.env.NODE_ENV === "development") {
  dotenv.config({ path: "../.env.dev" });
}

dotenv.config({ path: "../.env" });

2. Import this file and alpaca
3. Notice alpaca wins depending on dependency graph (I don't totally know what it takes for alapaca to get loaded first)

Filled out the Steps to Reproduce section?

  • I have entered valid steps to reproduce my issue or have attached a minimally reproducible case in code that shows my issue happening; and understand that without this my issue will be flagged as invalid and closed after 30 days.

Anything else?

Sorry for posting a bunch of issues at once - figured i drop in all the notes while i was here :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant