Code Monkey home page Code Monkey logo

webull-client's Introduction

Webull Client

Master Pipeline Status: pipeline status

Dev Pipeline Status: pipeline status

About

A Golang library for the Webull brokerage.

Example Usage

Get Authorization

First set some environment variables:

export WEBULL_USERNAME='[email protected]'
export WEBULL_PASSWORD='SuperStrongPasswerrrdd12345'
export WEBULL_PIN='123456'

Webull requires an MFA email when authenticating new devices.

Once your device has been authorized, you should be able to see device name in your Webull app under "Settings" -> "Two-Factor Authentication".

Now your subsequent API calls can simply use your device ID and token. Your token is retrieved from using Client.Login(...) or using the NewClient constructor:

package main

import (
	"fmt"
	webull "gitlab.com/brokerage-api/webull-client/client"
	model "gitlab.com/brokerage-api/webull-client/models"
	"os"
)

func main() {
	// Authenticate your device
	creds := webull.Credentials{
		Username:    os.Getenv("WEBULL_USERNAME"),
		Password:    os.Getenv("WEBULL_PASSWORD"),
		AccountType: model.AccountType(2),
		DeviceName:  fmt.Sprintf(os.Getenv("WEBULL_USERNAME") + "@go-client"),
	}
	if c, err := webull.NewClient(&creds); err != nil {
		panic(err)
	} else if c == nil {
		panic("no client returned")
	} else {
		if err = c.GetMFA(creds); err != nil {
			panic(err)
		}
		if acc, err := c.GetAccountID(); err != nil {
			panic(err)
		} else {
			res, _ := c.GetAccountDividends(acc)
			fmt.Printf("Dividends: %v", res)
		}
	}
}

MQTT Connection (Quotes Streaming)

You can connect and stream various data using MQTT.

This example will process (I think all) streamable data for a particular ticker for 90 seconds. Note: not tested for concurrency.

package main

import (
	"context"
	"fmt"
	webull "gitlab.com/brokerage-api/webull-client/webull"
	model "gitlab.com/brokerage-api/webull-client/models"
	"os"
	"time"
)

func main() {
	// Authenticate your device
	creds := webull.Credentials{
		Username:    os.Getenv("WEBULL_USERNAME"),
		Password:    os.Getenv("WEBULL_PASSWORD"),
		AccountType: model.AccountType(2),
		DeviceName:  fmt.Sprintf(os.Getenv("WEBULL_USERNAME") + "@go-client"),
	}
	if c, err := webull.NewClient(&creds); err != nil {
		panic(err)
	} else if c == nil {
		panic("no client returned")
	} else {
		var (
			tickerID = "913256135"
			msgTypes = []string{"101", "102", "103", "104", "105", "106", "107", "108"}
		)
		yourCallback := func(ctx context.Context, topic webull.Topic, msg interface{}) error {
			fmt.Printf("TOPIC: %v\nMESSAGE: %v", topic, msg)
			return nil
		}
		c.RegisterCallback(false, yourCallback, "101")
		ctx, cancel := context.WithTimeout(context.Background(), time.Second*90)
		defer cancel()
		if err = c.ConnectWebsockets(ctx, msgTypes, []string{tickerID}); err != nil {
			panic(err)
		}
	}
}

Disclaimer

Use at your own risk.

Issues / Contributions

If you run into any problems feel free to create an issue on Gitlab or submit a pull request.

Repository Views

HitCount

webull-client's People

Contributors

austin-millan avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

webull-client's Issues

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.