go_currencycom

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2023 License: MIT Imports: 15 Imported by: 0

README

go-currencycom

A Go client library for the Currency.com API.

GoDoc Currency.com Swagger API Go Report Card

Installation
go get github.com/radovsky1/go-currencycom
Contribution

This project is fully inspired by go-binance. All other materials are taken from the official Currency.com API documentation.

Importing
import (
    currencycom "github.com/radovsky1/go-currencycom"
)
REST API
Setup

Init client for API services. Get APIKey/SecretKey from your account.

var (
    apiKey = "your api key"
    secretKey = "your secret key"
)
currencycom.UseDemo = true // use demo server
client := currencycom.NewClient(apiKey, secretKey)

A service instance stands for a REST API endpoint and is initialized by client.NewXXXService function.

Simply call API in chain style. Call Do() in the end to send HTTP request and get response.

Create Order
order, err := client.NewCreateOrderService().
        Symbol("BTC/USD_LEVERAGE").
        Side(go_currencycom.SideTypeBuy).
        Type(go_currencycom.OrderTypeLimit).
        Quantity(0.03).
        Price(15000).
        Do(context.Background())
if err != nil {
    panic(err)
}
println(order.OrderID)
Fetch Order
order, err := client.NewGetOrderService().
        Symbol("BTC/USD_LEVERAGE").
        OrderID("123456789").
        Do(context.Background())
if err != nil {
    panic(err)
}
println(order.OrderID)
Cancel Order
order, err := client.NewCancelOrderService().
        Symbol("BTC/USD_LEVERAGE").
        OrderID("123456789").
        Do(context.Background())
if err != nil {
    panic(err)
}
println(order.OrderID)
List Open Orders
openOrders, err := client.NewListOpenOrdersService().Do(context.Background())
if err != nil {
    fmt.Println(err)
    return
}
fmt.Println(openOrders)
List Trading Positions
positions, err := client.NewListTradingPositionsService().Do(context.Background())
if err != nil {
    fmt.Println(err)
    return
}
fmt.Println(positions)
Get Account Information
account, err := client.NewGetAccountService().Do(context.Background())
if err != nil {
    fmt.Println(err)
    return
}
fmt.Println(account)

There are more services available, please check the source code.

Websocket API

You don't need Client in websocket API. Just call currencycom.WsXxxServe(args, handler, errHandler).

Market Data
wsMarketDataHandler := func(event *currencycom.WsMarketDataEvent) {
    fmt.Println(event)
}
errHandler := func(err error) {
    fmt.Println(err)
}
doneC, stopC, err := currencycom.WsMarketDataServe("BTC/USD_LEVERAGE", wsMarketDataHandler, errHandler)
if err != nil {
    fmt.Println(err)
    return
}
// use stopC to exit
go func() {
    time.Sleep(5 * time.Second)
    stopC <- struct{}{}
}()
// remove this if you do not want to be blocked here
<-doneC
OHLC Market Data
wsOHLCMarketDataHandler := func(event *currencycom.WsOHLCMarketDataEvent) {
    fmt.Println(event)
}
errHandler := func(err error) {
    fmt.Println(err)
}
doneC, stopC, err := currencycom.WsOHLCMarketDataServe("BTC/USD_LEVERAGE", wsOHLCMarketDataHandler, errHandler)
if err != nil {
    fmt.Println(err)
    return
}
// use stopC to exit
go func() {
    time.Sleep(5 * time.Second)
    stopC <- struct{}{}
}()
// remove this if you do not want to be blocked here
<-doneC
Trades
wsTradesHandler := func(event *currencycom.WsTradesEvent) {
    fmt.Println(event)
}
errHandler := func(err error) {
    fmt.Println(err)
}
doneC, stopC, err := currencycom.WsTradesServe("BTC/USD_LEVERAGE", wsTradesHandler, errHandler)
if err != nil {
    fmt.Println(err)
    return
}
// use stopC to exit
go func() {
    time.Sleep(5 * time.Second)
    stopC <- struct{}{}
}()
// remove this if you do not want to be blocked here
<-doneC
Feedback

If you have any questions/suggestions, please feel free to contact me.

Documentation

Index

Constants

View Source
const (
	// BaseURL is the base url of currency.com api
	BaseURL = "https://api-adapter.backend.currency.com/"
	// BaseDemoURL is the base url of currency.com demo api
	BaseDemoURL = "https://demo-api-adapter.backend.currency.com/"
)
View Source
const (
	SideTypeBuy  SideType = "BUY"
	SideTypeSell SideType = "SELL"

	OrderTypeLimit  OrderType = "LIMIT"
	OrderTypeMarket OrderType = "MARKET"
	OrderTypeStop   OrderType = "STOP"

	OrderStatusTypeNew             OrderStatusType = "NEW"
	OrderStatusTypePartiallyFilled OrderStatusType = "PARTIALLY_FILLED"
	OrderStatusTypeFilled          OrderStatusType = "FILLED"
	OrderStatusTypeCanceled        OrderStatusType = "CANCELED"
	OrderStatusTypeRejected        OrderStatusType = "REJECTED"
	OrderStatusTypeExpired         OrderStatusType = "EXPIRED"
	OrderStatusTypePendingCancel   OrderStatusType = "PENDING_CANCEL"

	TimeInForceTypeGTC TimeInForceType = "GTC"
	TimeInForceTypeIOC TimeInForceType = "IOC"
	TimeInForceTypeFOK TimeInForceType = "FOK"

	NewOrderRespTypeACK    NewOrderRespType = "ACK"
	NewOrderRespTypeRESULT NewOrderRespType = "RESULT"
	NewOrderRespTypeFULL   NewOrderRespType = "FULL"

	ExpireTimestampTypeGTC ExpireTimestampType = "GTC"
	ExpireTimestampTypeFOK ExpireTimestampType = "FOK"

	CandlestickInterval1m  CandlestickInterval = "1m"
	CandlestickInterval5m  CandlestickInterval = "5m"
	CandlestickInterval15m CandlestickInterval = "15m"
	CandlestickInterval30m CandlestickInterval = "30m"
	CandlestickInterval1h  CandlestickInterval = "1h"
	CandlestickInterval4h  CandlestickInterval = "4h"
	CandlestickInterval1d  CandlestickInterval = "1d"
	CandlestickInterval1w  CandlestickInterval = "1w"
)

Global enums

Variables

View Source
var (
	WebsocketTimeout   = 30 * time.Second
	WebsocketKeepAlive = true
	CorrelationID      = -1
)
View Source
var UseDemo = true

UseDemo is the flag to use demo api

Functions

func FormatTimestamp

func FormatTimestamp(t time.Time) int64

func IsAPIError

func IsAPIError(e error) bool

IsAPIError check if e is an API error

func WsMarketDataServe

func WsMarketDataServe(symbols []string, handler WsMarketDataHandler, errHandler ErrHandler) (doneC, stopC chan struct{}, err error)

func WsOHLCMarketDataServe

func WsOHLCMarketDataServe(symbols []string, intervals []string, handler WsOHLCMarketDataHandler, errHandler ErrHandler) (doneC, stopC chan struct{}, err error)

func WsTradesServe

func WsTradesServe(symbols []string, handler WsTradesHandler, errHandler ErrHandler) (doneC, stopC chan struct{}, err error)

Types

type APIError

type APIError struct {
	Code    int64  `json:"code"`
	Message string `json:"msg"`
}

APIError define API error when response status is 4xx or 5xx

func (APIError) Error

func (e APIError) Error() string

Error return error code and message

type Account

type Account struct {
	AffiliateID      string    `json:"affiliateId"`
	Balances         []Balance `json:"balances"`
	BuyerCommission  float32   `json:"buyerCommission"`
	CanDeposit       bool      `json:"canDeposit"`
	CanTrade         bool      `json:"canTrade"`
	CanWithdraw      bool      `json:"canWithdraw"`
	MakerCommission  float32   `json:"makerCommission"`
	SellerCommission float32   `json:"sellerCommission"`
	TakerCommission  float32   `json:"takerCommission"`
	UpdateTime       int64     `json:"updateTime"`
	UserID           int64     `json:"userId"`
}

type Ask

type Ask = PriceLevel

Ask is a type alias for PriceLevel.

type Balance

type Balance struct {
	AccountID          string  `json:"accountId"`
	CollateralCurrency bool    `json:"collateralCurrency"`
	Asset              string  `json:"asset"`
	Free               float64 `json:"free"`
	Locked             float64 `json:"locked"`
	Default            bool    `json:"default"`
}

type Bid

type Bid = PriceLevel

Bid is a type alias for PriceLevel.

type CancelOrderResponse

type CancelOrderResponse struct {
	ExecutedQty string          `json:"executedQty"`
	OrderID     string          `json:"orderId"`
	OrigQty     string          `json:"origQty"`
	Price       string          `json:"price"`
	Side        SideType        `json:"side"`
	Status      OrderStatusType `json:"status"`
	Symbol      string          `json:"symbol"`
	TimeInForce TimeInForceType `json:"timeInForce"`
	Type        OrderType       `json:"type"`
}

type CancelOrderService

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

func (*CancelOrderService) Do

func (s *CancelOrderService) Do(ctx context.Context, opts ...RequestOption) (res *CancelOrderResponse, err error)

Do send request

func (*CancelOrderService) OrderID

func (s *CancelOrderService) OrderID(orderID string) *CancelOrderService

OrderID set order id

func (*CancelOrderService) Symbol

func (s *CancelOrderService) Symbol(symbol string) *CancelOrderService

Symbol set symbol

type CandlestickInterval

type CandlestickInterval string

CandlestickInterval define interval of candlestick

type Client

type Client struct {
	APIKey     string
	SecretKey  string
	BaseURL    string
	UserAgent  string
	HTTPClient *http.Client
	Debug      bool
	Logger     *log.Logger
	TimeOffset int64
	// contains filtered or unexported fields
}

func NewClient

func NewClient(apiKey, secretKey string) *Client

func (*Client) NewCancelOrderService

func (c *Client) NewCancelOrderService() *CancelOrderService

func (*Client) NewCloseTradingPositionService

func (c *Client) NewCloseTradingPositionService() *CloseTradingPositionService

func (*Client) NewCreateOrderService

func (c *Client) NewCreateOrderService() *CreateOrderService

func (*Client) NewDepthService

func (c *Client) NewDepthService() *DepthService

func (*Client) NewEditExchangeOrderService

func (c *Client) NewEditExchangeOrderService() *EditExchangeOrderService

func (*Client) NewExchangeInfoService

func (c *Client) NewExchangeInfoService() *ExchangeInfoService

func (*Client) NewFetchOrderService

func (c *Client) NewFetchOrderService() *FetchOrderService

func (*Client) NewGetAccountService

func (c *Client) NewGetAccountService() *GetAccountService

func (*Client) NewKlinesService

func (c *Client) NewKlinesService() *KlinesService

func (*Client) NewListHistoricalPositionsService

func (c *Client) NewListHistoricalPositionsService() *ListHistoricalPositionsService

func (*Client) NewListOpenOrdersService

func (c *Client) NewListOpenOrdersService() *ListOpenOrdersService

func (*Client) NewListTradingPositionsService

func (c *Client) NewListTradingPositionsService() *ListTradingPositionsService

func (*Client) SetAPIEndpoint

func (c *Client) SetAPIEndpoint(endpoint string) *Client

type CloseTradingPositionResponse

type CloseTradingPositionResponse struct {
	Request []RequestDto `json:"request"`
}

type CloseTradingPositionService

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

func (*CloseTradingPositionService) Do

Do send request

func (*CloseTradingPositionService) PositionID

type CreateOrderResponse

type CreateOrderResponse struct {
	ExecutedQty        string          `json:"executedQty"`
	ExpireTimestamp    int64           `json:"expireTimestamp"`
	GuaranteedStopLoss bool            `json:"guaranteedStopLoss"`
	Margin             float64         `json:"margin"`
	OrderID            string          `json:"orderId"`
	OrigQty            string          `json:"origQty"`
	Price              string          `json:"price"`
	ProfitDistance     float64         `json:"profitDistance"`
	RejectMessage      string          `json:"rejectMessage"`
	Side               SideType        `json:"side"`
	Status             OrderStatusType `json:"status"`
	StopDistance       float64         `json:"stopDistance"`
	StopLoss           float64         `json:"stopLoss"`
	Symbol             string          `json:"symbol"`
	TakeProfit         float64         `json:"takeProfit"`
	TimeInForce        TimeInForceType `json:"timeInForce"`
	TrailingStopLoss   bool            `json:"trailingStopLoss"`
	TransactTime       int64           `json:"transactTime"`
	Type               OrderType       `json:"type"`
}

type CreateOrderService

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

func (*CreateOrderService) AccountID

func (s *CreateOrderService) AccountID(accountID int64) *CreateOrderService

AccountID set account id

func (*CreateOrderService) Do

func (s *CreateOrderService) Do(ctx context.Context, opts ...RequestOption) (res *CreateOrderResponse, err error)

Do send request

func (*CreateOrderService) ExpireTimestamp

func (s *CreateOrderService) ExpireTimestamp(expireTimestamp int64) *CreateOrderService

ExpireTimestamp set expire timestamp

func (*CreateOrderService) GuaranteedStopLoss

func (s *CreateOrderService) GuaranteedStopLoss(guaranteedStopLoss bool) *CreateOrderService

GuaranteedStopLoss set guaranteed stop loss

func (*CreateOrderService) Leverage

func (s *CreateOrderService) Leverage(leverage int32) *CreateOrderService

Leverage set leverage

func (*CreateOrderService) NewOrderRespType

func (s *CreateOrderService) NewOrderRespType(newOrderRespType NewOrderRespType) *CreateOrderService

NewOrderRespType set new order response type

func (*CreateOrderService) Price

Price set price

func (*CreateOrderService) ProfitDistance

func (s *CreateOrderService) ProfitDistance(profitDistance float64) *CreateOrderService

ProfitDistance set profit distance

func (*CreateOrderService) Quantity

func (s *CreateOrderService) Quantity(quantity float64) *CreateOrderService

Quantity set quantity

func (*CreateOrderService) Side

Side set side

func (*CreateOrderService) StopDistance

func (s *CreateOrderService) StopDistance(stopDistance float64) *CreateOrderService

StopDistance set stop distance

func (*CreateOrderService) StopLoss

func (s *CreateOrderService) StopLoss(stopLoss float64) *CreateOrderService

StopLoss set stop loss

func (*CreateOrderService) Symbol

func (s *CreateOrderService) Symbol(symbol string) *CreateOrderService

Symbol set symbol

func (*CreateOrderService) TakeProfit

func (s *CreateOrderService) TakeProfit(takeProfit float64) *CreateOrderService

TakeProfit set take profit

func (*CreateOrderService) TrailingStopLoss

func (s *CreateOrderService) TrailingStopLoss(trailingStopLoss bool) *CreateOrderService

TrailingStopLoss set trailing stop loss

func (*CreateOrderService) Type

func (s *CreateOrderService) Type(orderType OrderType) *CreateOrderService

Type set order type

type DepthResponse

type DepthResponse struct {
	LastUpdateID int64 `json:"lastUpdateId"`
	Bids         []Bid `json:"bids"`
	Asks         []Ask `json:"asks"`
}

DepthResponse define depth info with bids and asks

type DepthService

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

func (*DepthService) Do

func (s *DepthService) Do(ctx context.Context, opts ...RequestOption) (res *DepthResponse, err error)

Do send request

func (*DepthService) Limit

func (s *DepthService) Limit(limit int) *DepthService

Limit set limit

func (*DepthService) Symbol

func (s *DepthService) Symbol(symbol string) *DepthService

Symbol set symbol

type EditExchangeOrderResponse

type EditExchangeOrderResponse struct {
	OrderID string `json:"orderId"`
}

type EditExchangeOrderService

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

func (*EditExchangeOrderService) Do

Do send request

func (*EditExchangeOrderService) ExpireTimestamp

func (s *EditExchangeOrderService) ExpireTimestamp(expireTimestamp ExpireTimestampType) *EditExchangeOrderService

ExpireTimestamp set expire timestamp

func (*EditExchangeOrderService) OrderID

OrderID set order id

func (*EditExchangeOrderService) Price

Price set price

type ErrHandler

type ErrHandler func(err error)

type ExchangeFilter

type ExchangeFilter struct {
	FilterType string `json:"filterType"`
	MinPrice   string `json:"minPrice"`
	MaxPrice   string `json:"maxPrice"`
}

type ExchangeInfo

type ExchangeInfo struct {
	ExchangeFilters []ExchangeFilter     `json:"exchangeFilters"`
	RateLimits      []RateLimit          `json:"rateLimits"`
	ServerTime      int64                `json:"serverTime"`
	Symbols         []ExchangeSymbolInfo `json:"symbols"`
	Timezone        string               `json:"timezone"`
}

type ExchangeInfoService

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

func (*ExchangeInfoService) Do

func (s *ExchangeInfoService) Do(ctx context.Context, opts ...RequestOption) (res *ExchangeInfo, err error)

type ExchangeSymbolFilter

type ExchangeSymbolFilter struct {
	FilterType  string `json:"filterType"`
	TickSize    string `json:"tickSize"`
	MinQty      string `json:"minQty"`
	MaxQty      string `json:"maxQty"`
	MinNotional string `json:"minNotional"`
	StepSize    string `json:"stepSize"`
}

type ExchangeSymbolInfo

type ExchangeSymbolInfo struct {
	AssetType          string                 `json:"assetType"`
	BaseAsset          string                 `json:"baseAsset"`
	BaseAssetPrecision int                    `json:"baseAssetPrecision"`
	Country            string                 `json:"country"`
	ExchangeFee        float64                `json:"exchangeFee"`
	Filters            []ExchangeSymbolFilter `json:"filters"`
	Industry           string                 `json:"industry"`
	LongRate           float64                `json:"longRate"`
	MakerFee           float64                `json:"makerFee"`
	MarketModes        []string               `json:"marketModes"`
	MarketType         string                 `json:"marketType"`
	MaxSLGap           float64                `json:"maxSLGap"`
	MaxTPGap           float64                `json:"maxTPGap"`
	MinSLGap           float64                `json:"minSLGap"`
	MinTPGap           float64                `json:"minTPGap"`
	Name               string                 `json:"name"`
	OrderTypes         []OrderType            `json:"orderTypes"`
	QuoteAsset         string                 `json:"quoteAsset"`
	QuoteAssetID       string                 `json:"quoteAssetId"`
	QuotePrecision     int                    `json:"quotePrecision"`
	Sector             string                 `json:"sector"`
	ShortRate          float64                `json:"shortRate"`
	Status             string                 `json:"status"`
	SwapChargeInterval int64                  `json:"swapChargeInterval"`
	Symbol             string                 `json:"symbol"`
	TakerFee           float64                `json:"takerFee"`
	TickSize           float64                `json:"tickSize"`
	TickValue          float64                `json:"tickValue"`
	TradingFee         float64                `json:"tradingFee"`
	TradingHours       string                 `json:"tradingHours"`
}

type ExpireTimestampType

type ExpireTimestampType string

ExpireTimestampType define expire time of order

type FeeDetailsDto

type FeeDetailsDto struct {
	Commission float64 `json:"commission"`
}

type FetchOrderResponse

type FetchOrderResponse struct {
	AccountID          string          `json:"accountId"`
	ExecPrice          float64         `json:"execPrice"`
	ExecQuantity       float64         `json:"execQuantity"`
	ExpireTime         int64           `json:"expireTime"`
	GuaranteedStopLoss bool            `json:"guaranteedStopLoss"`
	Margin             float64         `json:"margin"`
	OrderID            string          `json:"orderId"`
	Price              float64         `json:"price"`
	Quantity           float64         `json:"quantity"`
	RejectReason       string          `json:"rejectReason"`
	Side               SideType        `json:"side"`
	Status             OrderStatusType `json:"status"`
	StopLoss           float64         `json:"stopLoss"`
	TakeProfit         float64         `json:"takeProfit"`
	TimeInForceType    TimeInForceType `json:"timeInForceType"`
	Timestamp          int64           `json:"timestamp"`
	TrailingStopLoss   bool            `json:"trailingStopLoss"`
	Type               OrderType       `json:"type"`
}

type FetchOrderService

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

func (*FetchOrderService) Do

func (s *FetchOrderService) Do(ctx context.Context, opts ...RequestOption) (res *FetchOrderResponse, err error)

Do send request

func (*FetchOrderService) OrderID

func (s *FetchOrderService) OrderID(orderID string) *FetchOrderService

OrderID set order id

func (*FetchOrderService) Symbol

func (s *FetchOrderService) Symbol(symbol string) *FetchOrderService

Symbol set symbol

type GetAccountService

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

func (*GetAccountService) Do

func (s *GetAccountService) Do(ctx context.Context, opts ...RequestOption) (res *Account, err error)

Do send request

type HistoricalPositionDto

type HistoricalPositionDto struct {
	AccountCurrency  string        `json:"accountCurrency"`
	AccountID        int64         `json:"accountId"`
	CreatedTimestamp int64         `json:"createdTimestamp"`
	Currency         string        `json:"currency"`
	ExecID           string        `json:"execId"`
	ExecTimestamp    int64         `json:"execTimestamp"`
	ExecutionTyp     string        `json:"executionType"`
	Fee              float64       `json:"fee"`
	FeeDetails       FeeDetailsDto `json:"feeDetails"`
	FxRate           float64       `json:"fxRate"`
	GSL              bool          `json:"gSL"`
	InstrumentID     int64         `json:"instrumentId"`
	PositionID       string        `json:"positionId"`
	Price            float64       `json:"price"`
	Quantity         float64       `json:"quantity"`
	RejectReason     string        `json:"rejectReason"`
	Rpl              float64       `json:"rpl"`
	RplConverted     float64       `json:"rplConverted"`
	Source           string        `json:"source"`
	Status           string        `json:"status"`
	StopLoss         float64       `json:"stopLoss"`
	Swap             float64       `json:"swap"`
	SwapConverted    float64       `json:"swapConverted"`
	Symbol           string        `json:"symbol"`
	TakeProfit       float64       `json:"takeProfit"`
	TrailingStopLoss bool          `json:"trailingStopLoss"`
}

type Kline

type Kline struct {
	OpenTime int64  `json:"openTime"`
	Open     string `json:"open"`
	High     string `json:"high"`
	Low      string `json:"low"`
	Close    string `json:"close"`
	Volume   string `json:"volume"`
}

Kline define kline info

type KlinesService

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

func (*KlinesService) Do

func (s *KlinesService) Do(ctx context.Context, opts ...RequestOption) (res []*Kline, err error)

func (*KlinesService) EndTime

func (s *KlinesService) EndTime(endTime int64) *KlinesService

func (*KlinesService) Interval

func (s *KlinesService) Interval(interval string) *KlinesService

func (*KlinesService) Limit

func (s *KlinesService) Limit(limit int) *KlinesService

func (*KlinesService) PriceType

func (s *KlinesService) PriceType(priceType string) *KlinesService

func (*KlinesService) StartTime

func (s *KlinesService) StartTime(startTime int64) *KlinesService

func (*KlinesService) Symbol

func (s *KlinesService) Symbol(symbol string) *KlinesService

func (*KlinesService) Type

func (s *KlinesService) Type(ktype string) *KlinesService

type ListHistoricalPositionsResponse

type ListHistoricalPositionsResponse struct {
	History []HistoricalPositionDto `json:"history"`
}

type ListHistoricalPositionsService

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

func (*ListHistoricalPositionsService) Do

Do send request

func (*ListHistoricalPositionsService) From

func (*ListHistoricalPositionsService) Limit

func (*ListHistoricalPositionsService) Symbol

func (*ListHistoricalPositionsService) To

type ListOpenOrdersService

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

func (*ListOpenOrdersService) Do

func (s *ListOpenOrdersService) Do(ctx context.Context, opts ...RequestOption) (res []*QueryOrderResponse, err error)

Do send request

type ListTradingPositionsResponse

type ListTradingPositionsResponse struct {
	Positions []TradingPositionDto `json:"positions"`
}

type ListTradingPositionsService

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

func (*ListTradingPositionsService) Do

Do send request

type NewOrderRespType

type NewOrderRespType string

NewOrderRespType define response JSON verbosity

type OrderStatusType

type OrderStatusType string

OrderStatusType define order status

type OrderType

type OrderType string

OrderType define order type

type PositionSideType

type PositionSideType string

PositionSideType define position side type of order

type PriceLevel

type PriceLevel struct {
	Price    float64
	Quantity float64
}

type PriceLevelList

type PriceLevelList []PriceLevel

func (PriceLevelList) Len

func (p PriceLevelList) Len() int

func (PriceLevelList) Less

func (p PriceLevelList) Less(i, j int) bool

func (PriceLevelList) Swap

func (p PriceLevelList) Swap(i, j int)

type QueryOrderResponse

type QueryOrderResponse struct {
	AccountID          string          `json:"accountId"`
	ExecutedQty        string          `json:"executedQty"`
	ExpireTimestamp    int64           `json:"expireTimestamp"`
	GuaranteedStopLoss bool            `json:"guaranteedStopLoss"`
	IcebergQty         string          `json:"icebergQty"`
	Leverage           bool            `json:"leverage"`
	Margin             float64         `json:"margin"`
	OrderID            string          `json:"orderId"`
	OrigQty            string          `json:"origQty"`
	Price              string          `json:"price"`
	Side               SideType        `json:"side"`
	Status             OrderStatusType `json:"status"`
	StopLoss           float64         `json:"stopLoss"`
	Symbol             string          `json:"symbol"`
	TakeProfit         float64         `json:"takeProfit"`
	Time               int64           `json:"time"`
	TimeInForce        TimeInForceType `json:"timeInForce"`
	TrailingStopLoss   bool            `json:"trailingStopLoss"`
	Type               OrderType       `json:"type"`
	UpdateTime         int64           `json:"updateTime"`
	Working            bool            `json:"working"`
}

type RateLimit

type RateLimit struct {
	Interval      string `json:"interval"`
	IntervalNum   int    `json:"intervalNum"`
	Limit         int    `json:"limit"`
	RateLimitType string `json:"rateLimitType"`
}

type RequestDto

type RequestDto struct {
	AccountID        string `json:"accountId"`
	CreatedTimestamp int64  `json:"createdTimestamp"`
	ID               int64  `json:"id"`
	OrderID          string `json:"orderId"`
	PositionID       string `json:"positionId"`
	RejectReason     string `json:"rejectReason"`
	RqType           string `json:"rqType"`
	State            string `json:"state"`
}

type RequestOption

type RequestOption func(*request)

RequestOption define option type for request

type SideType

type SideType string

SideType define side type of order

type TimeInForceType

type TimeInForceType string

TimeInForceType define time in force type of order

type TradingPositionDto

type TradingPositionDto struct {
	AccountID                           string  `json:"accountId"`
	ClosePrice                          float64 `json:"closePrice"`
	CloseQuantity                       float64 `json:"closeQuantity"`
	CloseTimestamp                      int64   `json:"closeTimestamp"`
	Cost                                float64 `json:"cost"`
	CreatedTimestamp                    int64   `json:"createdTimestamp"`
	Currency                            string  `json:"currency"`
	CurrentTrailingPrice                float64 `json:"currentTrailingPrice"`
	CurrenTrailingPriceUpdatedTimestamp int64   `json:"currenTrailingPriceUpdatedTimestamp"`
	Dividend                            float64 `json:"dividend"`
	Fee                                 float64 `json:"fee"`
	GuaranteedStopLoss                  bool    `json:"guaranteedStopLoss"`
	ID                                  string  `json:"id"`
	InstrumentID                        int64   `json:"instrumentId"`
	Margin                              float64 `json:"margin"`
	OpenPrice                           float64 `json:"openPrice"`
	OpenQuantity                        float64 `json:"openQuantity"`
	OpenTimestamp                       int64   `json:"openTimestamp"`
	OrderID                             string  `json:"orderId"`
	Rpl                                 float64 `json:"rpl"`
	RplConverted                        float64 `json:"rplConverted"`
	State                               string  `json:"state"`
	StopLoss                            float64 `json:"stopLoss"`
	Swap                                float64 `json:"swap"`
	SwapConverted                       float64 `json:"swapConverted"`
	Symbol                              string  `json:"symbol"`
	TakeProfit                          float64 `json:"takeProfit"`
	TrailingQuotedPrice                 float64 `json:"trailingQuotedPrice"`
	TrailingStopLoss                    bool    `json:"trailingStopLoss"`
	Type                                string  `json:"type"`
	Upl                                 float64 `json:"upl"`
	UplConverted                        float64 `json:"uplConverted"`
}

type UpdateTradingOrderResponse

type UpdateTradingOrderResponse struct {
	RequestID int64  `json:"requestId"`
	State     string `json:"state"`
}

type UpdateTradingOrderService

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

func (*UpdateTradingOrderService) Do

Do send request

func (*UpdateTradingOrderService) GuaranteedStopLoss

func (s *UpdateTradingOrderService) GuaranteedStopLoss(guaranteedStopLoss bool) *UpdateTradingOrderService

GuaranteedStopLoss set guaranteed stop loss

func (*UpdateTradingOrderService) NewPrice

NewPrice set new price

func (*UpdateTradingOrderService) OrderID

OrderID set order id

func (*UpdateTradingOrderService) ProfitDistance

func (s *UpdateTradingOrderService) ProfitDistance(profitDistance float64) *UpdateTradingOrderService

ProfitDistance set profit distance

func (*UpdateTradingOrderService) StopDistance

func (s *UpdateTradingOrderService) StopDistance(stopDistance float64) *UpdateTradingOrderService

StopDistance set stop distance

func (*UpdateTradingOrderService) StopLoss

StopLoss set stop loss

func (*UpdateTradingOrderService) TakeProfit

func (s *UpdateTradingOrderService) TakeProfit(takeProfit float64) *UpdateTradingOrderService

TakeProfit set take profit

func (*UpdateTradingOrderService) TrailingStopLoss

func (s *UpdateTradingOrderService) TrailingStopLoss(trailingStopLoss bool) *UpdateTradingOrderService

TrailingStopLoss set trailing stop loss

type UpdateTradingPositionResponse

type UpdateTradingPositionResponse struct {
	RequestID int64  `json:"requestId"`
	State     string `json:"state"`
}

type UpdateTradingPositionService

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

func (*UpdateTradingPositionService) Do

Do send request

func (*UpdateTradingPositionService) GuaranteedStopLoss

func (s *UpdateTradingPositionService) GuaranteedStopLoss(guaranteedStopLoss bool) *UpdateTradingPositionService

func (*UpdateTradingPositionService) PositionID

func (*UpdateTradingPositionService) ProfitDistance

func (s *UpdateTradingPositionService) ProfitDistance(profitDistance float64) *UpdateTradingPositionService

func (*UpdateTradingPositionService) StopDistance

func (s *UpdateTradingPositionService) StopDistance(stopDistance float64) *UpdateTradingPositionService

func (*UpdateTradingPositionService) StopLoss

func (*UpdateTradingPositionService) TakeProfit

func (*UpdateTradingPositionService) TrailingStopLoss

func (s *UpdateTradingPositionService) TrailingStopLoss(trailingStopLoss bool) *UpdateTradingPositionService

type WsConfig

type WsConfig struct {
	Endpoint string
}

type WsHandler

type WsHandler func(message []byte)

type WsMarketDataEvent

type WsMarketDataEvent struct {
	SymbolName string  `json:"symbolName"`
	Bid        float64 `json:"bid"`
	Ofr        float64 `json:"ofr"`
	BidQty     float64 `json:"bidQty"`
	OfrQty     float64 `json:"ofrQty"`
	Timestamp  int64   `json:"timestamp"`
}

type WsMarketDataHandler

type WsMarketDataHandler func(event *WsMarketDataEvent)

type WsOHLCMarketDataEvent

type WsOHLCMarketDataEvent struct {
	Symbol    string  `json:"symbol"`
	Interval  string  `json:"interval"`
	Type      string  `json:"type"`
	Open      float64 `json:"o"`
	High      float64 `json:"h"`
	Low       float64 `json:"l"`
	Close     float64 `json:"c"`
	Timestamp int64   `json:"t"`
}

type WsOHLCMarketDataHandler

type WsOHLCMarketDataHandler func(event *WsOHLCMarketDataEvent)

type WsRequest

type WsRequest struct {
	Destination   string  `json:"destination"`
	CorrelationID int     `json:"correlationId"`
	Payload       payload `json:"payload"`
}

type WsTradesEvent

type WsTradesEvent struct {
	Price         float64 `json:"price"`
	Size          float64 `json:"size"`
	ID            int64   `json:"id"`
	Timestamp     int64   `json:"ts"`
	Symbol        string  `json:"symbol"`
	OrderID       string  `json:"orderId"`
	ClientOrderID string  `json:"clientOrderId"`
	Buyer         bool    `json:"buyer"`
}

type WsTradesHandler

type WsTradesHandler func(event *WsTradesEvent)

Jump to

Keyboard shortcuts

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