Created
April 18, 2025 09:11
-
-
Save jongan69/fd6090d6128788a556d784ec342af85f to your computer and use it in GitHub Desktop.
Automate Deposit and Withdrawals into alpaca account
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
import os | |
import requests | |
from dotenv import load_dotenv | |
load_dotenv(override=True) | |
async def transfer_to_alpaca(amount, direction): | |
try: | |
direction = "INCOMING" if direction == "IN" else "OUTGOING" | |
relationship_id = os.getenv("ALPACA_RELATIONSHIP_ID") | |
transfer_api = os.getenv("ALPACA_TRANSFER_API") | |
headers = { | |
"Authorization": f"Bearer {os.getenv('ALPACA_BEARER_TOKEN')}" | |
} | |
data = { | |
"transfer_type": "ach", | |
"direction": "INCOMING", | |
"relationship_id": relationship_id, | |
"amount": amount | |
} | |
response = requests.post(transfer_api, headers=headers, json=data) | |
print(response.json()) | |
except Exception as e: | |
print(e) | |
if __name__ == "__main__": | |
asyncio.run(transfer_to_alpaca(10, "IN")) | |
asyncio.run(transfer_to_alpaca(10, "OUT")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment