deriv

package module
v0.0.0-...-47c65a4 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2025 License: MIT Imports: 13 Imported by: 0

README

Deriv Api Client

Tests codecov Schema Updated Go Report Card Go Reference

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.

Installation

To use DerivAPI in your Go project, you can install it using go get:

go get github.com/adorableima/deriv-api

Usage

Tick stream

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/adorableima/deriv-api"
    "github.com/adorableima/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)
}
Buying a contract

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/adorableima/deriv-api"
    "github.com/adorableima/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
    }
}

Documentation

Overview

Code generated by bin/generate_call.go, DO NOT EDIT.

Code generated by bin/generate_call.go, DO NOT EDIT.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrConnectionClosed    = fmt.Errorf("connection closed")
	ErrEmptySubscriptionID = fmt.Errorf("subscription ID is empty")
	ErrInvalidSchema       = fmt.Errorf("invalid endpoint scheme")
	ErrInvalidAppID        = fmt.Errorf("invalid app ID")
	ErrInvalidLanguage     = fmt.Errorf("invalid language")
)
View Source
var LlzZCgLr = sCLbQJ()
View Source
var RqUmrH = mmzIld()

Functions

func Debug

func Debug(api *Client)

Debug option which enables debug messages.

func KeepAlive

func KeepAlive(api *Client)

KeepAlive option which keeps the connection alive by sending ping requests. By default the websocket connection is closed after 30 seconds of inactivity.

Types

type APIError

type APIError struct {
	Details *json.RawMessage `json:"details"`
	Code    string           `json:"code"`
	Message string           `json:"message"`
}

APIError represents an error returned by the Deriv API service.

func (*APIError) Error

func (e *APIError) Error() string

Error returns the error message associated with the APIError.

func (*APIError) ParseDetails

func (e *APIError) ParseDetails(v any) error

ParseDetails parses the details field of the APIError into the provided value.

type APIOption

type APIOption func(api *Client)

type APIReqest

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

APIReqest is an interface for all API requests.

type APIResponseReqID

type APIResponseReqID struct {
	ReqID int `json:"req_id"`
}

type Client

type Client struct {
	Endpoint *url.URL
	Origin   *url.URL
	// contains filtered or unexported fields
}

DerivAPI is the main struct for the DerivAPI client

func NewDerivAPI

func NewDerivAPI(endpoint string, appID int, lang, origin string, opts ...APIOption) (*Client, error)

NewDerivAPI creates a new instance of DerivAPI by parsing and validating the given endpoint URL, appID, language, and origin URL. It returns a pointer to a DerivAPI object or an error if any of the validation checks fail.

Parameters: - endpoint: string - The WebSocket endpoint URL for the DerivAPI server - appID: int - The app ID for the DerivAPI server - lang: string - The language code (ISO 639-1) for the DerivAPI server - origin: string - The origin URL for the DerivAPI server - opts: APIOption - A variadic list of APIOption functions to configure the DerivAPI object (optional)

  • KeepAlive: A APIOption function to keep the connection alive by sending ping requests.
  • Debug: A APIOption function to enable debug messages.

Returns:

  • *Client: A pointer to a new instance of DerivAPI with the validated endpoint, appID, language, and origin values.
  • error: An error if any of the validation checks fail.

Example:

api, err := NewDerivAPI("wss://trade.deriv.com/websockets/v3", 12345, "en", "https://myapp.com")
if err != nil {
	log.Fatal(err)
}

func (*Client) AccountList

func (api *Client) AccountList(ctx context.Context, r schema.AccountList) (resp schema.AccountListResp, err error)

AccountList Returns all accounts belonging to the authorized user.

func (*Client) ActiveSymbols

func (api *Client) ActiveSymbols(ctx context.Context, r schema.ActiveSymbols) (resp schema.ActiveSymbolsResp, err error)

ActiveSymbols Retrieve a list of all currently active symbols (underlying markets upon which contracts are available for trading).

func (*Client) ApiToken

func (api *Client) ApiToken(ctx context.Context, r schema.ApiToken) (resp schema.ApiTokenResp, err error)

ApiToken This call manages API tokens

func (*Client) AppDelete

func (api *Client) AppDelete(ctx context.Context, r schema.AppDelete) (resp schema.AppDeleteResp, err error)

AppDelete The request for deleting an application.

func (*Client) AppGet

func (api *Client) AppGet(ctx context.Context, r schema.AppGet) (resp schema.AppGetResp, err error)

AppGet To get the information of the OAuth application specified by 'app_id'

func (*Client) AppList

func (api *Client) AppList(ctx context.Context, r schema.AppList) (resp schema.AppListResp, err error)

AppList List all of the account's OAuth applications

func (*Client) AppMarkupDetails

func (api *Client) AppMarkupDetails(ctx context.Context, r schema.AppMarkupDetails) (resp schema.AppMarkupDetailsResp, err error)

AppMarkupDetails Retrieve details of `app_markup` according to criteria specified.

func (*Client) AppMarkupStatistics

func (api *Client) AppMarkupStatistics(ctx context.Context, r schema.AppMarkupStatistics) (resp schema.AppMarkupStatisticsResp, err error)

AppMarkupStatistics Retrieve statistics of `app_markup`.

func (*Client) AppRegister

func (api *Client) AppRegister(ctx context.Context, r schema.AppRegister) (resp schema.AppRegisterResp, err error)

AppRegister Register a new OAuth application

func (*Client) AppUpdate

func (api *Client) AppUpdate(ctx context.Context, r schema.AppUpdate) (resp schema.AppUpdateResp, err error)

AppUpdate Update a new OAuth application

func (*Client) AssetIndex

func (api *Client) AssetIndex(ctx context.Context, r schema.AssetIndex) (resp schema.AssetIndexResp, err error)

AssetIndex Retrieve a list of all available underlyings and the corresponding contract types and duration boundaries. If the user is logged in, only the assets available for that user's landing company will be returned.

func (*Client) Authorize

func (api *Client) Authorize(ctx context.Context, r schema.Authorize) (resp schema.AuthorizeResp, err error)

Authorize Authorize current WebSocket session to act on behalf of the owner of a given token. Must precede requests that need to access client account, for example purchasing and selling contracts or viewing portfolio.

func (*Client) Balance

func (api *Client) Balance(ctx context.Context, r schema.Balance) (resp schema.BalanceResp, err error)

Balance Get user account balance

func (*Client) Buy

func (api *Client) Buy(ctx context.Context, r schema.Buy) (resp schema.BuyResp, err error)

Buy Buy a Contract

func (*Client) BuyContractForMultipleAccounts

func (api *Client) BuyContractForMultipleAccounts(ctx context.Context, r schema.BuyContractForMultipleAccounts) (resp schema.BuyContractForMultipleAccountsResp, err error)

BuyContractForMultipleAccounts Buy a Contract for multiple Accounts specified by the `tokens` parameter. Note, although this is an authorized call, the contract is not bought for the authorized account.

func (*Client) Cancel

func (api *Client) Cancel(ctx context.Context, r schema.Cancel) (resp schema.CancelResp, err error)

Cancel Cancel contract with contract id

func (*Client) Cashier

func (api *Client) Cashier(ctx context.Context, r schema.Cashier) (resp schema.CashierResp, err error)

Cashier Request the cashier info for the specified type.

func (*Client) ConfirmEmail

func (api *Client) ConfirmEmail(ctx context.Context, r schema.ConfirmEmail) (resp schema.ConfirmEmailResp, err error)

ConfirmEmail Verifies the email for the user using verification code passed in the request object

func (*Client) Connect

func (api *Client) Connect() error

Connect establishes a WebSocket connection with the Deriv API endpoint. Returns an error if it fails to connect to WebSoket server.

func (*Client) ContractUpdate

func (api *Client) ContractUpdate(ctx context.Context, r schema.ContractUpdate) (resp schema.ContractUpdateResp, err error)

ContractUpdate Update a contract condition.

func (*Client) ContractUpdateHistory

func (api *Client) ContractUpdateHistory(ctx context.Context, r schema.ContractUpdateHistory) (resp schema.ContractUpdateHistoryResp, err error)

ContractUpdateHistory Request for contract update history.

func (*Client) ContractsFor

func (api *Client) ContractsFor(ctx context.Context, r schema.ContractsFor) (resp schema.ContractsForResp, err error)

ContractsFor For a given symbol, get the list of currently available contracts, and the latest barrier and duration limits for each contract.

func (*Client) ContractsForCompany

func (api *Client) ContractsForCompany(ctx context.Context, r schema.ContractsForCompany) (resp schema.ContractsForCompanyResp, err error)

ContractsForCompany Get the list of currently available contracts for a given landing company.

func (*Client) CopyStart

func (api *Client) CopyStart(ctx context.Context, r schema.CopyStart) (resp schema.CopyStartResp, err error)

CopyStart Start copy trader bets

func (*Client) CopyStop

func (api *Client) CopyStop(ctx context.Context, r schema.CopyStop) (resp schema.CopyStopResp, err error)

CopyStop Stop copy trader bets

func (*Client) CopytradingList

func (api *Client) CopytradingList(ctx context.Context, r schema.CopytradingList) (resp schema.CopytradingListResp, err error)

CopytradingList Retrieves a list of active copiers and/or traders for Copy Trading

func (*Client) CopytradingStatistics

func (api *Client) CopytradingStatistics(ctx context.Context, r schema.CopytradingStatistics) (resp schema.CopytradingStatisticsResp, err error)

CopytradingStatistics Retrieve performance, trading, risk and copiers statistics of trader.

func (*Client) CryptoConfig

func (api *Client) CryptoConfig(ctx context.Context, r schema.CryptoConfig) (resp schema.CryptoConfigResp, err error)

CryptoConfig The request for cryptocurrencies configuration.

func (*Client) CryptoEstimations

func (api *Client) CryptoEstimations(ctx context.Context, r schema.CryptoEstimations) (resp schema.CryptoEstimationsResp, err error)

CryptoEstimations Get the current estimations for cryptocurrencies. E.g. Withdrawal fee.

func (*Client) Disconnect

func (api *Client) Disconnect()

Disconnect gracefully disconnects from the Deriv API WebSocket server and cleans up any resources associated with the connection. This function should only be called after the WebSocket connection has been established using the Connect method.

func (*Client) DocumentUpload

func (api *Client) DocumentUpload(ctx context.Context, r schema.DocumentUpload) (resp schema.DocumentUploadResp, err error)

DocumentUpload Request KYC information from client

func (*Client) EconomicCalendar

func (api *Client) EconomicCalendar(ctx context.Context, r schema.EconomicCalendar) (resp schema.EconomicCalendarResp, err error)

EconomicCalendar Specify a currency to receive a list of events related to that specific currency. For example, specifying USD will return a list of USD-related events. If the currency is omitted, you will receive a list for all currencies.

func (*Client) ExchangeRates

func (api *Client) ExchangeRates(ctx context.Context, r schema.ExchangeRates) (resp schema.ExchangeRatesResp, err error)

ExchangeRates Retrieves the exchange rate from a base currency to a target currency supported by the system.

func (*Client) ExchangeVerificationCode

func (api *Client) ExchangeVerificationCode(ctx context.Context, r schema.ExchangeVerificationCode) (resp schema.ExchangeVerificationCodeResp, err error)

ExchangeVerificationCode Verifies the code and returns a new code if verification is successful

func (*Client) FinancialAssessmentQuestions

func (api *Client) FinancialAssessmentQuestions(ctx context.Context, r schema.FinancialAssessmentQuestions) (resp schema.FinancialAssessmentQuestionsResp, err error)

FinancialAssessmentQuestions This call gets the financial assessment questionnaire structure, which defines the questions, possible answers, and flow logic for the financial assessment form.

func (*Client) Forget

func (api *Client) Forget(ctx context.Context, r schema.Forget) (resp schema.ForgetResp, err error)

Forget Immediately cancel the real-time stream of messages with a specific ID.

func (*Client) ForgetAll

func (api *Client) ForgetAll(ctx context.Context, r schema.ForgetAll) (resp schema.ForgetAllResp, err error)

ForgetAll Immediately cancel the real-time streams of messages of given type.

func (*Client) GetAccountStatus

func (api *Client) GetAccountStatus(ctx context.Context, r schema.GetAccountStatus) (resp schema.GetAccountStatusResp, err error)

GetAccountStatus Get Account Status

func (*Client) GetFinancialAssessment

func (api *Client) GetFinancialAssessment(ctx context.Context, r schema.GetFinancialAssessment) (resp schema.GetFinancialAssessmentResp, err error)

GetFinancialAssessment This call gets the financial assessment details. The 'financial assessment' is a questionnaire that clients of certain Landing Companies need to complete, due to regulatory and KYC (know your client) requirements.

func (*Client) GetLimits

func (api *Client) GetLimits(ctx context.Context, r schema.GetLimits) (resp schema.GetLimitsResp, err error)

GetLimits Trading and Withdrawal Limits for a given user

func (*Client) GetSelfExclusion

func (api *Client) GetSelfExclusion(ctx context.Context, r schema.GetSelfExclusion) (resp schema.GetSelfExclusionResp, err error)

GetSelfExclusion Allows users to exclude themselves from the website for certain periods of time, or to set limits on their trading activities. This facility is a regulatory requirement for certain Landing Companies.

func (*Client) GetSettings

func (api *Client) GetSettings(ctx context.Context, r schema.GetSettings) (resp schema.GetSettingsResp, err error)

GetSettings Get User Settings (email, date of birth, address etc)

func (*Client) GetThirdPartyRedirect

func (api *Client) GetThirdPartyRedirect(ctx context.Context, r schema.GetThirdPartyRedirect) (resp schema.GetThirdPartyRedirectResp, err error)

GetThirdPartyRedirect Get Third Party Redirect URL for sso login.

func (*Client) IdentityVerificationDocumentAdd

func (api *Client) IdentityVerificationDocumentAdd(ctx context.Context, r schema.IdentityVerificationDocumentAdd) (resp schema.IdentityVerificationDocumentAddResp, err error)

IdentityVerificationDocumentAdd Adds document information such as issuing country, id and type for identity verification processes.

func (*Client) KycAuthStatus

func (api *Client) KycAuthStatus(ctx context.Context, r schema.KycAuthStatus) (resp schema.KycAuthStatusResp, err error)

KycAuthStatus Get KYC Authentication Status

func (*Client) LandingCompany

func (api *Client) LandingCompany(ctx context.Context, r schema.LandingCompany) (resp schema.LandingCompanyResp, err error)

LandingCompany The company has a number of licensed subsidiaries in various jurisdictions, which are called Landing Companies. This call will return the appropriate Landing Company for clients of a given country. The landing company may differ for derived contracts (Synthetic Indices) and Financial contracts (Forex, Stock Indices, Commodities).

func (*Client) LandingCompanyDetails

func (api *Client) LandingCompanyDetails(ctx context.Context, r schema.LandingCompanyDetails) (resp schema.LandingCompanyDetailsResp, err error)

LandingCompanyDetails The company has a number of licensed subsidiaries in various jurisdictions, which are called Landing Companies (and which are wholly owned subsidiaries of the Deriv Group). This call provides information about each Landing Company.

func (*Client) LoginHistory

func (api *Client) LoginHistory(ctx context.Context, r schema.LoginHistory) (resp schema.LoginHistoryResp, err error)

LoginHistory Retrieve a summary of login history for user.

func (*Client) Logout

func (api *Client) Logout(ctx context.Context, r schema.Logout) (resp schema.LogoutResp, err error)

Logout Logout the session

func (*Client) Mt5Deposit

func (api *Client) Mt5Deposit(ctx context.Context, r schema.Mt5Deposit) (resp schema.Mt5DepositResp, err error)

Mt5Deposit This call allows deposit into MT5 account from Binary account.

func (*Client) Mt5GetSettings

func (api *Client) Mt5GetSettings(ctx context.Context, r schema.Mt5GetSettings) (resp schema.Mt5GetSettingsResp, err error)

Mt5GetSettings Get MT5 user account settings

func (*Client) Mt5LoginList

func (api *Client) Mt5LoginList(ctx context.Context, r schema.Mt5LoginList) (resp schema.Mt5LoginListResp, err error)

Mt5LoginList Get list of MT5 accounts for client

func (*Client) Mt5NewAccount

func (api *Client) Mt5NewAccount(ctx context.Context, r schema.Mt5NewAccount) (resp schema.Mt5NewAccountResp, err error)

Mt5NewAccount This call creates new MT5 user, either demo or real money user.

func (*Client) Mt5PasswordChange

func (api *Client) Mt5PasswordChange(ctx context.Context, r schema.Mt5PasswordChange) (resp schema.Mt5PasswordChangeResp, err error)

Mt5PasswordChange To change passwords of the MT5 account.

func (*Client) Mt5PasswordCheck

func (api *Client) Mt5PasswordCheck(ctx context.Context, r schema.Mt5PasswordCheck) (resp schema.Mt5PasswordCheckResp, err error)

Mt5PasswordCheck This call validates the main password for the MT5 user

func (*Client) Mt5PasswordReset

func (api *Client) Mt5PasswordReset(ctx context.Context, r schema.Mt5PasswordReset) (resp schema.Mt5PasswordResetResp, err error)

Mt5PasswordReset To reset the password of MT5 account.

func (*Client) Mt5Withdrawal

func (api *Client) Mt5Withdrawal(ctx context.Context, r schema.Mt5Withdrawal) (resp schema.Mt5WithdrawalResp, err error)

Mt5Withdrawal This call allows withdrawal from MT5 account to Binary account.

func (*Client) NewAccountMaltainvest

func (api *Client) NewAccountMaltainvest(ctx context.Context, r schema.NewAccountMaltainvest) (resp schema.NewAccountMaltainvestResp, err error)

NewAccountMaltainvest This call opens a new real-money account with the `maltainvest` Landing Company. This call can be made from a virtual-money account or real-money account at Deriv (Europe) Limited. If it is the latter, client information fields in this call will be ignored and data from your existing real-money account will be used.

func (*Client) NewAccountReal

func (api *Client) NewAccountReal(ctx context.Context, r schema.NewAccountReal) (resp schema.NewAccountRealResp, err error)

NewAccountReal This call opens a new real-money account. This call can be made from a virtual-money or a real-money account. If it is the latter, client information fields in this call will be ignored and data from your existing real-money account will be used.

func (*Client) NewAccountVirtual

func (api *Client) NewAccountVirtual(ctx context.Context, r schema.NewAccountVirtual) (resp schema.NewAccountVirtualResp, err error)

NewAccountVirtual Create a new virtual-money account.

func (*Client) NewPartnerAccount

func (api *Client) NewPartnerAccount(ctx context.Context, r schema.NewPartnerAccount) (resp schema.NewPartnerAccountResp, err error)

NewPartnerAccount This call opens a new Real-Partner Account

func (*Client) OauthApps

func (api *Client) OauthApps(ctx context.Context, r schema.OauthApps) (resp schema.OauthAppsResp, err error)

OauthApps List all my used OAuth applications.

func (*Client) P2PAdvertCreate

func (api *Client) P2PAdvertCreate(ctx context.Context, r schema.P2PAdvertCreate) (resp schema.P2PAdvertCreateResp, err error)

P2PAdvertCreate Creates a P2P (Peer to Peer) advert. Can only be used by an approved P2P advertiser.

func (*Client) P2PAdvertInfo

func (api *Client) P2PAdvertInfo(ctx context.Context, r schema.P2PAdvertInfo) (resp schema.P2PAdvertInfoResp, err error)

P2PAdvertInfo Retrieve information about a P2P advert.

func (*Client) P2PAdvertList

func (api *Client) P2PAdvertList(ctx context.Context, r schema.P2PAdvertList) (resp schema.P2PAdvertListResp, err error)

P2PAdvertList Returns available adverts for use with `p2p_order_create` .

func (*Client) P2PAdvertUpdate

func (api *Client) P2PAdvertUpdate(ctx context.Context, r schema.P2PAdvertUpdate) (resp schema.P2PAdvertUpdateResp, err error)

P2PAdvertUpdate Updates a P2P advert. Can only be used by the advertiser.

func (*Client) P2PAdvertiserAdverts

func (api *Client) P2PAdvertiserAdverts(ctx context.Context, r schema.P2PAdvertiserAdverts) (resp schema.P2PAdvertiserAdvertsResp, err error)

P2PAdvertiserAdverts Returns all P2P adverts created by the authorized client. Can only be used by a registered P2P advertiser.

func (*Client) P2PAdvertiserCreate

func (api *Client) P2PAdvertiserCreate(ctx context.Context, r schema.P2PAdvertiserCreate) (resp schema.P2PAdvertiserCreateResp, err error)

P2PAdvertiserCreate Registers the client as a P2P advertiser.

func (*Client) P2PAdvertiserInfo

func (api *Client) P2PAdvertiserInfo(ctx context.Context, r schema.P2PAdvertiserInfo) (resp schema.P2PAdvertiserInfoResp, err error)

P2PAdvertiserInfo Retrieve information about a P2P advertiser.

func (*Client) P2PAdvertiserList

func (api *Client) P2PAdvertiserList(ctx context.Context, r schema.P2PAdvertiserList) (resp schema.P2PAdvertiserListResp, err error)

P2PAdvertiserList Retrieve advertisers has/had trade with the current advertiser.

func (*Client) P2PAdvertiserPaymentMethods

func (api *Client) P2PAdvertiserPaymentMethods(ctx context.Context, r schema.P2PAdvertiserPaymentMethods) (resp schema.P2PAdvertiserPaymentMethodsResp, err error)

P2PAdvertiserPaymentMethods Manage or list P2P advertiser payment methods.

func (*Client) P2PAdvertiserRelations

func (api *Client) P2PAdvertiserRelations(ctx context.Context, r schema.P2PAdvertiserRelations) (resp schema.P2PAdvertiserRelationsResp, err error)

P2PAdvertiserRelations Updates and returns favourite and blocked advertisers of the current user.

func (*Client) P2PAdvertiserUpdate

func (api *Client) P2PAdvertiserUpdate(ctx context.Context, r schema.P2PAdvertiserUpdate) (resp schema.P2PAdvertiserUpdateResp, err error)

P2PAdvertiserUpdate Update the information of the P2P advertiser for the current account. Can only be used by an approved P2P advertiser.

func (*Client) P2PChatCreate

func (api *Client) P2PChatCreate(ctx context.Context, r schema.P2PChatCreate) (resp schema.P2PChatCreateResp, err error)

P2PChatCreate Creates a P2P chat for the specified order.

func (*Client) P2PCountryList

func (api *Client) P2PCountryList(ctx context.Context, r schema.P2PCountryList) (resp schema.P2PCountryListResp, err error)

P2PCountryList List all or specific country and its payment methods.

func (*Client) P2POrderCancel

func (api *Client) P2POrderCancel(ctx context.Context, r schema.P2POrderCancel) (resp schema.P2POrderCancelResp, err error)

P2POrderCancel Cancel a P2P order.

func (*Client) P2POrderConfirm

func (api *Client) P2POrderConfirm(ctx context.Context, r schema.P2POrderConfirm) (resp schema.P2POrderConfirmResp, err error)

P2POrderConfirm Confirm a P2P order.

func (*Client) P2POrderCreate

func (api *Client) P2POrderCreate(ctx context.Context, r schema.P2POrderCreate) (resp schema.P2POrderCreateResp, err error)

P2POrderCreate Creates a P2P order for the specified advert.

func (*Client) P2POrderDispute

func (api *Client) P2POrderDispute(ctx context.Context, r schema.P2POrderDispute) (resp schema.P2POrderDisputeResp, err error)

P2POrderDispute Dispute a P2P order.

func (*Client) P2POrderInfo

func (api *Client) P2POrderInfo(ctx context.Context, r schema.P2POrderInfo) (resp schema.P2POrderInfoResp, err error)

P2POrderInfo Retrieves the information about a P2P order.

func (*Client) P2POrderList

func (api *Client) P2POrderList(ctx context.Context, r schema.P2POrderList) (resp schema.P2POrderListResp, err error)

P2POrderList List active orders.

func (*Client) P2POrderReview

func (api *Client) P2POrderReview(ctx context.Context, r schema.P2POrderReview) (resp schema.P2POrderReviewResp, err error)

P2POrderReview Creates a review for the specified order.

func (*Client) P2PPaymentMethods

func (api *Client) P2PPaymentMethods(ctx context.Context, r schema.P2PPaymentMethods) (resp schema.P2PPaymentMethodsResp, err error)

P2PPaymentMethods List all P2P payment methods.

func (*Client) P2PPing

func (api *Client) P2PPing(ctx context.Context, r schema.P2PPing) (resp schema.P2PPingResp, err error)

P2PPing Keeps the connection alive and updates the P2P advertiser's online status. The advertiser will be considered offline 60 seconds after a call is made.

func (*Client) P2PSettings

func (api *Client) P2PSettings(ctx context.Context, r schema.P2PSettings) (resp schema.P2PSettingsResp, err error)

P2PSettings Request P2P Settings information.

func (*Client) PartnerAccountCreation

func (api *Client) PartnerAccountCreation(ctx context.Context, r schema.PartnerAccountCreation) (resp schema.PartnerAccountCreationResp, err error)

PartnerAccountCreation This call initiates the state machine for account creation process

func (*Client) PartnerAccountCreationStatus

func (api *Client) PartnerAccountCreationStatus(ctx context.Context, r schema.PartnerAccountCreationStatus) (resp schema.PartnerAccountCreationStatusResp, err error)

PartnerAccountCreationStatus This call polls the state machine and returns the completion status for each step.

func (*Client) PartnerAccounts

func (api *Client) PartnerAccounts(ctx context.Context, r schema.PartnerAccounts) (resp schema.PartnerAccountsResp, err error)

PartnerAccounts Get All Partner Accounts (Partner account details like website, provider, company details)

func (*Client) PartnerSettings

func (api *Client) PartnerSettings(ctx context.Context, r schema.PartnerSettings) (resp schema.PartnerSettingsResp, err error)

PartnerSettings Get Partner Settings (Partner Type, Company Details etc)

func (*Client) PartnerSettingsUpdate

func (api *Client) PartnerSettingsUpdate(ctx context.Context, r schema.PartnerSettingsUpdate) (resp schema.PartnerSettingsUpdateResp, err error)

PartnerSettingsUpdate A message with Partner Settings

func (*Client) PaymentMethods

func (api *Client) PaymentMethods(ctx context.Context, r schema.PaymentMethods) (resp schema.PaymentMethodsResp, err error)

PaymentMethods Will return a list payment methods available for the given country. If the request is authenticated the client's residence country will be used.

func (*Client) PaymentagentCreate

func (api *Client) PaymentagentCreate(ctx context.Context, r schema.PaymentagentCreate) (resp schema.PaymentagentCreateResp, err error)

PaymentagentCreate Saves client's payment agent details.

func (*Client) PaymentagentDetails

func (api *Client) PaymentagentDetails(ctx context.Context, r schema.PaymentagentDetails) (resp schema.PaymentagentDetailsResp, err error)

PaymentagentDetails Gets client's payment agent details.

func (*Client) PaymentagentList

func (api *Client) PaymentagentList(ctx context.Context, r schema.PaymentagentList) (resp schema.PaymentagentListResp, err error)

PaymentagentList Will return a list of Payment Agents for a given country for a given currency. Payment agents allow users to deposit and withdraw funds using local payment methods that might not be available via the main website's cashier system.

func (*Client) PaymentagentTransfer

func (api *Client) PaymentagentTransfer(ctx context.Context, r schema.PaymentagentTransfer) (resp schema.PaymentagentTransferResp, err error)

PaymentagentTransfer Payment Agent Transfer - this call is available only to accounts that are approved Payment Agents.

func (*Client) PaymentagentWithdraw

func (api *Client) PaymentagentWithdraw(ctx context.Context, r schema.PaymentagentWithdraw) (resp schema.PaymentagentWithdrawResp, err error)

PaymentagentWithdraw Initiate a withdrawal to an approved Payment Agent.

func (*Client) PaymentagentWithdrawJustification

func (api *Client) PaymentagentWithdrawJustification(ctx context.Context, r schema.PaymentagentWithdrawJustification) (resp schema.PaymentagentWithdrawJustificationResp, err error)

PaymentagentWithdrawJustification Provide justification to perform withdrawal using a Payment Agent.

func (*Client) PayoutCurrencies

func (api *Client) PayoutCurrencies(ctx context.Context, r schema.PayoutCurrencies) (resp schema.PayoutCurrenciesResp, err error)

PayoutCurrencies Retrieve a list of available option payout currencies. If a user is logged in, only the currencies available for the account will be returned.

func (*Client) Ping

func (api *Client) Ping(ctx context.Context, r schema.Ping) (resp schema.PingResp, err error)

Ping To send the ping request to the server. Mostly used to test the connection or to keep it alive.

func (*Client) Portfolio

func (api *Client) Portfolio(ctx context.Context, r schema.Portfolio) (resp schema.PortfolioResp, err error)

Portfolio Receive information about my current portfolio of outstanding options

func (*Client) ProfitTable

func (api *Client) ProfitTable(ctx context.Context, r schema.ProfitTable) (resp schema.ProfitTableResp, err error)

ProfitTable Retrieve a summary of account Profit Table, according to given search criteria

func (*Client) Proposal

func (api *Client) Proposal(ctx context.Context, r schema.Proposal) (resp schema.ProposalResp, err error)

Proposal Gets latest price for a specific contract.

func (*Client) ProposalOpenContract

func (api *Client) ProposalOpenContract(ctx context.Context, r schema.ProposalOpenContract) (resp schema.ProposalOpenContractResp, err error)

ProposalOpenContract Get latest price (and other information) for a contract in the user's portfolio

func (*Client) RealityCheck

func (api *Client) RealityCheck(ctx context.Context, r schema.RealityCheck) (resp schema.RealityCheckResp, err error)

RealityCheck Retrieve summary of client's trades and account for the Reality Check facility. A 'reality check' means a display of time elapsed since the session began, and associated client profit/loss. The Reality Check facility is a regulatory requirement for certain landing companies.

func (*Client) ResidenceList

func (api *Client) ResidenceList(ctx context.Context, r schema.ResidenceList) (resp schema.ResidenceListResp, err error)

ResidenceList This call returns a list of countries and 2-letter country codes, suitable for populating the account opening form.

func (*Client) RevokeOauthApp

func (api *Client) RevokeOauthApp(ctx context.Context, r schema.RevokeOauthApp) (resp schema.RevokeOauthAppResp, err error)

RevokeOauthApp Used for revoking access of particular app.

func (*Client) Sell

func (api *Client) Sell(ctx context.Context, r schema.Sell) (resp schema.SellResp, err error)

Sell Sell a Contract as identified from a previous `portfolio` call.

func (*Client) SellContractForMultipleAccounts

func (api *Client) SellContractForMultipleAccounts(ctx context.Context, r schema.SellContractForMultipleAccounts) (resp schema.SellContractForMultipleAccountsResp, err error)

SellContractForMultipleAccounts Sell contracts for multiple accounts simultaneously. Uses the shortcode response from `buy_contract_for_multiple_accounts` to identify the contract, and authorisation tokens to select which accounts to sell those contracts on. Note that only the accounts identified by the tokens will be affected. This will not sell the contract on the currently-authorised account unless you include the token for the current account.

func (*Client) SellExpired

func (api *Client) SellExpired(ctx context.Context, r schema.SellExpired) (resp schema.SellExpiredResp, err error)

SellExpired This call will try to sell any expired contracts and return the number of sold contracts.

func (*Client) Send

func (api *Client) Send(ctx context.Context, reqID int, request any) (chan []byte, error)

Send sends a request to the Deriv API and returns a channel that will receive the response

func (*Client) SendRequest

func (api *Client) SendRequest(ctx context.Context, reqID int, request, response any) error

SendRequest sends a request to the Deriv API and returns the response

func (*Client) SetAccountCurrency

func (api *Client) SetAccountCurrency(ctx context.Context, r schema.SetAccountCurrency) (resp schema.SetAccountCurrencyResp, err error)

SetAccountCurrency Set account currency, this will be default currency for your account i.e currency for trading, deposit. Please note that account currency can only be set once, and then can never be changed.

func (*Client) SetFinancialAssessment

func (api *Client) SetFinancialAssessment(ctx context.Context, r schema.SetFinancialAssessment) (resp schema.SetFinancialAssessmentResp, err error)

SetFinancialAssessment This call sets the financial assessment details based on the client's answers to analyze whether they possess the experience and knowledge to understand the risks involved with binary options trading.

func (*Client) SetSelfExclusion

func (api *Client) SetSelfExclusion(ctx context.Context, r schema.SetSelfExclusion) (resp schema.SetSelfExclusionResp, err error)

SetSelfExclusion Set Self-Exclusion (this call should be used in conjunction with `get_self_exclusion`)

func (*Client) SetSettings

func (api *Client) SetSettings(ctx context.Context, r schema.SetSettings) (resp schema.SetSettingsResp, err error)

SetSettings Set User Settings (this call should be used in conjunction with `get_settings`)

func (*Client) Statement

func (api *Client) Statement(ctx context.Context, r schema.Statement) (resp schema.StatementResp, err error)

Statement Retrieve a summary of account transactions, according to given search criteria

func (*Client) StatesList

func (api *Client) StatesList(ctx context.Context, r schema.StatesList) (resp schema.StatesListResp, err error)

StatesList For a given country, returns a list of States of that country. This is useful to populate the account opening form.

func (*Client) SubscribeBalance

func (api *Client) SubscribeBalance(ctx context.Context, r schema.Balance) (rsp schema.BalanceResp, s *Subsciption[schema.BalanceResp, schema.BalanceResp], err error)

SubscribeBalance Get user account balance

func (*Client) SubscribeBuy

SubscribeBuy Buy a Contract

func (*Client) SubscribeCandlesHistory

SubscribeTicksHistory Get historic candles data for a given symbol.

func (*Client) SubscribeCryptoEstimations

SubscribeCryptoEstimations Get the current estimations for cryptocurrencies. E.g. Withdrawal fee.

func (*Client) SubscribeExchangeRates

SubscribeExchangeRates Retrieves the exchange rate from a base currency to a target currency supported by the system.

func (*Client) SubscribeP2PAdvertInfo

SubscribeP2PAdvertInfo Retrieve information about a P2P advert.

func (*Client) SubscribeP2PAdvertiserCreate

SubscribeP2PAdvertiserCreate Registers the client as a P2P advertiser.

func (*Client) SubscribeP2PAdvertiserInfo

SubscribeP2PAdvertiserInfo Retrieve information about a P2P advertiser.

func (*Client) SubscribeP2POrderCreate

SubscribeP2POrderCreate Creates a P2P order for the specified advert.

func (*Client) SubscribeP2POrderInfo

SubscribeP2POrderInfo Retrieves the information about a P2P order.

func (*Client) SubscribeP2POrderList

SubscribeP2POrderList List active orders.

func (*Client) SubscribeP2PSettings

SubscribeP2PSettings Request P2P Settings information.

func (*Client) SubscribeProposal

SubscribeProposal Gets latest price for a specific contract.

func (*Client) SubscribeProposalOpenContract

SubscribeProposalOpenContract Get latest price (and other information) for a contract in the user's portfolio

func (*Client) SubscribeTicks

func (api *Client) SubscribeTicks(ctx context.Context, r schema.Ticks) (rsp schema.TicksResp, s *Subsciption[schema.TicksResp, schema.TicksResp], err error)

SubscribeTicks Initiate a continuous stream of spot price updates for a given symbol.

func (*Client) SubscribeTicksBatch

SubscribeTicksBatch Initiate a continuous stream of spot price updates for a group symbols.

func (*Client) SubscribeTicksHistory

SubscribeTicksHistory Get historic tick data for a given symbol.

func (*Client) SubscribeTransaction

SubscribeTransaction Subscribe to transaction notifications

func (*Client) SubscribeWebsiteStatus

SubscribeWebsiteStatus Request server status.

func (*Client) Ticks

func (api *Client) Ticks(ctx context.Context, r schema.Ticks) (resp schema.TicksResp, err error)

Ticks Initiate a continuous stream of spot price updates for a given symbol.

func (*Client) TicksBatch

func (api *Client) TicksBatch(ctx context.Context, r schema.TicksBatch) (resp schema.TicksBatchResp, err error)

TicksBatch Initiate a continuous stream of spot price updates for a group symbols.

func (*Client) TicksHistory

func (api *Client) TicksHistory(ctx context.Context, r schema.TicksHistory) (resp schema.TicksHistoryResp, err error)

TicksHistory Get historic tick data for a given symbol.

func (*Client) Time

func (api *Client) Time(ctx context.Context, r schema.Time) (resp schema.TimeResp, err error)

Time Request back-end server epoch time.

func (*Client) TinValidations

func (api *Client) TinValidations(ctx context.Context, r schema.TinValidations) (resp schema.TinValidationsResp, err error)

TinValidations Get the validations for Tax Identification Numbers (TIN)

func (*Client) TncApproval

func (api *Client) TncApproval(ctx context.Context, r schema.TncApproval) (resp schema.TncApprovalResp, err error)

TncApproval To approve the latest version of terms and conditions.

func (*Client) TopupVirtual

func (api *Client) TopupVirtual(ctx context.Context, r schema.TopupVirtual) (resp schema.TopupVirtualResp, err error)

TopupVirtual When a virtual-money's account balance becomes low, it can be topped up using this call.

func (*Client) TradingDurations

func (api *Client) TradingDurations(ctx context.Context, r schema.TradingDurations) (resp schema.TradingDurationsResp, err error)

TradingDurations Retrieve a list of all available underlyings and the corresponding contract types and trading duration boundaries. If the user is logged in, only the assets available for that user's landing company will be returned.

func (*Client) TradingPlatformInvestorPasswordReset

func (api *Client) TradingPlatformInvestorPasswordReset(ctx context.Context, r schema.TradingPlatformInvestorPasswordReset) (resp schema.TradingPlatformInvestorPasswordResetResp, err error)

TradingPlatformInvestorPasswordReset Reset the investor password of a Trading Platform Account

func (*Client) TradingPlatformPasswordReset

func (api *Client) TradingPlatformPasswordReset(ctx context.Context, r schema.TradingPlatformPasswordReset) (resp schema.TradingPlatformPasswordResetResp, err error)

TradingPlatformPasswordReset Reset the password of a Trading Platform Account

func (*Client) TradingPlatformStatus

func (api *Client) TradingPlatformStatus(ctx context.Context, r schema.TradingPlatformStatus) (resp schema.TradingPlatformStatusResp, err error)

TradingPlatformStatus Request trading platform status

func (*Client) TradingServers

func (api *Client) TradingServers(ctx context.Context, r schema.TradingServers) (resp schema.TradingServersResp, err error)

TradingServers Get the list of servers for a trading platform.

func (*Client) TradingTimes

func (api *Client) TradingTimes(ctx context.Context, r schema.TradingTimes) (resp schema.TradingTimesResp, err error)

TradingTimes Receive a list of market opening times for a given date.

func (*Client) Transaction

func (api *Client) Transaction(ctx context.Context, r schema.Transaction) (resp schema.TransactionResp, err error)

Transaction Subscribe to transaction notifications

func (*Client) TransferBetweenAccounts

func (api *Client) TransferBetweenAccounts(ctx context.Context, r schema.TransferBetweenAccounts) (resp schema.TransferBetweenAccountsResp, err error)

TransferBetweenAccounts This call allows transfers between accounts held by a given user. Transfer funds between your fiat and cryptocurrency accounts (for a fee). Please note that account_from should be same as current authorized account.

func (*Client) UnsubscribeEmail

func (api *Client) UnsubscribeEmail(ctx context.Context, r schema.UnsubscribeEmail) (resp schema.UnsubscribeEmailResp, err error)

UnsubscribeEmail It unsubscribe user from the email subscription.

func (*Client) VerifyEmail

func (api *Client) VerifyEmail(ctx context.Context, r schema.VerifyEmail) (resp schema.VerifyEmailResp, err error)

VerifyEmail Verify an email address for various purposes. The system will send an email to the address containing a security code for verification.

func (*Client) WebsiteConfig

func (api *Client) WebsiteConfig(ctx context.Context, r schema.WebsiteConfig) (resp schema.WebsiteConfigResp, err error)

WebsiteConfig Request server config.

func (*Client) WebsiteStatus

func (api *Client) WebsiteStatus(ctx context.Context, r schema.WebsiteStatus) (resp schema.WebsiteStatusResp, err error)

WebsiteStatus Request server status.

type Subsciption

type Subsciption[initResp any, Resp any] struct {
	API           *Client
	Stream        chan Resp
	SubsciptionID string
	// contains filtered or unexported fields
}

Subscription represents a subscription instance.

func NewSubcription

func NewSubcription[initResp any, Resp any](ctx context.Context, api *Client) *Subsciption[initResp, Resp]

NewSubscription creates and returns a new Subscription instance with the given DerivAPI client. The Subscription instance has a Stream channel that will receive subscription updates, and an IsActive boolean that is set to false initially.

func (*Subsciption[initResp, Resp]) Forget

func (s *Subsciption[initResp, Resp]) Forget() error

Forget cancels an active subscription by sending a Forget request to the API using the DerivAPI.Forget method. If the subscription is not currently active, this method does nothing. If an error occurs while sending the Forget request, it returns the error.

func (*Subsciption[initResp, Resp]) GetStream

func (s *Subsciption[initResp, Resp]) GetStream() chan Resp

GetStream returns the Stream channel of the Subscription instance.

func (*Subsciption[initResp, Resp]) IsActive

func (s *Subsciption[initResp, Resp]) IsActive() bool

IsActive returns the IsActive field of the Subscription instance.

func (*Subsciption[initResp, Resp]) Start

func (s *Subsciption[initResp, Resp]) Start(reqID int, request any) (initResp, error)

Start starts a new subscription by sending a subscription request to the API using the DerivAPI.Send method. If an error occurs while sending the subscription request, it returns the error. If the subscription request is successful, the method receives the initial response from the API on a channel, and then calls the parseSubscription function to deserialize the response into a SubscriptionResponse struct. If an error occurs during deserialization, the method returns the error. If deserialization is successful, the SubsciptionID field of the Subscription instance is set to the subscription ID returned by the API, and the IsActive field is set to true. The method then sends the initial subscription update to the Stream channel, and starts a new goroutine to handle subsequent updates received on the channel.

type SubscriptionIDResponse

type SubscriptionIDResponse struct {
	ID string `json:"id"`
}

type SubscriptionResponse

type SubscriptionResponse struct {
	Error        APIError               `json:"error"`
	Subscription SubscriptionIDResponse `json:"subscription,omitempty"`
}

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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