
Product
Introducing Socket Fix for Safe, Automated Dependency Upgrades
Automatically fix and test dependency updates with socket fix—a new CLI tool that turns CVE alerts into safe, automated upgrades.
github.com/ksysoev/deriv-api
This is unofficial library for working with Deriv API
DerivAPI is a Go package that provides a client for the Deriv API. It allows you to connect to the Deriv API and make requests to retrieve data and perform actions on your or your client's Deriv account.
To use DerivAPI in your Go project, you can install it using go get:
go get github.com/ksysoev/deriv-api
Here's an example of how to use DerivAPI to connect to the Deriv API and subscribe on market data updates:
import (
"context"
"fmt"
"log"
"time"
"github.com/ksysoev/deriv-api"
"github.com/ksysoev/deriv-api/schema"
)
api, err := deriv.NewDerivAPI("wss://ws.binaryws.com/websockets/v3", 1, "en", "http://example.com/")
if err != nil {
log.Fatal(err)
}
defer api.Disconnect()
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
resp, sub, err := api.SubscribeTicks(ctx, schema.Ticks{Ticks: "R_50"})
if err != nil {
log.Fatal(err)
return
}
fmt.Println("Symbol: ", *resp.Tick.Symbol, "Quote: ", *resp.Tick.Quote)
for tick := range sub.Stream {
fmt.Println("Symbol: ", *tick.Tick.Symbol, "Quote: ", *tick.Tick.Quote)
}
Here's another example of how to use DerivAPI to buy contract and listen for updates for this contract.
import (
"context"
"log"
"time"
"github.com/ksysoev/deriv-api"
"github.com/ksysoev/deriv-api/schema"
)
apiToken := "YOU_API_TOKEN_HERE"
api, err := deriv.NewDerivAPI("wss://ws.binaryws.com/websockets/v3", 1, "en", "https://www.binary.com")
if err != nil {
log.Fatal(err)
}
defer api.Disconnect()
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
// First, we need to authorize the connection
reqAuth := schema.Authorize{Authorize: apiToken}
_, err = api.Authorize(ctx, reqAuth)
if err != nil {
log.Fatal(err)
}
amount := 100.0
barrier := "+0.001"
duration := 5
basis := schema.ProposalBasisPayout
reqProp := schema.Proposal{
Proposal: 1,
Amount: &amount,
Barrier: &barrier,
Basis: &basis,
ContractType: deriv.ProposalContractTypeCALL,
Currency: "USD",
Duration: &duration,
DurationUnit: deriv.ProposalDurationUnitT,
Symbol: "R_50",
}
// Send a proposal request
proposal, err := api.Proposal(ctx, reqProp)
if err != nil {
log.Fatal(err)
}
buyReq := schema.Buy{
Buy: proposal.Proposal.Id,
Price: 100.0,
}
_, buySub, err := api.SubscribeBuy(context.Background(), buyReq)
if err != nil {
log.Fatal(err)
}
for proposalOpenContract := range buySub.Stream {
log.Println("Current Spot: ", *proposalOpenContract.ProposalOpenContract.CurrentSpot)
if *proposalOpenContract.ProposalOpenContract.IsSold == 1 {
log.Println("Contract Result: ", proposalOpenContract.ProposalOpenContract.Status.Value)
buySub.Forget()
break
}
}
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Automatically fix and test dependency updates with socket fix—a new CLI tool that turns CVE alerts into safe, automated upgrades.
Security News
CISA denies CVE funding issues amid backlash over a new CVE foundation formed by board members, raising concerns about transparency and program governance.
Product
We’re excited to announce a powerful new capability in Socket: historical data and enhanced analytics.