anko

package module
v2.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2022 License: MIT Imports: 13 Imported by: 0

README

github.com/anglo-korean/anko-go-sdk

GoDoc Go Report Card

Package anko provides a golang SDK to the Anko Investor Forecasts gRPC service.

import "github.com/anglo-korean/anko-go-sdk"

It handles authentication and reconnection logic.

anko.ConnectionTimeout = time.Second // default: 5s

client, err := anko.New("anko-1234", "my-client")
if err != nil {
	panic(err)
}

panic(client.Handle(func(f *anko.Forecast) error {
	log.Printf("%#v", f)
	return nil
}))

This SDK accepts an Anko Token and a per-connection name (which may aid debugging where a single token is used across auto-scaled services) and returns a channel of forecasts for ready consumption.

client.Handle accepts an anko.Handler function, a convention borrowed from packages such as net/http. This function looks like:

type Handler func(*anko.Forecast) error

This function will be called on every Forecast received from the Anko Investor Forecasts gRPC Service. Any returned error will halt the processing of Forecasts. By default these functions are called sequentially; this is the opposite behaviour to http.HandlerFunc, where each handler runs in a new go function.

If this behaviour is important to you, then simply write your anko.Handler to provide its own sync/ dispatch/ gofunc logic.


Readme created from Go doc with goreadme

Documentation

Overview

Package anko provides a golang SDK to the Anko Investor Forecasts gRPC service.

import "github.com/anglo-korean/anko-go-sdk"

It handles authentication and reconnection logic.

anko.ConnectionTimeout = time.Second // default: 5s

client, err := anko.New("anko-1234", "my-client")
if err != nil {
	panic(err)
}

panic(client.Handle(func(f *anko.Forecast) error {
	log.Printf("%#v", f)
	return nil
}))

This SDK accepts an Anko Token and a per-connection name (which may aid debugging where a single token is used across auto-scaled services) and returns a channel of forecasts for ready consumption.

client.Handle accepts an anko.Handler function, a convention borrowed from packages such as net/http. This function looks like:

type Handler func(*anko.Forecast) error

This function will be called on every Forecast received from the Anko Investor Forecasts gRPC Service. Any returned error will halt the processing of Forecasts. By default these functions are called sequentially; this is the opposite behaviour to http.HandlerFunc, where each handler runs in a new go function.

If this behaviour is important to you, then simply write your anko.Handler to provide its own sync/ dispatch/ gofunc logic.

Index

Constants

View Source
const UA = "github.com/anglo-korean/anko-go-sdk@v2.0.2"

UA represents the User Agent shared with the gateway, and is used to provide metrics to allow things like deprecation warnings, and to help track errors in implementations.

To provide your own UA, you will need to either fork the repo, or write your own client

Variables

View Source
var (
	Label_name = map[int32]string{
		0: "unknown",
		1: "down",
		2: "up1_5",
		3: "up2",
		4: "up2_5",
		5: "up3",
		6: "up3_5",
		7: "up4",
		8: "higher",
	}
	Label_value = map[string]int32{
		"unknown": 0,
		"down":    1,
		"up1_5":   2,
		"up2":     3,
		"up2_5":   4,
		"up3":     5,
		"up3_5":   6,
		"up4":     7,
		"higher":  8,
	}
)

Enum value maps for Label.

View Source
var Addr = "forecasts.anko-investor.com:443"

Addr is the remote address of the Anko Streaming Endpoint. It may be used to point to different Anko Endpoints, for instance where enterprise users have custom VPN endpoints.

Similarly, it allows developers to point to stubbed endpoints during testing.

In essence, though, the default value is correct and fine for 99.9% of applications. If you don't know whether you need to change this, then you don't need to change this (as gnomic as that is).

View Source
var ConnectionTimeout = time.Second * 5

ConnectionTimeout is used in two places: * To timeout connections to the Forecasts gRPC Service, and * To provide a time limit for the Forecasts gRPC Service to validate an anko token and signal readiness

This timeout allows consumer applications to recognise when a gRPC connection is hanging, and when a lack of Forecasts just means there are no valid Forecasts.

View Source
var File_gateway_proto protoreflect.FileDescriptor
View Source
var Forecasts_ServiceDesc = grpc.ServiceDesc{
	ServiceName: "Forecasts",
	HandlerType: (*ForecastsServer)(nil),
	Methods:     []grpc.MethodDesc{},
	Streams: []grpc.StreamDesc{
		{
			StreamName:    "Stream",
			Handler:       _Forecasts_Stream_Handler,
			ServerStreams: true,
		},
	},
	Metadata: "gateway.proto",
}

Forecasts_ServiceDesc is the grpc.ServiceDesc for Forecasts service. It's only intended for direct use with grpc.RegisterService, and not to be introspected or modified (even as a copy)

View Source
var TLSConfig = new(tls.Config)

TLSConfig allows for overriding how this SDK connects to the specified `Addr`;

Some developers, for instance, may prefer to set very restrictive TLS configs whereas others may not.

Similarly, when pointing to stubbed endpoints developers may want to set this as per

anko.TLSConfig = &tls.Config{InsecureSkipVerify: true}

to avoid having to use trusted endpoints

Functions

func RegisterForecastsServer

func RegisterForecastsServer(s grpc.ServiceRegistrar, srv ForecastsServer)

Types

type Connection

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

Connection represents a connection to the Anko Investor Forecasts gRPC service.

Once instantiated, it is used to stream Forecasts for consumer applications to use as they want.

func New

func New(token, identifier string) (c Connection, err error)

New creates a connection to the Anko Investor gRPC service

func (Connection) Handle

func (c Connection) Handle(handler Handler) (err error)

Handle accepts a Handler in order to provide Forecasts to consumer applications.

As detailed in the documentation for Handler, Forecasts are processed one-at-a-time, when the previous Forecast has been processed.

This behaviour may be avoided by having your Handler `go func` out to another function.

Any errors returned from a Handler will cause this function to return.

type Forecast

type Forecast struct {
	Id     string  `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
	Ric    string  `protobuf:"bytes,2,opt,name=ric,proto3" json:"ric,omitempty"`
	Score  float64 `protobuf:"fixed64,3,opt,name=score,proto3" json:"score,omitempty"`
	Symbol *Symbol `protobuf:"bytes,4,opt,name=symbol,proto3" json:"symbol,omitempty"`
	Label  Label   `protobuf:"varint,5,opt,name=label,proto3,enum=Label" json:"label,omitempty"`
	// contains filtered or unexported fields
}

Forecast represents the product of the analysis of a piece of intelligence.

A piece of intelligence is processed through the Anglo Korean pipeline to determine the stock market symbol (represented here as a RIC, see: https://en.wikipedia.org/wiki/Reuters_Instrument_Code) a piece of intelligence will affect, the forecast change as a 'Label' (the definitions of which are described in the Label message), and a confidence score for this forecast (as a floating point value between 0 and 1, where 0 is a lack of confidence and 1 is complete confidence).

For users which do not speak RIC, we also embed our internal representation of a symbol, which includes the symbol, the exchange name, and how confident we are that this symbol is affected by a piece of intelligence

func (*Forecast) Descriptor deprecated

func (*Forecast) Descriptor() ([]byte, []int)

Deprecated: Use Forecast.ProtoReflect.Descriptor instead.

func (*Forecast) GetId

func (x *Forecast) GetId() string

func (*Forecast) GetLabel

func (x *Forecast) GetLabel() Label

func (*Forecast) GetRic

func (x *Forecast) GetRic() string

func (*Forecast) GetScore

func (x *Forecast) GetScore() float64

func (*Forecast) GetSymbol

func (x *Forecast) GetSymbol() *Symbol

func (*Forecast) ProtoMessage

func (*Forecast) ProtoMessage()

func (*Forecast) ProtoReflect

func (x *Forecast) ProtoReflect() protoreflect.Message

func (*Forecast) Reset

func (x *Forecast) Reset()

func (*Forecast) String

func (x *Forecast) String() string

type ForecastsClient

type ForecastsClient interface {
	Stream(ctx context.Context, in *Metadata, opts ...grpc.CallOption) (Forecasts_StreamClient, error)
}

ForecastsClient is the client API for Forecasts service.

For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.

func NewForecastsClient

func NewForecastsClient(cc grpc.ClientConnInterface) ForecastsClient

type ForecastsServer

type ForecastsServer interface {
	Stream(*Metadata, Forecasts_StreamServer) error
	// contains filtered or unexported methods
}

ForecastsServer is the server API for Forecasts service. All implementations must embed UnimplementedForecastsServer for forward compatibility

type Forecasts_StreamClient

type Forecasts_StreamClient interface {
	Recv() (*Forecast, error)
	grpc.ClientStream
}

type Forecasts_StreamServer

type Forecasts_StreamServer interface {
	Send(*Forecast) error
	grpc.ServerStream
}

type Handler

type Handler func(*Forecast) error

Handler is a function, in much the same vein as http.HandlerFunc, which consumer applications may use to process Forecasts.

Handler is called on every received forecasts. Any error returned by it will halt the consumer, and so Handlers must make sure to only return errors where this behaviour is appropriate.

Similarly Handlers are called synchonously, which is the opposite behaviour to how http.HandlerFunc works- it is the responsibility of the developer to provide gofunc/ sync semantics where required.

type Label

type Label int32

Label represents the price change forecast

const (
	Label_unknown Label = 0
	Label_down    Label = 1
	Label_up1_5   Label = 2
	Label_up2     Label = 3
	Label_up2_5   Label = 4
	Label_up3     Label = 5
	Label_up3_5   Label = 6
	Label_up4     Label = 7
	Label_higher  Label = 8
)

func (Label) Descriptor

func (Label) Descriptor() protoreflect.EnumDescriptor

func (Label) Enum

func (x Label) Enum() *Label

func (Label) EnumDescriptor deprecated

func (Label) EnumDescriptor() ([]byte, []int)

Deprecated: Use Label.Descriptor instead.

func (Label) Number

func (x Label) Number() protoreflect.EnumNumber

func (Label) String

func (x Label) String() string

func (Label) Type

func (Label) Type() protoreflect.EnumType

type Metadata

type Metadata struct {
	Ua   string `protobuf:"bytes,1,opt,name=ua,proto3" json:"ua,omitempty"`
	Tags []*Tag `protobuf:"bytes,2,rep,name=tags,proto3" json:"tags,omitempty"`
	// contains filtered or unexported fields
}

Metadata prvides some simple additional information a request might want to include, such as user-agent data, or some key-values for later reporting.

All fields are totally optional, though we would prefer that any clients where a token is used across multiple clients, a unique UA is set _per_ client. This will help debugging issues.

Tags are useful for reporting.

func (*Metadata) Descriptor deprecated

func (*Metadata) Descriptor() ([]byte, []int)

Deprecated: Use Metadata.ProtoReflect.Descriptor instead.

func (*Metadata) GetTags

func (x *Metadata) GetTags() []*Tag

func (*Metadata) GetUa

func (x *Metadata) GetUa() string

func (*Metadata) ProtoMessage

func (*Metadata) ProtoMessage()

func (*Metadata) ProtoReflect

func (x *Metadata) ProtoReflect() protoreflect.Message

func (*Metadata) Reset

func (x *Metadata) Reset()

func (*Metadata) String

func (x *Metadata) String() string

type Symbol

type Symbol struct {
	Symbol   string  `protobuf:"bytes,1,opt,name=symbol,proto3" json:"symbol,omitempty"`
	Score    float64 `protobuf:"fixed64,2,opt,name=score,proto3" json:"score,omitempty"`
	Ratio    float64 `protobuf:"fixed64,3,opt,name=ratio,proto3" json:"ratio,omitempty"`
	Exchange string  `protobuf:"bytes,4,opt,name=exchange,proto3" json:"exchange,omitempty"`
	// contains filtered or unexported fields
}

Symbol holds the raw representation of a symbol within Anglo Korean tied to a piece of intelligence.

Symbol and Exchange are pretty self explanatory.

Score and Ratio are used to express how confident we are that we've identified the correct symbol from a piece of intellegince; when processing data we assign a score to each symbol we derive- if the intelligence references a symbol directly then we add n points, if there's a reference to a company name or initialism then we add n/2 points, and if there's a reference to a corporate office's name we add n/5 points.

Where a score is quite low, or where there are many symbols with the same score (like a company on many markets), or where the ratio of this symbol to other symbols scores (if our symbol score is less than a third of all the scores added together, for instance) then we already discard forecasts.

By passing it here, we allow for clients to fine-tune their own confidence scoring if they need to.

func (*Symbol) Descriptor deprecated

func (*Symbol) Descriptor() ([]byte, []int)

Deprecated: Use Symbol.ProtoReflect.Descriptor instead.

func (*Symbol) GetExchange

func (x *Symbol) GetExchange() string

func (*Symbol) GetRatio

func (x *Symbol) GetRatio() float64

func (*Symbol) GetScore

func (x *Symbol) GetScore() float64

func (*Symbol) GetSymbol

func (x *Symbol) GetSymbol() string

func (*Symbol) ProtoMessage

func (*Symbol) ProtoMessage()

func (*Symbol) ProtoReflect

func (x *Symbol) ProtoReflect() protoreflect.Message

func (*Symbol) Reset

func (x *Symbol) Reset()

func (*Symbol) String

func (x *Symbol) String() string

type Tag

type Tag struct {
	Key   string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"`
	Value string `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"`
	// contains filtered or unexported fields
}

Tag is a key/value pair, used in reporting.

For instance, a user may wish to know how many client failures occured for tag "environment=production", or "version=2.0.0"

func (*Tag) Descriptor deprecated

func (*Tag) Descriptor() ([]byte, []int)

Deprecated: Use Tag.ProtoReflect.Descriptor instead.

func (*Tag) GetKey

func (x *Tag) GetKey() string

func (*Tag) GetValue

func (x *Tag) GetValue() string

func (*Tag) ProtoMessage

func (*Tag) ProtoMessage()

func (*Tag) ProtoReflect

func (x *Tag) ProtoReflect() protoreflect.Message

func (*Tag) Reset

func (x *Tag) Reset()

func (*Tag) String

func (x *Tag) String() string

type UnimplementedForecastsServer

type UnimplementedForecastsServer struct {
}

UnimplementedForecastsServer must be embedded to have forward compatible implementations.

func (UnimplementedForecastsServer) Stream

type UnsafeForecastsServer

type UnsafeForecastsServer interface {
	// contains filtered or unexported methods
}

UnsafeForecastsServer may be embedded to opt out of forward compatibility for this service. Use of this interface is not recommended, as added methods to ForecastsServer will result in compilation errors.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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