Documentation ¶
Index ¶
- Constants
- func NewError(resp *http.Response) error
- type AccountResponse
- type Client
- func (c *Client) CancelOrder(ctx context.Context, id string) (AccountResponse, error)
- func (c *Client) CreateOrder(ctx context.Context, createReq CreateOrderRequest) (AccountResponse, error)
- func (c *Client) Login(username, password string) error
- func (c *Client) UpdateOrder(ctx context.Context, id string, updateReq UpdateOrderRequest) (AccountResponse, error)
- type CreateOrderRequest
- type Error
- type Option
- type OrderTimeValidity
- type OrderType
- type UpdateOrderRequest
Constants ¶
const ( OrderTypeMarket OrderType = "MARKET" OrderTypeStop OrderType = "STOP" OrderTypeLimit OrderType = "LIMIT" OrderTypeStopLimit OrderType = "STOP_LIMIT" OrderTimeValidityDay OrderTimeValidity = "DAY" OrderTimeValidityTillCancelled OrderTimeValidity = "GOOD_TILL_CANCEL" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AccountResponse ¶
type AccountResponse struct { Account struct { Dealer string `json:"dealer"` Positions []struct { PositionID string `json:"positionId"` HumanID string `json:"humanId"` Created time.Time `json:"created"` AveragePrice float64 `json:"averagePrice"` AveragePriceConverted float64 `json:"averagePriceConverted"` CurrentPrice float64 `json:"currentPrice"` Value float64 `json:"value"` Investment float64 `json:"investment"` Code string `json:"code"` Margin float64 `json:"margin"` Ppl float64 `json:"ppl"` Quantity float64 `json:"quantity"` MaxBuy float64 `json:"maxBuy"` MaxSell float64 `json:"maxSell"` MaxOpenBuy float64 `json:"maxOpenBuy"` MaxOpenSell float64 `json:"maxOpenSell"` Frontend string `json:"frontend"` AutoInvestQuantity float64 `json:"autoInvestQuantity"` FxPpl float64 `json:"fxPpl"` } `json:"positions"` Cash struct { Free float64 `json:"free"` Total float64 `json:"total"` Interest float64 `json:"interest"` Indicator float64 `json:"indicator"` Commission float64 `json:"commission"` Cash float64 `json:"cash"` Ppl float64 `json:"ppl"` Result float64 `json:"result"` SpreadBack float64 `json:"spreadBack"` NonRefundable float64 `json:"nonRefundable"` Dividend float64 `json:"dividend"` StockInvestment float64 `json:"stockInvestment"` FreeForStocks float64 `json:"freeForStocks"` TotalCashForWithdraw float64 `json:"totalCashForWithdraw"` BlockedForStocks float64 `json:"blockedForStocks"` PieCash float64 `json:"pieCash"` } `json:"cash"` LimitStop []interface{} `json:"limitStop"` Oco []interface{} `json:"oco"` IfThen []interface{} `json:"ifThen"` EquityOrders []struct { OrderID string `json:"orderId"` Type string `json:"type"` Code string `json:"code"` Quantity float64 `json:"quantity"` FilledQuantity float64 `json:"filledQuantity"` Status string `json:"status"` StopPrice float64 `json:"stopPrice"` Created time.Time `json:"created"` Frontend string `json:"frontend"` } `json:"equityOrders"` EquityValueOrders []interface{} `json:"equityValueOrders"` ID int `json:"id"` Timestamp int64 `json:"timestamp"` } `json:"account"` }
AccountResponse returned from various v2 endpoints.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client for interacting with the undocumented Trading 212 website API.
func (*Client) CancelOrder ¶
CancelOrder with id.
func (*Client) CreateOrder ¶
func (c *Client) CreateOrder( ctx context.Context, createReq CreateOrderRequest, ) (AccountResponse, error)
CreateOrder creates a new order.
func (*Client) Login ¶
Login as a user obtaining the session cookies required to make other requests.
func (*Client) UpdateOrder ¶
func (c *Client) UpdateOrder( ctx context.Context, id string, updateReq UpdateOrderRequest, ) (AccountResponse, error)
UpdateOrder with id.
type CreateOrderRequest ¶
type CreateOrderRequest struct { InstrumentCode string `json:"instrumentCode"` OrderType OrderType `json:"orderType"` StopPrice float64 `json:"stopPrice,omitempty"` LimitPrice float64 `json:"limitPrice,omitempty"` Quantity float64 `json:"quantity"` TimeValidity OrderTimeValidity `json:"timeValidity"` }
CreateOrderRequest contains the request parameters to create an order.
type Error ¶
type Error struct { StatusCode int `json:"-"` Body []byte `json:"-"` Code string `json:"code"` Message string `json:"message"` }
Error returned from the Trading 212 API.
type Option ¶
type Option func(*Client)
Option sets an optional setting on the Client.
func WithHTTPClient ¶
WithHTTPClient returns an Option to set the http.Client to be used.
func WithPracticeMode ¶
func WithPracticeMode() Option
WithPracticeMode returns an Option to set the Client to make requests to the demo mode environment for practice.
type OrderTimeValidity ¶
type OrderTimeValidity string
OrderTimeValidity is how long the order is valid for e.g OrderTimeValidityDay/OrderTimeValidityTilCancelled.
type OrderType ¶
type OrderType string
OrderType is the type of order e.g OrderTypeStop/OrderTypeMarket.
type UpdateOrderRequest ¶
type UpdateOrderRequest struct { StopPrice float64 `json:"stopPrice,omitempty"` LimitPrice float64 `json:"limitPrice,omitempty"` Quantity int `json:"quantity,omitempty"` TimeValidity OrderTimeValidity `json:"timeValidity,omitempty"` }
UpdateOrderRequest contains the request parameters to update an order.