Make your brokerage work for you.
- Connect to your preferred broker in Kotlin or Java 💁
- Provide a single interface for accessing multiple brokers’ APIs 🏪
- Accelerate the development of algorithmic trading for the JVM 💰
Before you bring Batil into your own project you’ll want to first retrieve your credentials from your broker and setup Docker. Then add the dependency to your Gradle file.
build.gradle.kts
repositories {
mavenCentral()
}
dependencies {
implementation("com.seansoper:batil:^1.0.4")
}You can then use the full-suite of service endpoints.
val client = EtradeClient( "key", "secret", "username", "password", EtradeClient.Endpoint.LIVE) client.accounts.list()?.let { it.first().accountIdKey?.let { accountIdKey -> val service = client.orders val previewRequest = buyEquityLimit("PLTR", 21f, 100) service.createPreview(accountIdKey, previewRequest)?.let { previewOrderResponse -> service.placeOrder(accountIdKey, previewRequest, previewOrderResponse)?.let { completedOrder -> println("Purchased 100 shares of PLTR at 21ドル") println(completedOrder) } } } }
More examples of usage can be found here. Full documentation available here.
You’ll need to request both a sandbox and production API consumer key and secret from the API team.
- Sign into your E*TRADE account and head over to Customer Service ➡ Message Center ➡ Contact Us. From there select the account you want to associate with your API key. For the subject, select
API Sandbox Autoand for the topic selectSandbox Key. Expect to hear back within a few hours. - To access the production API you’ll need to send a signed copy of the Developer Agreement to etradeapi@etrade.com.
Docker is used to access a Chromium instance that can login to the E*TRADE website to retrieve the necessary OAuth keys.
- Download Docker
- Run the following command to start the container:
docker container run -d -p 9222:9222 zenika/alpine-chrome \
--no-sandbox \
--remote-debugging-address=0.0.0.0 \
--remote-debugging-port=9222 \
--user-agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36" \
about:blank- You can clone the project locally and build the demo E*TRADE client (check the
build/libsdir).
./gradlew fatJar
- Using the sample provided, add a
batil.yamlto the directory where you intend to run the JAR file. Substitute the default values with the correct values. - Important Ensure you never check your version of
batil.yamlinto git. - Verify your account.
java -jar Batil-etrade.jar verify
- By default the app runs in sandbox mode. Add the
--productionswitch to use in production.
java -jar Batil-etrade.jar verify --production
For the full list of available options use the --help switch.
% java -jar Batil-etrade.jar list_accounts --production Account ID (47246378) Key: -i07qS52YOXHWSjf8hvZPA Type: INDIVIDUAL Name: Status: ACTIVE Description: Individual Brokerage
% java -jar Batil-etrade.jar get_balances -i07qS52YOXHWSjf8hvZPA --production Account ID Key (-i07qS52YOXHWSjf8hvZPA) Net cash: 3470.154 Cash balance: 0.0 Margin balance: -1743.5747 Cash buying power: 3470.154 Margin buying power: 26233.848 Cash available for investment: 0.0 Cash available for withdrawal: 0.0
% java -jar Batil-etrade.jar lookup pltr tsla clov --production PALANTIR TECHNOLOGIES INC CL A Last bid: 24.35 Earnings per share: -0.7414 Total volume: 26106710 TESLA INC COM Last bid: 818.32 Earnings per share: 1.9124 Total volume: 12247170 CLOVER HEALTH INVESTMENTS CORP COM CL A Last bid: 8.12 Earnings per share: -0.9715 Total volume: 18767897
The Batil was a coastal ship in use for hundreds of years up until the 1950s. Serving primarily as a merchant vessel, it was ubiquitous throughout South Asia and the Middle East helping to create a resilient trade network.