clients

package
v0.0.0-...-0205a2a Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComputeHmac256

func ComputeHmac256(message string, key []byte) string

func GenerateSig

func GenerateSig(message, secret string) (string, error)

Types

type Balance

type Balance struct {
	Token    string  `json:"token"`
	Balance  float64 `json:"balance"`
	Platform string  `json:"platform"`
}

type Error

type Error struct {
	Code   int    `json:"code"`
	Reason string `json:"reason"`
}

func (Error) Error

func (e Error) Error() string

type FalconXError

type FalconXError struct {
	Code   string `json:"code"`
	Reason string `json:"reason"`
}

type FalconXWarning

type FalconXWarning struct {
	Code    string `json:"code"`
	Message string `json:"message"`
	Side    string `json:"side"`
}

type OrderRequest

type OrderRequest struct {
	TokenPair     TokenPair `json:"token_pair"`
	Quantity      Quantity  `json:"quantity"`
	Side          string    `json:"side"`
	OrderType     string    `json:"order_type"`
	TimeInForce   string    `json:"time_in_force"`
	LimitPrice    float64   `json:"limit_price"`
	SlippageBps   float64   `json:"slippage_bps"`
	ClientOrderId string    `json:"client_order_id"`
}

type OrderResponse

type OrderResponse struct {
	Status        string           `json:"status"`
	FxQuoteId     string           `json:"fx_quote_id"`
	BuyPrice      float64          `json:"buy_price,string"`
	SellPrice     float64          `json:"sell_price,string"`
	Platform      string           `json:"platform"`
	TokenPair     TokenPair        `json:"token_pair"`
	Quantity      Quantity         `json:"quantity_requested"`
	SideRequested string           `json:"side_requested"`
	QuoteTime     time.Time        `json:"t_quote"`
	ExpiryTime    time.Time        `json:"t_expiry"`
	ExecutionTime time.Time        `json:"t_execute"`
	IsFilled      bool             `json:"is_filled"`
	GrossFeeBps   float64          `json:"gross_fee_bps,string"`
	GrossFeeUSD   float64          `json:"gross_fee_usd,string"`
	RebateBps     float64          `json:"rebate_bps,string"`
	RebateUSD     float64          `json:"rebate_usd,string"`
	FeeBps        float64          `json:"fee_bps,string"`
	FeeUSD        float64          `json:"fee_usd,string"`
	SideExecuted  string           `json:"side_executed"`
	TraderEmail   string           `json:"trader_email"`
	OrderType     string           `json:"order_type"`
	TimeInForce   string           `json:"time_in_force"`
	LimitPrice    float64          `json:"limit_price,string"`
	SlippageBps   float64          `json:"slippage_bps,string"`
	Error         FalconXError     `json:"error"`
	Warnings      []FalconXWarning `json:"warnings"`
	ClientOrderId string           `json:"client_order_id"`
}

type Quantity

type Quantity struct {
	Token string  `json:"token"`
	Value float64 `json:"value,string"`
}

type QuoteExecutionRequest

type QuoteExecutionRequest struct {
	FxQuoteId string `json:"fx_quote_id"`
	Side      string `json:"side"`
}

type QuoteRequest

type QuoteRequest struct {
	TokenPair     TokenPair `json:"token_pair"`
	Quantity      Quantity  `json:"quantity"`
	Side          string    `json:"side"`
	ClientOrderId string    `json:"client_order_id"`
}

type QuoteResponse

type QuoteResponse struct {
	Status        string           `json:"status"`
	FxQuoteId     string           `json:"fx_quote_id"`
	BuyPrice      float64          `json:"buy_price,string"`
	SellPrice     float64          `json:"sell_price,string"`
	Platform      string           `json:"platform"`
	TokenPair     TokenPair        `json:"token_pair"`
	Quantity      Quantity         `json:"quantity_requested"`
	PositionIn    Quantity         `json:"position_in"`
	PositionOut   Quantity         `json:"position_out"`
	SideRequested string           `json:"side_requested"`
	QuoteTime     time.Time        `json:"t_quote"`
	ExpiryTime    time.Time        `json:"t_expiry"`
	ExecutionTime time.Time        `json:"t_execute"`
	IsFilled      bool             `json:"is_filled"`
	TraderEmail   string           `json:"trader_email"`
	Error         FalconXError     `json:"error"`
	Warnings      []FalconXWarning `json:"warnings"`
	ClientOrderId string           `json:"client_order_id"`
}

type RestClient

type RestClient struct {
	Config     RestClientConfig
	HTTPClient *http.Client
}

func NewRestClient

func NewRestClient(config RestClientConfig) *RestClient

func (*RestClient) ExecuteQuote

func (client *RestClient) ExecuteQuote(quoteParams QuoteExecutionRequest) (QuoteResponse, error)

ExecuteQuote executes the quote.

:param fx_quote_id: (str) the quote id received via get_quote
:param side: (str) must be either buy or sell
    Example:
        {
            'status': 'success',
            'buy_price': 294.0,
            'error': None,
            'fx_quote_id': 'fad0ac687b1e439a92a0bafd92441e48',
            'is_filled': True,
            'price_executed': 294.0,
            'quantity_requested': {'token': 'ETH', 'value': '0.10000'},
            'sell_price': 293.94,
            'side_executed': 'buy',
            'side_requested': 'two_way',
            't_execute': '2019-07-03T21:45:10.358335+00:00',
            't_expiry': '2019-07-03T21:45:17.198692+00:00',
            't_quote': '2019-07-03T21:45:07.198688+00:00',
            'token_pair': {'base_token': 'ETH', 'quote_token': 'USD'}
        }

func (*RestClient) GetBalances

func (client *RestClient) GetBalances() ([]Balance, error)

GetBalances gets account balances.

:param platform: possible values -> ('browser', 'api', 'margin')
    Example:
        [
            {'balance': 0.0, 'token': 'BTC', 'platform': 'browser'},
            {'balance': -1.3772005993291505, 'token': 'ETH', 'platform': 'api'},
            {'balance': 187.624207, 'token': 'USD', 'platform': 'api'}
        ]

func (*RestClient) GetExecutedQuotes

func (client *RestClient) GetExecutedQuotes(tStart time.Time, tEnd time.Time) ([]QuoteResponse, error)

GetExecutedQuotes gets a historical record of executed quotes in the time range.

:param t_start: (str) time in ISO8601 format (e.g. '2019-07-02T22:06:24.342342+00:00')
:param t_end: (str) time in ISO8601 format (e.g. '2019-07-03T22:06:24.234213+00:00'
:param platform: possible values -> ('browser', 'api', 'margin')
    Example:
        [{'buy_price': 293.1, 'error': None, 'fx_quote_id': 'e2e1758f1a094a2a85825b592e9fc0d9',
        'is_filled': True, 'price_executed': 293.1, 'platform': 'browser', 'quantity_requested': {'token': 'ETH', 'value': '0.10000'},
        'sell_price': 293.03, 'side_executed': 'buy', 'side_requested': 'two_way', 'status': 'success',
        't_execute': '2019-07-03T14:02:56.539710+00:00', 't_expiry': '2019-07-03T14:03:02.038093+00:00',
        't_quote': '2019-07-03T14:02:52.038087+00:00',
        'token_pair': {'base_token': 'ETH', 'quote_token': 'USD'}, 'trader_email': 'trader1@company.com'},
        {'buy_price': 293.1, 'error': None, 'fx_quote_id': 'fc17a0d884444a0db5a7d9568c6c3f70',
        'is_filled': True, 'price_executed': 293.03, 'platform': 'api', 'quantity_requested': {'token': 'ETH', 'value': '0.10000'},
        'sell_price': 293.03, 'side_executed': 'sell', 'side_requested': 'two_way', 'status': 'success',
        't_execute': '2019-07-03T14:02:46.480337+00:00', 't_expiry': '2019-07-03T14:02:50.454222+00:00',
        't_quote': '2019-07-03T14:02:40.454217+00:00', 'token_pair': {'base_token': 'ETH', 'quote_token': 'USD'},
        'trader_email': 'trader2@company.com'}]

func (*RestClient) GetQuote

func (client *RestClient) GetQuote(quoteParams QuoteRequest) (QuoteResponse, error)

GetQuote gets a two_way, buy or sell quote for a token pair.

        :param base: (str) base token e.g. BTC, ETH
        :param quote: (str) quote token e.g. USD, BTC
        :param quantity: (float, Decimal)
        :param side: (str) 'two_way', 'buy', 'sell'
		   Example:
            {
              "status": "success",
              "fx_quote_id": "00c884b056f949338788dfb59e495377",
              "buy_price": 12650,
              "sell_price": null,
              "token_pair": {
                "base_token": "BTC",
                "quote_token": "USD"
              },
              "quantity_requested": {
                "token": "BTC",
                "value": "10"
              },
              "side_requested": "buy",
              "t_quote": "2019-06-27T11:59:21.875725+00:00",
              "t_expiry": "2019-06-27T11:59:22.875725+00:00",
              "is_filled": false,
              "side_executed": null,
              "price_executed": null,
              "t_execute": null,
              "client_order_id": "d6f3e1fa-e148-4009-9c07-a87f9ae78d1a"
            }

func (*RestClient) GetQuoteStatus

func (client *RestClient) GetQuoteStatus(fxQuoteID string) (QuoteResponse, error)

GetQuoteStatus checks the status of a quote already requested.

:param fx_quote_id: (str) the quote id received via get_quote
    Example:
        {
          "status": "success",
          "fx_quote_id": "00c884b056f949338788dfb59e495377",
          "buy_price": 12650,
          "sell_price": null,
          "platform": "api",
          "token_pair": {
            "base_token": "BTC",
            "quote_token": "USD"
          },
          "quantity_requested": {
            "token": "BTC",
            "value": "10"
          },
          "side_requested": "buy",
          "t_quote": "2019-06-27T11:59:21.875725+00:00",
          "t_expiry": "2019-06-27T11:59:22.875725+00:00",
          "is_filled": false,
          "side_executed": null,
          "price_executed": null,
          "t_execute": null,
          "trader_email": "trader1@company.com"
        }

func (*RestClient) GetTotalBalances

func (client *RestClient) GetTotalBalances() ([]TotalBalance, error)

func (*RestClient) GetTradeLimits

func (client *RestClient) GetTradeLimits(platform string) (TradeLimits, error)

func (*RestClient) GetTradeSizes

func (client *RestClient) GetTradeSizes() ([]TradeSize, error)

func (*RestClient) GetTradeVolume

func (client *RestClient) GetTradeVolume(tStart time.Time, tEnd time.Time) (TradeVolume, error)

func (*RestClient) GetTradingPairs

func (client *RestClient) GetTradingPairs() ([]TokenPair, error)

GetTradingPairs gets a list of trading pairs you are eligible to trade Example: [{'base_token': 'BTC', 'quote_token': 'USD'}, {'base_token': 'ETH', 'quote_token': 'USD'}]

func (*RestClient) GetTransfers

func (client *RestClient) GetTransfers(tStart time.Time, tEnd time.Time) ([]Transfer, error)

GetTransfers gets a historical record of deposits/withdrawals between the given time range.

:param t_start: (str) time in ISO8601 format (e.g. '2019-07-02T22:06:24.342342+00:00')
:param t_end: (str) time in ISO8601 format (e.g. '2019-07-03T22:06:24.234213+00:00'
:param platform: possible values -> ('browser', 'api', 'margin')
    Example:
        [
          {
            "type": "deposit",
            "platform": "api",
            "token": "BTC",
            "quantity": 1.0,
            "t_create": "2019-06-20T01:01:01+00:00"
          },
          {
            "type": "withdrawal",
            "platform": "midas",
            "token": "BTC",
            "quantity": 1.0,
            "t_create": "2019-06-22T01:01:01+00:00"
          }
        ]

func (*RestClient) Headers

func (client *RestClient) Headers(method, url, timestamp, data string) (map[string]string, error)

Headers generates a map that can be used as headers to authenticate a request

func (*RestClient) PlaceOrder

func (client *RestClient) PlaceOrder(orderParams OrderRequest) (OrderResponse, error)

PlaceOrder gets a two_way, buy or sell quote for a token pair.

        :param base: (str) base token e.g. BTC, ETH
        :param quote: (str) quote token e.g. USD, BTC
        :param quantity: (float, Decimal)
        :param side: (str) 'buy', 'sell'
        :param order_type: (str) 'market', 'limit'
        :param time_in_force: (str) 'fok' [only required for limit orders]
        :param limit_price: (float, Decimal) [only required for limit orders]
        :param slippage_bps: (float, Decimal) [only valid for fok limit orders]
		   Example:
            {
                "status": "success",
                "fx_quote_id": "00c884b056f949338788dfb59e495377",
                "buy_price": 8545.12,
                "sell_price": null,
                "platform": "api",
                "token_pair": {
                    "base_token": "BTC",
                    "quote_token": "USD"
                },
                "quantity_requested": {
                    "token": "BTC",
                    "value": "10"
                },
                "side_requested": "buy",
                "t_quote": "2019-06-27T11:59:21.875725+00:00",
                "t_expiry": "2019-06-27T11:59:22.875725+00:00",
                "is_filled": true,
                "gross_fee_bps": 8,
                "gross_fee_usd": 101.20,
                "rebate_bps": 3,
                "rebate_usd": 37.95,
                "fee_bps": 5,
                "fee_usd": 63.25,
                "side_executed": "buy",
                "trader_email": "trader@company.com",
                "order_type": "limit",
                "time_in_force": "fok",
                "limit_price": 8547.11,
                "slippage_bps": 2,
                "error": null,
                "client_order_id": "d6f3e1fa-e148-4009-9c07-a87f9ae78d1a"
            }

func (*RestClient) Request

func (client *RestClient) Request(method string, url string,
	params interface{}, result interface{}) (res *http.Response, err error)

type RestClientConfig

type RestClientConfig struct {
	BaseURL    string
	Secret     string
	APIKey     string
	Passphrase string
}

type SocketClient

type SocketClient struct {
	Config     SocketClientConfig
	Namespace  string
	Transport  *transport.WebsocketTransport
	Connection *gosocketio.Client
}

func NewSocketClient

func NewSocketClient(config SocketClientConfig, namespace string) *SocketClient

func (*SocketClient) AddAuth

func (client *SocketClient) AddAuth() error

func (*SocketClient) Connect

func (client *SocketClient) Connect() error

type SocketClientConfig

type SocketClientConfig struct {
	Host       string
	Secret     string
	APIKey     string
	Passphrase string
}

type SubscriptionRequest

type SubscriptionRequest struct {
	TokenPair       TokenPair `json:"token_pair"`
	Quantity        []float64 `json:"quantity"`
	ClientRequestID string    `json:"client_request_id"`
}

type TokenPair

type TokenPair struct {
	BaseToken  string `json:"base_token"`
	QuoteToken string `json:"quote_token"`
}

type TotalBalance

type TotalBalance struct {
	Token        string  `json:"token"`
	TotalBalance float64 `json:"total_balance"`
}

type TradeLimit

type TradeLimit struct {
	Available float64 `json:"available"`
	Total     float64 `json:"total"`
	Used      float64 `json:"used"`
}

type TradeLimits

type TradeLimits struct {
	GrossLimits TradeLimit `json:"gross_limits"`
	NetLimits   TradeLimit `json:"net_limits"`
}

type TradeSize

type TradeSize struct {
	Platform                 string         `json:"platform"`
	TokenPair                TokenPair      `json:"token_pair"`
	TradeSizeLimitQuoteToken TradeSizeLimit `json:"trade_size_limits_in_quote_token"`
}

type TradeSizeLimit

type TradeSizeLimit struct {
	Max float64 `json:"max"`
	Min float64 `json:"min"`
}

type TradeVolume

type TradeVolume struct {
	StartDate time.Time `json:"start_date"`
	EndDate   time.Time `json:"end_date"`
	USDVolume float64   `json:"usd_volume"`
}

type Transfer

type Transfer struct {
	Type       string    `json:"type"`
	Platform   string    `json:"platform"`
	Token      string    `json:"token"`
	Quantity   float64   `json:"quantity,string"`
	CreateTime time.Time `json:"t_create"`
	Status     string    `json:"status"`
}

type UserConfigRequest

type UserConfigRequest struct {
	MessageType     string `json:"message_type"`
	ClientRequestID string `json:"client_request_id"`
}

type UserConfigResponse

type UserConfigResponse struct {
	MessageType     string      `json:"message_type"`
	ClientRequestID string      `json:"client_request_id"`
	Success         bool        `json:"success"`
	Data            interface{} `json:"data"`
	Error           interface{} `json:"error"`
}

Jump to

Keyboard shortcuts

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