Git Product home page Git Product logo

batil's Introduction

Batil Logo

tests codecov Maven Central Kotlin License

Make your brokerage work for you.

Goals

  • 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 💰

Use

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.

Supported Brokers

Setup

E*TRADE

  1. Retrieve your credentials
  2. Setup Docker
  3. Verify your credentials
  4. Other Commands
  5. Troubleshooting

Credentials

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 Auto and for the topic select Sandbox 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 [email protected].

Docker

Docker is used to access a Chromium instance that can login to the E*TRADE website to retrieve the necessary OAuth keys.

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

Verify

  • You can clone the project locally and build the demo E*TRADE client (check the build/libs dir).
./gradlew fatJar
  • Using the sample provided, add a batil.yaml to 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.yaml into git.
  • Verify your account.
java -jar Batil-etrade.jar verify
  • By default the app runs in sandbox mode. Add the --production switch to use in production.
java -jar Batil-etrade.jar verify --production

Other Commands

For the full list of available options use the --help switch.

List Accounts
% java -jar Batil-etrade.jar list_accounts --production

Account ID (47246378)
Key: -i07qS52YOXHWSjf8hvZPA
Type: INDIVIDUAL
Name:
Status: ACTIVE
Description: Individual Brokerage
Get Balances
% 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
Lookup Tickers
% 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

Resources

So What’s a Batil Anyways?

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.