bitflyer

package
v0.0.0-...-f003305 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: MPL-2.0 Imports: 21 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewWithdrawsFromTxs

func NewWithdrawsFromTxs(
	sourceFrom string,
	txs []custodian.Transaction,
) (*[]WithdrawToDepositIDPayload, error)

NewWithdrawsFromTxs creates an array of withdrawal requests

Types

type CheckBulkStatusPayload

type CheckBulkStatusPayload struct {
	Withdrawals []CheckStatusPayload `json:"withdrawals"`
}

CheckBulkStatusPayload holds info for checking the status of a transfer

func TransferIDsToBulkStatus

func TransferIDsToBulkStatus(transferIDs []string) CheckBulkStatusPayload

TransferIDsToBulkStatus takes a list of transferIDs and turns them into a payload for checking their status

type CheckStatusPayload

type CheckStatusPayload struct {
	TransferID string `json:"transfer_id"`
}

CheckStatusPayload holds the transfer id to check

type Client

type Client interface {
	// FetchQuote gets a quote of BAT to JPY
	FetchQuote(ctx context.Context, productCode string, readFromFile bool) (*Quote, error)
	// UploadBulkPayout posts a signed bulk layout to bitflyer
	UploadBulkPayout(ctx context.Context, payload WithdrawToDepositIDBulkPayload) (*WithdrawToDepositIDBulkResponse, error)
	// CheckPayoutStatus checks the status of a transaction
	CheckPayoutStatus(ctx context.Context, payload CheckBulkStatusPayload) (*WithdrawToDepositIDBulkResponse, error)
	// CheckInventory check available balance of bitflyer account
	CheckInventory(ctx context.Context) (map[string]Inventory, error)
	// RefreshToken refreshes the token belonging to the provided secret values
	RefreshToken(ctx context.Context, payload TokenPayload) (*TokenResponse, error)
	// SetAuthToken sets the auth token on underlying client object
	SetAuthToken(authToken string)
	// FetchBalance requests balance information for the auth token on the underlying client object
	FetchBalance(ctx context.Context) (*InventoryResponse, error)
}

Client abstracts over the underlying client

func New

func New() (Client, error)

New returns a new HTTPClient, retrieving the base URL from the environment

type ClientWithPrometheus

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

ClientWithPrometheus implements Client interface with all methods wrapped with Prometheus metrics

func NewClientWithPrometheus

func NewClientWithPrometheus(base Client, instanceName string) ClientWithPrometheus

NewClientWithPrometheus returns an instance of the Client decorated with prometheus summary metric

func (ClientWithPrometheus) CheckInventory

func (_d ClientWithPrometheus) CheckInventory(ctx context.Context) (m1 map[string]Inventory, err error)

CheckInventory implements Client

func (ClientWithPrometheus) CheckPayoutStatus

CheckPayoutStatus implements Client

func (ClientWithPrometheus) FetchBalance

func (_d ClientWithPrometheus) FetchBalance(ctx context.Context) (ip1 *InventoryResponse, err error)

FetchBalance implements Client

func (ClientWithPrometheus) FetchQuote

func (_d ClientWithPrometheus) FetchQuote(ctx context.Context, productCode string, readFromFile bool) (qp1 *Quote, err error)

FetchQuote implements Client

func (ClientWithPrometheus) RefreshToken

func (_d ClientWithPrometheus) RefreshToken(ctx context.Context, payload TokenPayload) (tp1 *TokenResponse, err error)

RefreshToken implements Client

func (ClientWithPrometheus) SetAuthToken

func (_d ClientWithPrometheus) SetAuthToken(authToken string)

SetAuthToken implements Client

func (ClientWithPrometheus) UploadBulkPayout

UploadBulkPayout implements Client

type DryRunOption

type DryRunOption struct {
	RequestAPITransferStatus string `json:"request_api_transfer_status"`
	ProcessTimeSec           uint   `json:"process_time_sec"`
	StatusAPITransferStatus  string `json:"status_api_transfer_status"`
}

DryRunOption holds options for dry running a transaction

type HTTPClient

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

HTTPClient wraps http.Client for interacting with the cbr server

func (*HTTPClient) CheckInventory

func (c *HTTPClient) CheckInventory(
	ctx context.Context,
) (map[string]Inventory, error)

CheckInventory fetches the current balances of an account

func (*HTTPClient) CheckPayoutStatus

CheckPayoutStatus checks bitflyer transaction status

func (*HTTPClient) FetchBalance

func (c *HTTPClient) FetchBalance(ctx context.Context) (*InventoryResponse, error)

FetchBalance requests balance information for the auth token on the underlying client object

func (*HTTPClient) FetchQuote

func (c *HTTPClient) FetchQuote(
	ctx context.Context,
	productCode string,
	readFromFile bool,
) (*Quote, error)

FetchQuote fetches prices for determining constraints

func (*HTTPClient) RefreshToken

func (c *HTTPClient) RefreshToken(ctx context.Context, payload TokenPayload) (*TokenResponse, error)

RefreshToken gets a new token from bitflyer

func (*HTTPClient) SetAuthToken

func (c *HTTPClient) SetAuthToken(authToken string)

SetAuthToken sets the auth token

func (*HTTPClient) UploadBulkPayout

UploadBulkPayout uploads payouts to bitflyer

type Inventory

type Inventory struct {
	CurrencyCode string          `json:"currency_code"`
	Amount       decimal.Decimal `json:"amount"`
	Available    decimal.Decimal `json:"available"`
}

Inventory holds the balance for a particular currency

type InventoryResponse

type InventoryResponse struct {
	AccountHash string      `json:"account_hash"`
	Inventory   []Inventory `json:"inventory"`
}

InventoryResponse is the response to a balance inquery

type PriceTokenInfo

type PriceTokenInfo struct {
	ProductCode string          `json:"product_code,omitempty"`
	Rate        decimal.Decimal `json:"rate,omitempty"`
	IssuedAt    int             `json:"iat,omitempty"`
	Expiry      int             `json:"exp,omitempty"`
}

PriceTokenInfo holds info from the price token

type Quote

type Quote struct {
	ProductCode  string          `json:"product_code"`
	MainCurrency string          `json:"main_currency"`
	SubCurrency  string          `json:"sub_currency"`
	Rate         decimal.Decimal `json:"rate"`
	PriceToken   string          `json:"price_token"`
}

Quote returns a quote of BAT prices

type QuoteQuery

type QuoteQuery struct {
	ProductCode string `url:"product_code,omitempty"`
}

QuoteQuery holds the query params for the quote

func (*QuoteQuery) GenerateQueryString

func (qq *QuoteQuery) GenerateQueryString() (url.Values, error)

GenerateQueryString - implement the QueryStringBody interface

type SavedQuote

type SavedQuote struct {
	Body   Quote     `json:"body"`
	Expiry time.Time `json:"expiry"`
}

SavedQuote stores a quote locally

type TokenPayload

type TokenPayload struct {
	GrantType         string `json:"grant_type"`
	ClientID          string `json:"client_id"`
	ClientSecret      string `json:"client_secret"`
	ExtraClientSecret string `json:"extra_client_secret"`
}

TokenPayload holds the data needed to get a new token

func TokenPayloadFromCtx

func TokenPayloadFromCtx(ctx context.Context) TokenPayload

TokenPayloadFromCtx - given some context, create our bf token payload

type TokenResponse

type TokenResponse struct {
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
	ExpiresIn    int    `json:"expires_in"`
	Scope        string `json:"scope"`
	AccountHash  string `json:"account_hash"`
	TokenType    string `json:"token_type"`
}

TokenResponse holds the response from refreshing a token

type WithdrawToDepositIDBulkPayload

type WithdrawToDepositIDBulkPayload struct {
	DryRun       bool                         `json:"dry_run"`
	Withdrawals  []WithdrawToDepositIDPayload `json:"withdrawals"`
	PriceToken   string                       `json:"price_token"`
	DryRunOption *DryRunOption                `json:"dry_run_option,omitempty"`
}

WithdrawToDepositIDBulkPayload holds all WithdrawToDepositIDPayload(s) for a single bulk request

func NewWithdrawToDepositIDBulkPayload

func NewWithdrawToDepositIDBulkPayload(dryRunOptions *DryRunOption, priceToken string, withdrawals *[]WithdrawToDepositIDPayload) *WithdrawToDepositIDBulkPayload

NewWithdrawToDepositIDBulkPayload creates a bulk request

func (WithdrawToDepositIDBulkPayload) ToBulkStatus

ToBulkStatus converts an upload to a checks status payload

type WithdrawToDepositIDBulkResponse

type WithdrawToDepositIDBulkResponse struct {
	DryRun      bool                          `json:"dry_run"`
	Withdrawals []WithdrawToDepositIDResponse `json:"withdrawals"`
}

WithdrawToDepositIDBulkResponse holds info about the status of the bulk settlements

type WithdrawToDepositIDPayload

type WithdrawToDepositIDPayload struct {
	CurrencyCode string  `json:"currency_code"`
	Amount       float64 `json:"amount"`
	DryRun       *bool   `json:"dry_run,omitempty"`
	DepositID    string  `json:"deposit_id"`
	TransferID   string  `json:"transfer_id"`
	SourceFrom   string  `json:"source_from"`
}

WithdrawToDepositIDPayload holds a single withdrawal request

type WithdrawToDepositIDResponse

type WithdrawToDepositIDResponse struct {
	CurrencyCode string          `json:"currency_code"`
	Amount       decimal.Decimal `json:"amount"`
	Message      string          `json:"message"`
	Status       string          `json:"transfer_status"`
	TransferID   string          `json:"transfer_id"`
}

WithdrawToDepositIDResponse holds a single withdrawal request

func (WithdrawToDepositIDResponse) CategorizeStatus

func (withdrawResponse WithdrawToDepositIDResponse) CategorizeStatus() string

CategorizeStatus checks the status of a withdrawal response and categorizes it

Directories

Path Synopsis
Package mock_bitflyer is a generated GoMock package.
Package mock_bitflyer is a generated GoMock package.

Jump to

Keyboard shortcuts

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