api

package
v0.0.0-...-db7d511 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2019 License: MIT Imports: 6 Imported by: 6

Documentation

Overview

Package api contains definitions for the client and transports

Index

Constants

View Source
const (
	FAK           OrderType = "FAK"
	FOK                     = "FOK"
	LIMIT                   = "LIMIT"
	STOP_LIMIT              = "STOP_LIMIT"
	STOP_TRAILING           = "STOP_TRAILING"
	OCO                     = "OCO"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AccountOrder

type AccountOrder struct {
	Accno   int64 `json:"accno"`
	OrderId int64 `json:"orderid,omitempty"` // Only when modifying existing

	// Mandatory
	Identifier string    `json:"identifier"`
	MarketId   int64     `json:"market_id"`
	Price      float64   `json:"price"`
	Volume     int64     `json:"volume,omitempty"`
	Side       OrderSide `json:"side"`

	// Omited == LIMIT
	OrderType OrderType `json:"order_type,omitempty"`

	// Special
	Currency            string          `json:"currency,omitempty"`
	ValidUntil          string          `json:"valid_until,omitempty"`
	OpenVolume          int64           `json:"open_volume,omitempty"`
	Reference           string          `json:"reference,omitempty"`
	ActivationCondition OrderCondition  `json:"activation_condition,omitempty"`
	TriggerCondition    OrderTriggerDir `json:"trigger_condition,omitempty"`
	TriggerValue        float64         `json:"trigger_value,omitempty"`
}

func (AccountOrder) Apply

func (ao AccountOrder) Apply(b *RequestBuilder) (ret *RequestBuilder)

type ApiClient

type ApiClient struct {
	// contains filtered or unexported fields
}

func NewApiClient

func NewApiClient(ph TransportHandler) *ApiClient

func (*ApiClient) Account

func (ac *ApiClient) Account(accno int64) (res swagger.AccountInfo, err error)

func (*ApiClient) AccountLedgers

func (ac *ApiClient) AccountLedgers(accno int64) (res swagger.LedgerInformation, err error)

func (*ApiClient) AccountOrders

func (ac *ApiClient) AccountOrders(accno int64) (res []swagger.Order, err error)

func (*ApiClient) AccountPositions

func (ac *ApiClient) AccountPositions(accno int64) (res []swagger.Position, err error)

func (*ApiClient) AccountTrades

func (ac *ApiClient) AccountTrades(accno int64) (res []swagger.Trade, err error)

func (*ApiClient) Accounts

func (ac *ApiClient) Accounts() (res []swagger.Account, err error)

func (*ApiClient) ActivateOrder

func (ac *ApiClient) ActivateOrder(accno, id int64) (res swagger.OrderReply, err error)

func (*ApiClient) Countries

func (ac *ApiClient) Countries(countries ...string) (res []swagger.Country, err error)

func (*ApiClient) CreateOrder

func (ac *ApiClient) CreateOrder(order *AccountOrder) (res swagger.OrderReply, err error)

func (*ApiClient) CreateSimpleOrder

func (ac *ApiClient) CreateSimpleOrder(accno int64, identifier string, market int64,
	price float64, vol int64, side string) (res swagger.OrderReply, err error)

func (*ApiClient) CustomRequest

func (ac *ApiClient) CustomRequest(command string) (rb *RequestBuilder)

Custom

func (*ApiClient) DeleteOrder

func (ac *ApiClient) DeleteOrder(accno, id int64) (res swagger.OrderReply, err error)

func (*ApiClient) FeedStatus

func (ac *ApiClient) FeedStatus() (res map[string]interface{}, err error)

func (*ApiClient) FeedSub

func (ac *ApiClient) FeedSub(typ, id, mark string) (res map[string]interface{}, err error)

Feeds

func (*ApiClient) FeedSubNews

func (ac *ApiClient) FeedSubNews(source int64) (res map[string]interface{}, err error)

func (*ApiClient) FeedUnsub

func (ac *ApiClient) FeedUnsub(subId string) (res map[string]string, err error)

func (*ApiClient) GetTransport

func (ac *ApiClient) GetTransport() TransportHandler

func (*ApiClient) Indicators

func (ac *ApiClient) Indicators(indicators ...string) (res []swagger.Indicator, err error)

func (*ApiClient) InstrumentLeverages

func (ac *ApiClient) InstrumentLeverages(id int64, instrument_type, instrument_group_type string) (res []swagger.Instrument, err error)

func (*ApiClient) InstrumentLookup

func (ac *ApiClient) InstrumentLookup(typ, instrument string) (res []swagger.Instrument, err error)
func (ac *ApiClient) InstrumentLeverageFilters(pathMap{id int64})(res swagger.,err error) {
  err = ac.build(InstrumentLeverageFiltersCmd). &)
  return
}
func (ac *ApiClient) InstrumentOptionPairs(pathMap{id int64})(res swagger.,err error) {
  err = ac.build(InstrumentOptionPairsCmd). &)
  return
}
func (ac *ApiClient) InstrumentOptionPairFilters(pathMap{id int64})(res swagger.,err error) {
  err = ac.build(InstrumentOptionPairFiltersCmd). &)
  return
}

The lookup_type is isin_code_currency_market_id or market_id_identifier

func (*ApiClient) InstrumentSearch

func (ac *ApiClient) InstrumentSearch(query string) (res []swagger.Instrument, err error)

func (*ApiClient) InstrumentSearchStream

func (ac *ApiClient) InstrumentSearchStream(query, types string, fuzzy bool) (ret chan swagger.Instrument)

The advanced instrument search will page, and return the results in a chan. Ignoring error for now

func (*ApiClient) InstrumentTypes

func (ac *ApiClient) InstrumentTypes() (res []swagger.InstrumentType, err error)

func (*ApiClient) InstrumentUnderlyings

func (ac *ApiClient) InstrumentUnderlyings(typ, currency string) (res []swagger.Instrument, err error)
func (ac *ApiClient) InstrumentType(pathMap{pathMap{"Type",fmtInt}})(res swagger.,err error) {
  err = ac.build(InstrumentTypeCmd). &)
  return
}

func (*ApiClient) Instruments

func (ac *ApiClient) Instruments(ids ...int64) (res []swagger.Instrument, err error)

func (*ApiClient) List

func (ac *ApiClient) List(id int64) (res []swagger.Instrument, err error)

func (*ApiClient) Lists

func (ac *ApiClient) Lists() (res []swagger.List, err error)

func (*ApiClient) Market

func (ac *ApiClient) Market(ids ...int64) (res []swagger.Market, err error)

func (*ApiClient) NewsSources

func (ac *ApiClient) NewsSources() (res []swagger.NewsSource, err error)
func (ac *ApiClient) SearchNews()(res swagger.,err error) {
  err = ac.build(SearchNewsCmd). &)
  return
}
func (ac *ApiClient) News(pathMap{ids []int64})(res swagger.,err error) {
  err = ac.build(NewsCmd). &)
  return
}

func (*ApiClient) RealtimeAccess

func (ac *ApiClient) RealtimeAccess() (res []swagger.RealtimeAccess, err error)

func (*ApiClient) Session

func (ac *ApiClient) Session() (res swagger.Login, err error)

func (*ApiClient) TickSize

func (ac *ApiClient) TickSize(ids ...int64) (res []swagger.TicksizeTable, err error)

func (*ApiClient) TickSizes

func (ac *ApiClient) TickSizes() (res []swagger.TicksizeTable, err error)

func (*ApiClient) TradableDay

func (ac *ApiClient) TradableDay(ids ...string) (res []swagger.IntradayGraph, err error)

func (*ApiClient) TradableInfo

func (ac *ApiClient) TradableInfo(ids ...string) (res []swagger.TradableInfo, err error)

func (*ApiClient) TradableTrades

func (ac *ApiClient) TradableTrades(ids ...string) (res []swagger.PublicTrades, err error)

func (*ApiClient) UpdateOrder

func (ac *ApiClient) UpdateOrder(accno, id int64) (res swagger.OrderReply, err error)

type ErrorHolder

type ErrorHolder struct {
	Status  ErrorStatus `json:"status,omitempty"`
	Message string      `json:"message,omitempty"`
}

func (*ErrorHolder) Error

func (eh *ErrorHolder) Error() string

type ErrorStatus

type ErrorStatus int64

type OrderCondition

type OrderCondition string

type OrderSide

type OrderSide string

func (OrderSide) Buy

func (os OrderSide) Buy() OrderSide

func (OrderSide) Sell

func (os OrderSide) Sell() OrderSide

type OrderTriggerDir

type OrderTriggerDir string

type OrderType

type OrderType string

type Params

type Params map[string]string

func (Params) Pluck

func (p Params) Pluck(keys ...string) (res []string)

func (Params) Sprintf

func (p Params) Sprintf(format string, keys ...string) string

func (Params) SubParams

func (p Params) SubParams(keys ...string) (res Params)

type Request

type Request struct {
	Command RequestCommand `json:"cmd"`
	Args    Params         `json:"args,omitempty"`
}

func NewRequest

func NewRequest(command RequestCommand, params map[string]string) (req *Request, err error)

func (*Request) Encode

func (req *Request) Encode() ([]byte, error)

type RequestArgumentInfo

type RequestArgumentInfo struct {
	Name        string   `json:"name"`
	Description string   `json:"desc,omitempty"`
	Options     []string `json:"opts,omitempty"`
	Optional    bool     `json:"optional,omitempty"`

	Address string `json:"address,omitempty"` // Optional.  Use when the command is located on none standard topic
}

type RequestBuilder

type RequestBuilder struct {
	// contains filtered or unexported fields
}

func (*RequestBuilder) Exec

func (rb *RequestBuilder) Exec(res interface{}) error

func (*RequestBuilder) F

func (rb *RequestBuilder) F(key string, val float64) *RequestBuilder

func (*RequestBuilder) FA

func (rb *RequestBuilder) FA(key string, val []float64) *RequestBuilder

func (*RequestBuilder) I

func (rb *RequestBuilder) I(key string, val int64) *RequestBuilder

func (*RequestBuilder) IA

func (rb *RequestBuilder) IA(key string, val []int64) *RequestBuilder

func (*RequestBuilder) Price

func (rb *RequestBuilder) Price(key string, val float64) *RequestBuilder

func (*RequestBuilder) S

func (rb *RequestBuilder) S(key, val string) *RequestBuilder

func (*RequestBuilder) V

func (rb *RequestBuilder) V(key string, val interface{}) *RequestBuilder

type RequestCommand

type RequestCommand string
const (
	// Internally used.  A well behaving transport should return the commands it can handle
	TransportRespondsToCmd RequestCommand = "TransportRespondsTo"

	SessionCmd                     RequestCommand = "Session"
	AccountsCmd                    RequestCommand = "Accounts"
	AccountCmd                     RequestCommand = "Account"
	AccountLedgersCmd              RequestCommand = "AccountLedgers"
	AccountOrdersCmd               RequestCommand = "AccountOrders"
	CreateOrderCmd                 RequestCommand = "CreateOrder"
	ActivateOrderCmd               RequestCommand = "ActivateOrder"
	UpdateOrderCmd                 RequestCommand = "UpdateOrder"
	DeleteOrderCmd                 RequestCommand = "DeleteOrder"
	AccountPositionsCmd            RequestCommand = "AccountPositions"
	AccountTradesCmd               RequestCommand = "AccountTrades"
	CountriesCmd                   RequestCommand = "Countries"
	IndicatorsCmd                  RequestCommand = "Indicators"
	InstrumentsCmd                 RequestCommand = "Instruments"
	InstrumentSearchCmd            RequestCommand = "InstrumentSearch"
	InstrumentLookupCmd            RequestCommand = "InstrumentLookup"
	InstrumentLeveragesCmd         RequestCommand = "InstrumentLeverages"
	InstrumentLeverageFiltersCmd   RequestCommand = "InstrumentLeverageFilters"
	InstrumentOptionPairsCmd       RequestCommand = "InstrumentOptionPairs"
	InstrumentOptionPairFiltersCmd RequestCommand = "InstrumentOptionPairFilters"
	InstrumentSectorsCmd           RequestCommand = "InstrumentSectors"
	InstrumentSectorCmd            RequestCommand = "InstrumentSector"
	InstrumentTypesCmd             RequestCommand = "InstrumentTypes"
	InstrumentUnderlyingsCmd       RequestCommand = "InstrumentUnderlyings"
	ListsCmd                       RequestCommand = "Lists"
	ListCmd                        RequestCommand = "List"
	MarketCmd                      RequestCommand = "Market"
	SearchNewsCmd                  RequestCommand = "SearchNews"
	NewsCmd                        RequestCommand = "News"
	NewsSourcesCmd                 RequestCommand = "NewsSources"
	RealtimeAccessCmd              RequestCommand = "RealtimeAccess"
	TickSizesCmd                   RequestCommand = "TickSizes"
	TickSizeCmd                    RequestCommand = "TickSize"
	TradableInfoCmd                RequestCommand = "TradableInfo"
	TradableIntradayCmd            RequestCommand = "TradableIntraday"
	TradableTradesCmd              RequestCommand = "TradableTrades"

	FeedSubCmd    RequestCommand = "FeedSubscribe"
	FeedUnsubCmd  RequestCommand = "FeedUnsubscribe"
	FeedStatusCmd RequestCommand = "FeedStatus"

	FeedLastCmd RequestCommand = "FeedLast"
)

The commands that we support. Will be mapped in the low level TransportHandler

type RequestCommandInfo

type RequestCommandInfo struct {
	Command    RequestCommand                        `json:"cmd"`
	Desc       string                                `json:"desc,omitempty"`
	Arguments  []RequestArgumentInfo                 `json:"args,omitempty"`
	TimeToLive int64                                 `json:"ttl,omitempty"`
	HandlerFn  func(Params) (json.RawMessage, error) `json:"-"` // If implemented, we can
}

Is used as return struct for TransportRespondsToCmd

func (*RequestCommandInfo) AddArgument

func (rci *RequestCommandInfo) AddArgument(name string) *RequestCommandInfo

For builder pattern

func (*RequestCommandInfo) AddFullArgument

func (rci *RequestCommandInfo) AddFullArgument(name, desc string, opts []string, optional bool) *RequestCommandInfo

For builder pattern

func (*RequestCommandInfo) AddOptArgument

func (rci *RequestCommandInfo) AddOptArgument(name string) *RequestCommandInfo

For builder pattern

func (*RequestCommandInfo) Description

func (rci *RequestCommandInfo) Description(desc string) *RequestCommandInfo

For builder pattern

func (*RequestCommandInfo) GetArgumentNames

func (rci *RequestCommandInfo) GetArgumentNames() (res []string)

func (*RequestCommandInfo) Handler

func (rci *RequestCommandInfo) Handler(fun func(Params) (json.RawMessage, error)) *RequestCommandInfo

For builder pattern

func (*RequestCommandInfo) TTL

For builder pattern

func (*RequestCommandInfo) TTLHours

func (rci *RequestCommandInfo) TTLHours(hours int64) *RequestCommandInfo

For builder pattern

type RequestCommandTransport

type RequestCommandTransport map[RequestCommand]*RequestCommandInfo

func (RequestCommandTransport) AddCommand

func (rct RequestCommandTransport) AddCommand(name string) *RequestCommandInfo

func (RequestCommandTransport) Preform

func (rct RequestCommandTransport) Preform(req *Request) (res Response)

type Response

type Response struct {
	Error   *ErrorHolder    `json:"error,omitempty"`   // Error, if any. nil if not
	Payload json.RawMessage `json:"payload,omitempty"` // Response payload as JSON
}

func (*Response) Fail

func (ar *Response) Fail(status ErrorStatus, msg string)

func (*Response) IsError

func (ar *Response) IsError() bool

func (*Response) Marshal

func (ar *Response) Marshal(ob interface{}) (err error)

func (*Response) String

func (ar *Response) String() string

func (*Response) Success

func (ar *Response) Success(res interface{})

func (*Response) Unmarshal

func (ar *Response) Unmarshal(ob interface{}) error

type Transport

type Transport func(*Request) Response

Invoke the request. If there is an error, it should be set in the response struct

func (Transport) Preform

func (p Transport) Preform(req *Request) Response

Let the func implement the handler

type TransportCacheHandler

type TransportCacheHandler interface {
	Handle(RequestCommandInfo, TransportHandler, *Request) Response
}

type TransportCacheHandlerFn

type TransportCacheHandlerFn func(RequestCommandInfo, TransportHandler, *Request) Response

func (TransportCacheHandlerFn) Handle

type TransportHandler

type TransportHandler interface {
	Preform(*Request) Response
}

type TransportRouter

type TransportRouter struct {
	// contains filtered or unexported fields
}

func NewCachedTransportRouter

func NewCachedTransportRouter(ch TransportCacheHandler, transports ...TransportHandler) (tr *TransportRouter, err error)

func NewTransportRouter

func NewTransportRouter(transports ...TransportHandler) (tr *TransportRouter, err error)

func (*TransportRouter) AddTransportHandler

func (tr *TransportRouter) AddTransportHandler(th TransportHandler) (err error)

func (TransportRouter) Preform

func (tr TransportRouter) Preform(req *Request) (res Response)

Jump to

Keyboard shortcuts

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