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 ¶
- Variables
- func RegisterForecastsServer(s grpc.ServiceRegistrar, srv ForecastsServer)
- type Connection
- type Forecast
- func (*Forecast) Descriptor() ([]byte, []int)deprecated
- func (x *Forecast) GetId() string
- func (x *Forecast) GetLabel() Label
- func (x *Forecast) GetRic() string
- func (x *Forecast) GetScore() float64
- func (x *Forecast) GetSymbol() *Symbol
- func (*Forecast) ProtoMessage()
- func (x *Forecast) ProtoReflect() protoreflect.Message
- func (x *Forecast) Reset()
- func (x *Forecast) String() string
- type ForecastsClient
- type ForecastsServer
- type Forecasts_StreamClient
- type Forecasts_StreamServer
- type Handler
- type Label
- type Metadata
- type Symbol
- func (*Symbol) Descriptor() ([]byte, []int)deprecated
- func (x *Symbol) GetExchange() string
- func (x *Symbol) GetRatio() float64
- func (x *Symbol) GetScore() float64
- func (x *Symbol) GetSymbol() string
- func (*Symbol) ProtoMessage()
- func (x *Symbol) ProtoReflect() protoreflect.Message
- func (x *Symbol) Reset()
- func (x *Symbol) String() string
- type Tag
- type UnimplementedForecastsServer
- type UnsafeForecastsServer
Constants ¶
This section is empty.
Variables ¶
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.
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.
var File_gateway_proto protoreflect.FileDescriptor
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)
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) ProtoMessage ¶
func (*Forecast) ProtoMessage()
func (*Forecast) ProtoReflect ¶
func (x *Forecast) ProtoReflect() protoreflect.Message
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 ¶
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
func (Label) Descriptor ¶
func (Label) Descriptor() protoreflect.EnumDescriptor
func (Label) EnumDescriptor
deprecated
func (Label) Number ¶
func (x Label) Number() protoreflect.EnumNumber
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) ProtoMessage ¶
func (*Metadata) ProtoMessage()
func (*Metadata) ProtoReflect ¶
func (x *Metadata) ProtoReflect() protoreflect.Message
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) GetExchange ¶
func (*Symbol) ProtoMessage ¶
func (*Symbol) ProtoMessage()
func (*Symbol) ProtoReflect ¶
func (x *Symbol) ProtoReflect() protoreflect.Message
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) ProtoMessage ¶
func (*Tag) ProtoMessage()
func (*Tag) ProtoReflect ¶
func (x *Tag) ProtoReflect() protoreflect.Message
type UnimplementedForecastsServer ¶
type UnimplementedForecastsServer struct { }
UnimplementedForecastsServer must be embedded to have forward compatible implementations.
func (UnimplementedForecastsServer) Stream ¶
func (UnimplementedForecastsServer) Stream(*Metadata, Forecasts_StreamServer) error
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.