Orbis SDK is designed to help clients consume Orbis APIs with ease. Orbis SDK takes care of all the heavy lifting and provides out-of-the-box ready-to-use objects.
Make sure your project is using Go Modules (it will have a go.mod file in its root if it already is):
go mod init
Then, reference orbis-sdk-go in a Go program with import:
import "github.com/OrbisSystems/orbis-sdk-go"
Go version of the SDK is 1.20
Run any of the normal go commands (build/install/test). The Go toolchain will resolve and fetch the stripe-go module automatically.
Alternatively, you can also explicitly go get the package into a project:
go get -u github.com/OrbisSystems/orbis-sdk-go
Below are a few simple examples:
cfg := config.Config{
Host: "host-to-orbis-server", // ask client support. JUST hostname, without setting schema. Example: localhost, NOT https://localhost
LogLevel: config.TraceLogLevel,
}
You can use redis
tokenStorage, err := storage.NewRedisStorage(storage.Config{
Host: "localhost",
Port: 6379,
})
or in-memory storage
tokenStorage := storage.NewInMemoryStorage()
authSys := auth.New(tokenStorage)
cli := client.NewSDK(cfg, authSys)
You can check do you need to loging
needToLogin, err := cli.Account.NeedToLogin(ctx)
For login use the next API
cli.Account.LoginByEmail(ctx, model.LoginByEmailRequest{
Email: "test@test.com",
Password: "passpass",
DeviceID: "devideID",
RememberMe: true,
})
Also, you can use API Keys for loging using LoginByAPIKey
method.
After login, you can use one of the many APIs we provide you via this client. Here are some examples:
response, err := cli.News.GetByFilter(ctx, model.NewsFilterRequest{
Paging: model.Paging{
Limit: 100,
Offset: 2,
},
})
response, err := cli.TipRank.AnalystPortfolios(ctx, model.PortfoliosRequest{
ExpertUID: "dwdqw31",
Number: 12,
})
response, err := cli.Logos.SymbolLogos(ctx, "AAPL")
response, err := cli.Funds.GetFundDetails(ctx, "AAPL")
By using web socket connection you can get news feed from our system
newsCh, err := cli.WS.Subscribe(ctx, model.NewsSubscription)
if err != nil {
log.Error(err)
return
}
// newsCh is chan model.News
package main
import (
"context"
"fmt"
"time"
"github.com/OrbisSystems/orbis-sdk-go/auth"
"github.com/OrbisSystems/orbis-sdk-go/client"
"github.com/OrbisSystems/orbis-sdk-go/config"
"github.com/OrbisSystems/orbis-sdk-go/model"
"github.com/OrbisSystems/orbis-sdk-go/storage"
)
func main() {
// creating basic context
ctx := context.Background()
// set configs
cfg := config.Config{
Host: "host-to-orbis-server",
LogLevel: config.InfoLogLevel,
}
// init token storage using REDIS
tokenStorage, err := storage.NewRedisStorage(storage.Config{
Host: "localhost",
Port: 6379,
})
if err != nil {
panic(err)
}
// init auth system
authSys := auth.New(tokenStorage)
// create SDK Client
cli := client.NewSDK(cfg, authSys)
// check do we need to call Log In flow
needToLogin, err := cli.Account.NeedToLogin(ctx)
if err != nil {
return
}
if needToLogin {
// if we need to Log In - do it using email and password
if err := cli.Account.LoginByEmail(ctx, model.LoginByEmailRequest{
Email: "some-email@loca.com",
Password: "strong_password",
DeviceID: "qwqeqweq",
RememberMe: true,
}); err != nil {
fmt.Println("login error")
}
}
// get some latest news
news, err := cli.News.GetByFilter(ctx, model.NewsFilterRequest{
Paging: model.Paging{
Limit: 10,
},
})
fmt.Println(err)
fmt.Println(news)
// get some fund details for specific symbol
fundDetails, err := cli.Funds.GetFundDetails(ctx, "AAPL")
fmt.Println(err)
fmt.Println(fundDetails)
// create web socket subscription for getting news in realtime
newsCh, err := cli.WS.Subscribe(ctx, model.NewsSubscription)
if err != nil {
fmt.Println(err)
return
}
go func() {
for {
select {
// reading news from web socket
case wsNews := <-newsCh:
fmt.Println(wsNews)
}
}
}()
time.Sleep(time.Hour * 48)
}