position

package
v0.1.37 Latest Latest
Warning

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

Go to latest
Published: May 21, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertAddReduceMarginRequestToParams

func ConvertAddReduceMarginRequestToParams(req *AddReduceMarginRequest) client.Params

func ConvertConfirmNewRiskLimitRequestToParams

func ConvertConfirmNewRiskLimitRequestToParams(req *ConfirmNewRiskLimitRequest) client.Params

func ConvertGetClosedPnLRequestToParams

func ConvertGetClosedPnLRequestToParams(req *GetClosedPnLRequest) client.Params

func ConvertGetMovePositionHistoryRequestToParams

func ConvertGetMovePositionHistoryRequestToParams(req *GetMovePositionHistoryRequest) client.Params

func ConvertMovePositionRequestToParams

func ConvertMovePositionRequestToParams(req *MovePositionRequest) client.Params

func ConvertPositionRequestParams

func ConvertPositionRequestParams(params *RequestParams) client.Params

ConvertPositionRequestParams prepares the request parameters for fetching position info.

func ConvertSetAutoAddMarginRequestToParams

func ConvertSetAutoAddMarginRequestToParams(req *SetAutoAddMarginRequest) client.Params

func ConvertSetLeverageRequestToParams

func ConvertSetLeverageRequestToParams(req *SetLeverageRequest) client.Params

func ConvertSetRiskLimitRequestToParams

func ConvertSetRiskLimitRequestToParams(req *SetRiskLimitRequest) client.Params

func ConvertSetTPSLModeRequestToParams

func ConvertSetTPSLModeRequestToParams(req *SetTPSLModeRequest) client.Params

func ConvertSetTradingStopRequestToParams

func ConvertSetTradingStopRequestToParams(req *SetTradingStopRequest) client.Params

func ConvertSwitchMarginModeRequestToParams

func ConvertSwitchMarginModeRequestToParams(req *SwitchMarginModeRequest) client.Params

func ConvertSwitchPositionModeRequestToParams

func ConvertSwitchPositionModeRequestToParams(req *SwitchPositionModeRequest) client.Params

Types

type AddReduceMarginRequest

type AddReduceMarginRequest struct {
	Category    string `json:"category"`    // Required: "linear" or "inverse"
	Symbol      string `json:"symbol"`      // Required: Symbol name
	Margin      string `json:"margin"`      // Required: Amount to add (positive) or reduce (negative)
	PositionIdx *int   `json:"positionIdx"` // Optional: Position index for hedge mode
}

AddReduceMarginRequest represents the payload for adding or reducing margin.

type ClosedPnLResponse

type ClosedPnLResponse struct {
	RetCode int    `json:"retCode"`
	RetMsg  string `json:"retMsg"`
	Result  struct {
		NextPageCursor string        `json:"nextPageCursor"`
		Category       string        `json:"category"`
		List           []interface{} `json:"list"`
	} `json:"result"`
	RetExtInfo interface{} `json:"retExtInfo"`
	Time       int64       `json:"time"`
}

ClosedPnLResponse represents the response structure for closed PnL records.

type ConfirmNewRiskLimitRequest

type ConfirmNewRiskLimitRequest struct {
	Category string `json:"category"` // Required: "linear" or "inverse"
	Symbol   string `json:"symbol"`   // Required: Symbol name
}

ConfirmNewRiskLimitRequest represents the payload for confirming a new risk limit.

type Details

type Details struct {
	PositionIdx            int    `json:"positionIdx"`
	RiskID                 int    `json:"riskId"`
	RiskLimitValue         string `json:"riskLimitValue"`
	Symbol                 string `json:"symbol"`
	Side                   string `json:"side"`
	Size                   string `json:"size"`
	AvgPrice               string `json:"avgPrice"`
	PositionValue          string `json:"positionValue"`
	TradeMode              int    `json:"tradeMode"`
	PositionStatus         string `json:"positionStatus"`
	AutoAddMargin          int    `json:"autoAddMargin"`
	AdlRankIndicator       int    `json:"adlRankIndicator"`
	Leverage               string `json:"leverage"`
	PositionBalance        string `json:"positionBalance"`
	MarkPrice              string `json:"markPrice"`
	LiqPrice               string `json:"liqPrice"`
	BustPrice              string `json:"bustPrice"`
	PositionMM             string `json:"positionMM"`
	PositionIM             string `json:"positionIM"`
	TpslMode               string `json:"tpslMode"`
	TakeProfit             string `json:"takeProfit"`
	StopLoss               string `json:"stopLoss"`
	TrailingStop           string `json:"trailingStop"`
	UnrealisedPnl          string `json:"unrealisedPnl"`
	CumRealisedPnl         string `json:"cumRealisedPnl"`
	Seq                    int64  `json:"seq"`
	IsReduceOnly           bool   `json:"isReduceOnly"`
	MmrSysUpdateTime       string `json:"mmrSysUpdateTime"`
	LeverageSysUpdatedTime string `json:"leverageSysUpdatedTime"`
	CreatedTime            string `json:"createdTime"`
	UpdatedTime            string `json:"updatedTime"`
}

Details represent the details of a single position.

type GetClosedPnLRequest

type GetClosedPnLRequest struct {
	Category  string  `json:"category"`            // Required: "linear" or "inverse"
	Symbol    *string `json:"symbol,omitempty"`    // Optional: Symbol name
	StartTime *int64  `json:"startTime,omitempty"` // Optional: The start timestamp (ms)
	EndTime   *int64  `json:"endTime,omitempty"`   // Optional: The end timestamp (ms)
	Limit     *int    `json:"limit,omitempty"`     // Optional: Limit for data size per page
	Cursor    *string `json:"cursor,omitempty"`    // Optional: Cursor for pagination
}

GetClosedPnLRequest represents the query parameters for fetching closed PnL records.

type GetMovePositionHistoryRequest

type GetMovePositionHistoryRequest struct {
	Category     *string `json:"category,omitempty"`     // Optional: Product type
	Symbol       *string `json:"symbol,omitempty"`       // Optional: Symbol name
	StartTime    *int64  `json:"startTime,omitempty"`    // Optional: Start timestamp
	EndTime      *int64  `json:"endTime,omitempty"`      // Optional: End timestamp
	Status       *string `json:"status,omitempty"`       // Optional: Order status
	BlockTradeId *string `json:"blockTradeId,omitempty"` // Optional: Block trade ID
	Limit        *int    `json:"limit,omitempty"`        // Optional: Data size limit per page
	Cursor       *string `json:"cursor,omitempty"`       // Optional: Pagination cursor
}

GetMovePositionHistoryRequest represents the query parameters for fetching move position history.

type GetMovePositionHistoryResponse

type GetMovePositionHistoryResponse struct {
	RetCode int    `json:"retCode"`
	RetMsg  string `json:"retMsg"`
	Result  struct {
		List           []MovePositionHistoryEntry `json:"list"`
		NextPageCursor string                     `json:"nextPageCursor"`
	} `json:"result"`
	RetExtInfo interface{} `json:"retExtInfo"`
	Time       int64       `json:"time"`
}

GetMovePositionHistoryResponse represents the response from fetching move position history.

type MovePositionHistoryEntry

type MovePositionHistoryEntry struct {
	BlockTradeId  string `json:"blockTradeId"`
	Category      string `json:"category"`
	OrderId       string `json:"orderId"`
	UserId        int    `json:"userId"`
	Symbol        string `json:"symbol"`
	Side          string `json:"side"`
	Price         string `json:"price"`
	Qty           string `json:"qty"`
	ExecFee       string `json:"execFee"`
	Status        string `json:"status"`
	ExecId        string `json:"execId"`
	ResultCode    int    `json:"resultCode"`
	ResultMessage string `json:"resultMessage"`
	CreatedAt     int64  `json:"createdAt"`
	UpdatedAt     int64  `json:"updatedAt"`
	RejectParty   string `json:"rejectParty"`
}

MovePositionHistoryEntry represents a single entry in the move position history.

type MovePositionRequest

type MovePositionRequest struct {
	FromUID string                   `json:"fromUid"`
	ToUID   string                   `json:"toUid"`
	List    []MovePositionRequestLeg `json:"list"`
}

MovePositionRequest encapsulates the payload for moving positions.

type MovePositionRequestLeg

type MovePositionRequestLeg struct {
	Category string `json:"category"` // "linear", "spot", "option"
	Symbol   string `json:"symbol"`
	Price    string `json:"price"`
	Side     string `json:"side"` // "Buy" or "Sell"
	Qty      string `json:"qty"`
}

MovePositionRequestLeg represents a single leg of a move position request.

type MovePositionResponse

type MovePositionResponse struct {
	RetCode int    `json:"retCode"`
	RetMsg  string `json:"retMsg"`
	Result  struct {
		BlockTradeId string `json:"blockTradeId"`
		Status       string `json:"status"`
		RejectParty  string `json:"rejectParty"`
	} `json:"result"`
}

MovePositionResponse represents the response from a move position request.

type Position

type Position interface {
	// GetPositionInfo retrieves position information based on the provided parameters.
	// params: RequestParams - the parameters for the position info request.
	// returns: *Response - the response containing position information.
	//          error - an error if the request fails.
	GetPositionInfo(params *RequestParams) (*Response, error)

	// SetLeverage sets the leverage for a position based on the provided request.
	// req: SetLeverageRequest - the request containing leverage settings.
	// returns: *Response - the response after setting the leverage.
	//          error - an error if the request fails.
	SetLeverage(req *SetLeverageRequest) (*Response, error)

	// SwitchMarginMode switches the margin mode (cross or isolated) for a position.
	// req: SwitchMarginModeRequest - the request containing margin mode settings.
	// returns: *Response - the response after switching the margin mode.
	//          error - an error if the request fails.
	SwitchMarginMode(req *SwitchMarginModeRequest) (*Response, error)

	// SetTPSLMode sets the Take Profit/Stop Loss mode for a given symbol.
	// req: SetTPSLModeRequest - the request containing TP/SL mode settings.
	// returns: *Response - the response after setting the TP/SL mode.
	//          error - an error if the request fails.
	SetTPSLMode(req *SetTPSLModeRequest) (*Response, error)

	// SwitchPositionMode switches the position mode for USDT perpetual and Inverse futures.
	// req: SwitchPositionModeRequest - the request containing position mode settings.
	// returns: *Response - the response after switching the position mode.
	//          error - an error if the request fails.
	SwitchPositionMode(req *SwitchPositionModeRequest) (*Response, error)

	// SetRiskLimit sets the risk limit for a specific symbol.
	// req: SetRiskLimitRequest - the request containing risk limit settings.
	// returns: *Response - the response after setting the risk limit.
	//          error - an error if the request fails.
	SetRiskLimit(req *SetRiskLimitRequest) (*Response, error)

	// SetTradingStop sets take profit, stop loss, or trailing stop for the position.
	// req: SetTradingStopRequest - the request containing trading stop settings.
	// returns: *Response - the response after setting the trading stop.
	//          error - an error if the request fails.
	SetTradingStop(req *SetTradingStopRequest) (*Response, error)

	// SetAutoAddMargin toggles auto-add-margin for an isolated margin position.
	// req: SetAutoAddMarginRequest - the request containing auto-add-margin settings.
	// returns: *Response - the response after setting auto-add-margin.
	//          error - an error if the request fails.
	SetAutoAddMargin(req *SetAutoAddMarginRequest) (*Response, error)

	// AddOrReduceMargin manually adds or reduces margin for an isolated margin position.
	// req: AddReduceMarginRequest - the request containing add/reduce margin settings.
	// returns: *Response - the response after adding or reducing margin.
	//          error - an error if the request fails.
	AddOrReduceMargin(req *AddReduceMarginRequest) (*Response, error)

	// MovePositions transfers positions between UIDs.
	// req: MovePositionRequest - the request containing move position settings.
	// returns: *MovePositionResponse - the response after moving positions.
	//          error - an error if the request fails.
	MovePositions(req *MovePositionRequest) (*MovePositionResponse, error)

	// GetMovePositionHistory queries the history of moved positions.
	// req: GetMovePositionHistoryRequest - the request containing query parameters for move position history.
	// returns: *GetMovePositionHistoryResponse - the response containing the move position history.
	//          error - an error if the request fails.
	GetMovePositionHistory(req *GetMovePositionHistoryRequest) (*GetMovePositionHistoryResponse, error)

	// ConfirmNewRiskLimit confirms the new risk limit for a position, removing the reduceOnly mark if successful.
	// req: ConfirmNewRiskLimitRequest - the request containing new risk limit settings.
	// returns: *Response - the response after confirming the new risk limit.
	//          error - an error if the request fails.
	ConfirmNewRiskLimit(req *ConfirmNewRiskLimitRequest) (*Response, error)
}

Position defines the interface for interacting with position-related operations in the Bybit API.

func New

func New(c *client.Client) Position

New creates a new instance of the Position interface, which can be used to interact with the Bybit API.

type RequestParams

type RequestParams struct {
	Category   *string `json:"category"`
	Symbol     *string `json:"symbol"`
	BaseCoin   *string `json:"baseCoin"`
	SettleCoin *string `json:"settleCoin"`
	Limit      *int    `json:"limit"`
	Cursor     *string `json:"cursor"`
}

RequestParams represents the query parameters for fetching position information.

type Response

type Response struct {
	RetCode int    `json:"retCode"`
	RetMsg  string `json:"retMsg"`
	Result  struct {
		List           []Details `json:"list"`
		NextPageCursor string    `json:"nextPageCursor"`
		Category       string    `json:"category"`
	} `json:"result"`
	RetExtInfo interface{} `json:"retExtInfo"`
	Time       int64       `json:"time"`
}

Response represents the response structure for position information.

type SetAutoAddMarginRequest

type SetAutoAddMarginRequest struct {
	Category      string `json:"category"`              // Required: "linear" or "inverse"
	Symbol        string `json:"symbol"`                // Required: Symbol name
	AutoAddMargin int    `json:"autoAddMargin"`         // Required: 0 for off, 1 for on
	PositionIdx   *int   `json:"positionIdx,omitempty"` // Optional: Position index for hedge mode
}

SetAutoAddMarginRequest represents the payload for toggling auto-add-margin.

type SetLeverageRequest

type SetLeverageRequest struct {
	Category     *string `json:"category"`
	Symbol       *string `json:"symbol"`
	BuyLeverage  *string `json:"buyLeverage"`
	SellLeverage *string `json:"sellLeverage"`
}

SetLeverageRequest represents the payload for setting leverage.

type SetRiskLimitRequest

type SetRiskLimitRequest struct {
	Category    string `json:"category"`    // Required: "linear" or "inverse"
	Symbol      string `json:"symbol"`      // Required: Symbol name
	RiskID      int    `json:"riskId"`      // Required: Risk limit ID
	PositionIdx *int   `json:"positionIdx"` // Optional: Position index (for hedge mode)
}

SetRiskLimitRequest represents the payload for setting the risk limit of a position.

type SetTPSLModeRequest

type SetTPSLModeRequest struct {
	Category *string `json:"category"`
	Symbol   *string `json:"symbol"`
	TPSLMode *string `json:"tpSlMode"` // "Full" or "Partial"
}

SetTPSLModeRequest represents the payload for setting the TP/SL mode.

type SetTradingStopRequest

type SetTradingStopRequest struct {
	Category     string  `json:"category"`               // Required
	Symbol       string  `json:"symbol"`                 // Required
	TakeProfit   *string `json:"takeProfit,omitempty"`   // Optional, 0 to cancel
	StopLoss     *string `json:"stopLoss,omitempty"`     // Optional, 0 to cancel
	TrailingStop *string `json:"trailingStop,omitempty"` // Optional, 0 to cancel
	TpTriggerBy  *string `json:"tpTriggerBy,omitempty"`  // Optional
	SlTriggerBy  *string `json:"slTriggerBy,omitempty"`  // Optional
	ActivePrice  *string `json:"activePrice,omitempty"`  // Optional
	TPSLMode     string  `json:"tpslMode"`               // Required
	TpSize       *string `json:"tpSize,omitempty"`       // Optional
	SlSize       *string `json:"slSize,omitempty"`       // Optional
	TpLimitPrice *string `json:"tpLimitPrice,omitempty"` // Optional
	SlLimitPrice *string `json:"slLimitPrice,omitempty"` // Optional
	TpOrderType  *string `json:"tpOrderType,omitempty"`  // Optional
	SlOrderType  *string `json:"slOrderType,omitempty"`  // Optional
	PositionIdx  int     `json:"positionIdx"`            // Required
}

SetTradingStopRequest represents the payload for setting trading stops (TP, SL, TS).

type SwitchMarginModeRequest

type SwitchMarginModeRequest struct {
	Category     *string `json:"category"`
	Symbol       *string `json:"symbol"`
	TradeMode    *int    `json:"tradeMode"`
	BuyLeverage  *string `json:"buyLeverage"`
	SellLeverage *string `json:"sellLeverage"`
}

type SwitchPositionModeRequest

type SwitchPositionModeRequest struct {
	Category string  `json:"category"`         // Required: "linear" for USDT Perp, "inverse" for Inverse Futures
	Symbol   *string `json:"symbol,omitempty"` // Optional: Symbol name; either symbol or coin is required
	Coin     *string `json:"coin,omitempty"`   // Optional: Coin; either symbol or coin is required
	Mode     *int    `json:"mode"`             // Required: 0 for Merged Single, 3 for Both Sides
}

SwitchPositionModeRequest represents the payload for switching the position mode.

Jump to

Keyboard shortcuts

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