webull

package
v1.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 14, 2021 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultDeviceID if none is supplied by user.
	DefaultDeviceID = "2292c4714f144eb08ed3edec7f7ce284"
	// PasswordSalt is used for salting your password
	PasswordSalt = "wl_app-a&b@!423^"
	// DefaultDeviceName is a device name
	DefaultDeviceName = "test"
	// DefaultTokenExpiryFormat is used to parse the custom datetime returned by Webull
	DefaultTokenExpiryFormat = "2006-01-02T15:04:05.000+0000"
)
View Source
const (
	QuotesEndpoint         = "https://quoteapi.webull.com/api"
	UserEndpoint           = "https://userapi.webull.com/api"
	BrokerQuotesEndpoint   = "https://quoteapi.webullbroker.com/api"
	BrokerQuotesGWEndpoint = "https://quotes-gw.webullbroker.com/api"
	SecuritiesEndpoint     = "https://securitiesapi.webullbroker.com/api"
	UserBrokerEndpoint     = "https://userapi.webullbroker.com/api"
	PaperTradeEndpoint     = "https://act.webullbroker.com/webull-paper-center/api"
	PaperTradeEndpointV    = "https://act.webullfintech.com/webull-paper-center/api"
	TradeEndpoint          = "https://tradeapi.webulltrade.com/api/trade"
	StockInfoEndpoint      = "https://infoapi.webull.com/api"
)

Endpoints for the Webull API

View Source
const (
	// HeaderKeyAccessToken variable should be used instead of hard-coding the header key for auth tokens.
	HeaderKeyAccessToken = "access_token"
	// HeaderKeyDeviceID variable should be used instead of hard-coding the header key for device IDs.
	HeaderKeyDeviceID = "did"
	// HeaderKeyTradeToken variable should be used instead of hard-coding the header key for trade auth tokens.
	HeaderKeyTradeToken = "t_token"
	// HeaderKeyTradeTime variable should be used instead of hard-coding the header key for trade time.
	HeaderKeyTradeTime = "t_time"
	// QueryKeyTickerID variable should be used instead of hard-coding the query parameter for Ticker ID.
	QueryKeyTickerID = "tickerID"
	// QueryKeyDerivativeIDs variable should be used instead of hard-coding the query parameter derivative IDs.
	QueryKeyDerivativeIDs = "derivativeIds"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthExpiredError

type AuthExpiredError struct{}

AuthExpiredError returned when token needs to be refreshed

func (*AuthExpiredError) Error

func (e *AuthExpiredError) Error() string

type Client

type Client struct {
	Username       string
	HashedPassword string
	AccountType    model.AccountType
	MFA            string
	UUID           string
	DeviceName     string

	AccessToken           string
	AccessTokenExpiration time.Time
	RefreshToken          string

	TradeToken           string
	TradeTokenExpiration time.Time

	DeviceID string

	ClientItf
	// contains filtered or unexported fields
}

Client is a helpful abstraction around some common metadata required for API operations.

func NewClient

func NewClient(creds *Credentials) (c *Client, err error)

NewClient is a constructor for the Webull-Client client

func (*Client) CancelAllPaperOrders

func (c *Client) CancelAllPaperOrders(accountID string) ([]int32, error)

CancelAllPaperOrders is a wrapper for cancelling a number of WORKING orders. Note: no pagination so no guarantee all orders will cancel

func (*Client) CancelOrder

func (c *Client) CancelOrder(accountID, orderID string) (*interface{}, error)

CancelOrder cancels trade

func (*Client) CancelPaperOrder

func (c *Client) CancelPaperOrder(accountID, orderID string) (*interface{}, error)

CancelPaperOrder cancels paper trade

func (*Client) CheckOtocoOrder

func (c *Client) CheckOtocoOrder(accountID string, input model.PostOtocoOrderRequest) (*interface{}, error)

CheckOtocoOrder checks OTOCO order (TODO)

func (*Client) ConnectWebsockets

func (c *Client) ConnectWebsockets(tickerIDs []string) (err error)

ConnectWebsockets connects to a streaming API by Webull NOTE: client still unstable

func (*Client) DoAndDecode

func (c *Client) DoAndDecode(req *http.Request, dest interface{}) (err error)

DoAndDecode provides useful abstractions around common errors and decoding issues. Ideally unmarshals into `dest`. On error, it'll use the Webull `ErrorBody` model. Last fallback is a plain interface.

func (*Client) GetAccount

func (c *Client) GetAccount(accountID int) (*model.GetAccountResponse, error)

GetAccount gets account details for account `accountID`

func (*Client) GetAccountDividends

func (c *Client) GetAccountDividends(accountID string) (*model.GetDividendsResponse, error)

GetAccountDividends gets account `accountID` total dividends.

func (*Client) GetAccountID

func (c *Client) GetAccountID() (string, error)

GetAccountID gets an account ID

func (*Client) GetAccountIDs

func (c *Client) GetAccountIDs() (accountIDs []string, err error)

GetAccountIDs gets all account IDs

func (*Client) GetAccountV5

func (c *Client) GetAccountV5() (*model.GetAccountsResponseV5, error)

GetAccountV5 gets account details for account. Note: Doesn't work.

func (*Client) GetAccounts

func (c *Client) GetAccounts() (*model.GetSecurityAccountsResponse, error)

GetAccounts gets all associated accounts

func (*Client) GetActiveGainersLosers

func (c *Client) GetActiveGainersLosers(direction, regionID, userRegionID string) (*[]model.ActiveGainersLosers, error)

GetActiveGainersLosers gets the day's active gainers or losers.

func (*Client) GetAlerts

func (c *Client) GetAlerts() (*model.GetAlertsResponse, error)

GetAlerts gets all alerts.

func (*Client) GetAndDecode

func (c *Client) GetAndDecode(URL url.URL, dest interface{}, headers *map[string]string, urlValues *map[string]string) error

GetAndDecode retrieves from the endpoint and unmarshals resulting json into the provided destination interface, which must be a pointer.

func (*Client) GetMFA

func (c *Client) GetMFA(creds Credentials) (err error)

GetMFA requests for a 2FA code

func (*Client) GetOptionsQuotes

func (c *Client) GetOptionsQuotes(tickerID, derivativeIds string) (*model.GetStockOptionsResponse, error)

GetOptionsQuotes gets options quotes.

func (*Client) GetOrders

func (c *Client) GetOrders(accountID string, status model.OrderStatus, count int32) (*[]model.GetOrdersItem, error)

GetOrders returns orders.

func (*Client) GetPaperOrders

func (c *Client) GetPaperOrders(paperAccountID string, startTime string, dateType string, orderStatus model.OrderStatus) (*[]model.PaperOrder, error)

GetPaperOrders gets user paper trades

func (*Client) GetPaperTradeAccountID

func (c *Client) GetPaperTradeAccountID() (string, error)

GetPaperTradeAccountID is a a helper function for getting a single paper trading account ID

func (*Client) GetPaperTradeAccountIDs

func (c *Client) GetPaperTradeAccountIDs() ([]string, error)

GetPaperTradeAccountIDs is a a helper function for getting all paper trading account IDs.

func (*Client) GetPaperTradeAccounts

func (c *Client) GetPaperTradeAccounts() (*[]model.PaperAccount, error)

GetPaperTradeAccounts gets information for all paper accounts.

func (*Client) GetRealtimeStockQuote

func (c *Client) GetRealtimeStockQuote(tickerID string) (*model.GetStockQuoteResponse, error)

GetRealtimeStockQuote gets real-time data for ticker `tickerID`

func (*Client) GetStockAnalysis

func (c *Client) GetStockAnalysis(tickerID string) (*model.GetStockAnalysisResponse, error)

GetStockAnalysis gets Webull stock analysis for tickerID `tickerID`

func (*Client) GetStockFundamentals

func (c *Client) GetStockFundamentals(tickerID string) (*model.GetFundamentalsResponse, error)

GetStockFundamentals gets stock fundamentals for ticker `tickerID`

func (*Client) GetStockOptions

func (c *Client) GetStockOptions(tickerID, expireDate, direction string, count, includeWeekly, queryAll int32) (*model.GetStockOptionsResponse, error)

GetStockOptions queries for options quotes.

func (*Client) GetTicker

func (c *Client) GetTicker(symbol string) (*model.LookupTickerResponse, error)

GetTicker gets ticker information for a provided stock symbol

func (*Client) GetTickerID

func (c *Client) GetTickerID(symbol string) (string, error)

GetTickerID is a helper function for getting a ticker ID from a stock symbol

func (*Client) GetTransfers

func (c *Client) GetTransfers(accountID string, count uint32) (*model.Transfers, error)

GetTransfers returns Transfers.

func (*Client) GetUser

func (c *Client) GetUser() (*model.GetUserDetailsResponse, error)

GetUser gets user your details

func (*Client) IsTradeable

func (c *Client) IsTradeable(tickerID string) (*model.GetIsTradeableResponse, error)

IsTradeable returns information on where a specific ticker is traded

func (*Client) Login

func (c *Client) Login(creds Credentials) (err error)

Login implements TokenSource

func (*Client) ModifyOrder

func (c *Client) ModifyOrder(accountID string, orderID string, input model.PostStockOrderRequest) (*interface{}, error)

ModifyOrder modifies trade (TODO)

func (*Client) ModifyPaperOrder

func (c *Client) ModifyPaperOrder(accountID string, orderID string, input model.PostStockOrderRequest) (*interface{}, error)

ModifyPaperOrder modifies paper trade

func (*Client) PlaceOrder

func (c *Client) PlaceOrder(accountID string, input model.PostStockOrderRequest) (*model.PostOrderResponse, error)

PlaceOrder places trade (TODO)

func (*Client) PlaceOtocoOrder

func (c *Client) PlaceOtocoOrder(accountID string, input model.PostOtocoOrderRequest) (*interface{}, error)

PlaceOtocoOrder places OTOCO trade (TODO)

func (*Client) PlacePaperOrder

func (c *Client) PlacePaperOrder(accountID string, input model.PostStockOrderRequest) (*model.PostPaperOrderResponse, error)

PlacePaperOrder places paper trade

func (*Client) PostAndDecode

func (c *Client) PostAndDecode(URL url.URL, dest interface{}, headers *map[string]string, urlValues *map[string]string, payload []byte) error

PostAndDecode retrieves from the endpoint and unmarshals resulting json into the provided destination interface, which must be a pointer.

func (*Client) Token

func (c *Client) Token() (*oauth2.Token, error)

Token implements TokenSource

func (*Client) TradeLogin

func (c *Client) TradeLogin(creds Credentials) (err error)

TradeLogin implements TokenSource

type ClientItf added in v1.0.7

type ClientItf interface {
	// Orders related
	GetOrders(accountID string, status model.OrderStatus, count int32) (*[]model.GetOrdersItem, error)
	IsTradeable(tickerID string) (*model.GetIsTradeableResponse, error)
	PlaceOrder(accountID string, input model.PostStockOrderRequest) (*model.PostOrderResponse, error)
	CheckOtocoOrder(accountID string, input model.PostOtocoOrderRequest) (*interface{}, error)
	PlaceOtocoOrder(accountID string, input model.PostOtocoOrderRequest) (*interface{}, error)
	CancelOrder(accountID, orderID string) (*interface{}, error)
	ModifyOrder(accountID string, orderID string, input model.PostStockOrderRequest) (*interface{}, error)

	// Utility related
	GetTickerID(symbol string) (string, error)
	GetRealtimeStockQuote(tickerID string) (*model.GetStockQuoteResponse, error)
}

ClientInf is an abstraction of order related function

type ClientMock added in v1.0.7

type ClientMock struct {
	Username       string
	HashedPassword string
	AccountType    model.AccountType
	MFA            string
	UUID           string
	DeviceName     string

	AccessToken           string
	AccessTokenExpiration time.Time
	RefreshToken          string

	TradeToken           string
	TradeTokenExpiration time.Time

	DeviceID string
	// contains filtered or unexported fields
}

ClientMock is a mock for client unit testing.

func (*ClientMock) CancelOrder added in v1.0.7

func (m *ClientMock) CancelOrder(accountID, orderID string) (*interface{}, error)

func (*ClientMock) CheckOtocoOrder added in v1.0.7

func (m *ClientMock) CheckOtocoOrder(accountID string, input model.PostOtocoOrderRequest) (*interface{}, error)

func (*ClientMock) GetOrders added in v1.0.7

func (m *ClientMock) GetOrders(accountID string, status model.OrderStatus, count int32) (*[]model.GetOrdersItem, error)

The following functions are mocking functions for client orders

func (*ClientMock) GetRealtimeStockQuote added in v1.0.9

func (m *ClientMock) GetRealtimeStockQuote(tickerID string) (*model.GetStockQuoteResponse, error)

func (*ClientMock) GetTickerID added in v1.0.7

func (m *ClientMock) GetTickerID(symbol string) (string, error)

func (*ClientMock) IsTradeable added in v1.0.7

func (m *ClientMock) IsTradeable(tickerID string) (*model.GetIsTradeableResponse, error)

func (*ClientMock) ModifyOrder added in v1.0.7

func (m *ClientMock) ModifyOrder(accountID string, orderID string, input model.PostStockOrderRequest) (*interface{}, error)

func (*ClientMock) PlaceOrder added in v1.0.7

func (m *ClientMock) PlaceOrder(accountID string, input model.PostStockOrderRequest) (*model.PostOrderResponse, error)

func (*ClientMock) PlaceOtocoOrder added in v1.0.7

func (m *ClientMock) PlaceOtocoOrder(accountID string, input model.PostOtocoOrderRequest) (*interface{}, error)

type Credentials

type Credentials struct {
	Username    string
	Password    string
	DeviceID    string
	TradePIN    string
	MFA         string
	DeviceName  string
	AccountType model.AccountType
	Creds       oauth2.TokenSource
}

Credentials implements oauth2 using the webull implementation

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL