mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-04 23:16:54 +00:00
exchanges: Update Bybit exchange to V5 (#1301)
* Adding Bybit public endpoints * Completed adding market endpoints * Added trade endpoints * Adding position endpoints * completing position endpoints * Adding Pre-upgrade endpoints * Completed adding Pre-upgrade and Account endpoints * Added asset endpoints * Added user endpoints and unit tests * Adding spot leverage and margin trade endpoints * spot margin trade added * added spot-margin-trade, institutional lending, c2c lending, and broker * Adding wrapper funnctions * Working on wrapper public methods * Added wrapper functions and unit tests * Added websocket support with unit tests * Update websocket handlers and added rate-limiter * wrapper function, websocket handlers, and linter issues fixe * unit tests fixes and codespell correction * Update documentation * Minor websocket handling fix and URL consts merging * types, unit test other updates * Updated websocket and methods based on review * Added GetFeeByType method with unit test and fixes * add filter for Unified and Normal endpoints * Mock recording and unit tests update * minor linter issue fix * websocket and rest tests and fix * change asset types and wrapper methods update * rm: forgotten panic message * endpoints, websocket and unit tests update * Added and updated endpoints and unit test * linter and spell fix * unit test and orders update * Update on endpoints, fields, config pairs and formating, and unit tests * minor update on responses * Fix unit test and types * Unit tests, models, and wrapper issues fix and mock test recording * rm print statement * Fix issue, add FundingRate wrapper func, mock record * minor type and unit test update * Update on order handling and unit test * Minor test * Minor fix in wrapper * unit tests update, recording, and documentation update * Unit tests and minor wrapper function update * minor unit test fix * Added newly added endpoints, unit tests, and mock recording * Rename GetInstruments -> GetInstrumentInfo * doc update * Minor unit tests update * Minor unit test and wrapper update * Fix linter issue * Add unit test and minor updates * Revert websocket error declaration * Revert websocket error declaration * Balace --> Balance * Fix config issues * Added next funding time minor fix * Update GetLatestFundingRates and record mock test data * Added LatestFundingRate time * Fix test issue of TestAllExchangeWrappers * config pairs update * configtest spot pairs update * Minor update on options UpdateOrderExecutionLimits wrapper func * Linter issue fix and added new currency codes * Added new currency codes * Update bybit pairs in config_example * config assets pair format update
This commit is contained in:
@@ -63,9 +63,13 @@ type Submit struct {
|
||||
QuoteAmount float64
|
||||
// TriggerPrice is mandatory if order type `Stop, Stop Limit or Take Profit`
|
||||
// See btcmarkets_wrapper.go.
|
||||
TriggerPrice float64
|
||||
ClientID string // TODO: Shift to credentials
|
||||
ClientOrderID string
|
||||
TriggerPrice float64
|
||||
|
||||
// added to represent a unified trigger price type information such as LastPrice, MarkPrice, and IndexPrice
|
||||
// https://bybit-exchange.github.io/docs/v5/order/create-order
|
||||
TriggerPriceType PriceType
|
||||
ClientID string // TODO: Shift to credentials
|
||||
ClientOrderID string
|
||||
|
||||
// The system will first borrow you funds at the optimal interest rate and then place an order for you.
|
||||
// see kucoin_wrapper.go
|
||||
@@ -80,7 +84,8 @@ type Submit struct {
|
||||
RetrieveFees bool
|
||||
// RetrieveFeeDelay some exchanges take time to properly save order data
|
||||
// and cannot retrieve fees data immediately
|
||||
RetrieveFeeDelay time.Duration
|
||||
RetrieveFeeDelay time.Duration
|
||||
RiskManagementModes RiskManagementModes
|
||||
|
||||
// Hidden when enabled orders not displaying in order book.
|
||||
Hidden bool
|
||||
@@ -142,6 +147,12 @@ type Modify struct {
|
||||
Price float64
|
||||
Amount float64
|
||||
TriggerPrice float64
|
||||
|
||||
// added to represent a unified trigger price type information such as LastPrice, MarkPrice, and IndexPrice
|
||||
// https://bybit-exchange.github.io/docs/v5/order/create-order
|
||||
TriggerPriceType PriceType
|
||||
|
||||
RiskManagementModes RiskManagementModes
|
||||
}
|
||||
|
||||
// ModifyResponse is an order modifying return type
|
||||
@@ -303,6 +314,7 @@ const (
|
||||
Active
|
||||
PartiallyCancelled
|
||||
PartiallyFilled
|
||||
PartiallyFilledCancelled
|
||||
Filled
|
||||
Cancelled
|
||||
PendingCancel
|
||||
@@ -398,3 +410,34 @@ type ClassificationError struct {
|
||||
// forcing required filter operations when calling method Filter() on
|
||||
// MultiOrderRequest.
|
||||
type FilteredOrders []Detail
|
||||
|
||||
// RiskManagement represents a risk management detail information.
|
||||
type RiskManagement struct {
|
||||
Enabled bool
|
||||
TriggerPriceType PriceType
|
||||
Price float64
|
||||
|
||||
// LimitPrice limit order price when stop-los or take-profit risk management method is triggered
|
||||
LimitPrice float64
|
||||
// OrderType order type when stop-loss or take-profit risk management method is triggered.
|
||||
OrderType Type
|
||||
}
|
||||
|
||||
// RiskManagementModes represents take-profit and stop-loss risk management methods.
|
||||
type RiskManagementModes struct {
|
||||
// Mode take-profit/stop-loss mode
|
||||
Mode string
|
||||
TakeProfit RiskManagement
|
||||
StopLoss RiskManagement
|
||||
}
|
||||
|
||||
// PriceType enforces a standard for price types used for take-profit and stop-loss trigger types
|
||||
type PriceType uint8
|
||||
|
||||
// price types
|
||||
const (
|
||||
LastPrice PriceType = 0
|
||||
IndexPrice PriceType = 1 << iota
|
||||
MarkPrice
|
||||
UnknownPriceType
|
||||
)
|
||||
|
||||
@@ -25,7 +25,7 @@ const (
|
||||
shortSide = Short | Sell | Ask
|
||||
longSide = Long | Buy | Bid
|
||||
|
||||
inactiveStatuses = Filled | Cancelled | InsufficientBalance | MarketUnavailable | Rejected | PartiallyCancelled | Expired | Closed | AnyStatus | Cancelling | Liquidated
|
||||
inactiveStatuses = Filled | Cancelled | InsufficientBalance | MarketUnavailable | Rejected | PartiallyCancelled | PartiallyFilledCancelled | Expired | Closed | AnyStatus | Cancelling | Liquidated
|
||||
activeStatuses = Active | Open | PartiallyFilled | New | PendingCancel | Hidden | AutoDeleverage | Pending
|
||||
notPlaced = InsufficientBalance | MarketUnavailable | Rejected
|
||||
)
|
||||
@@ -37,6 +37,9 @@ var (
|
||||
// ErrOrderNotFound is returned when no order is found
|
||||
ErrOrderNotFound = errors.New("order not found")
|
||||
|
||||
// ErrUnknownPriceType returned when price type is unknown
|
||||
ErrUnknownPriceType = errors.New("unknown price type")
|
||||
|
||||
errTimeInForceConflict = errors.New("multiple time in force options applied")
|
||||
errUnrecognisedOrderType = errors.New("unrecognised order type")
|
||||
errUnrecognisedOrderStatus = errors.New("unrecognised order status")
|
||||
@@ -784,6 +787,8 @@ func (s Status) String() string {
|
||||
return "PARTIALLY_CANCELLED"
|
||||
case PartiallyFilled:
|
||||
return "PARTIALLY_FILLED"
|
||||
case PartiallyFilledCancelled:
|
||||
return "PARTIALLY_FILLED_CANCELED"
|
||||
case Filled:
|
||||
return "FILLED"
|
||||
case Cancelled:
|
||||
@@ -1132,6 +1137,8 @@ func StringToOrderStatus(status string) (Status, error) {
|
||||
return Filled, nil
|
||||
case PartiallyCancelled.String(), "PARTIALLY CANCELLED", "ORDER_PARTIALLY_TRANSACTED":
|
||||
return PartiallyCancelled, nil
|
||||
case PartiallyFilledCancelled.String(), "PARTIALLYFILLEDCANCELED":
|
||||
return PartiallyFilledCancelled, nil
|
||||
case Open.String():
|
||||
return Open, nil
|
||||
case Closed.String():
|
||||
@@ -1285,3 +1292,33 @@ func (m *Modify) Validate(opt ...validate.Checker) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// String implements the stringer interface
|
||||
func (t PriceType) String() string {
|
||||
switch t {
|
||||
case LastPrice:
|
||||
return "LastPrice"
|
||||
case IndexPrice:
|
||||
return "IndexPrice"
|
||||
case MarkPrice:
|
||||
return "MarkPrice"
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
// StringToPriceType for converting case insensitive order side
|
||||
// and returning a real Side
|
||||
func (t PriceType) StringToPriceType(priceType string) (PriceType, error) {
|
||||
priceType = strings.ToLower(priceType)
|
||||
switch priceType {
|
||||
case "lastprice", "":
|
||||
return LastPrice, nil
|
||||
case "indexprice":
|
||||
return IndexPrice, nil
|
||||
case "markprice":
|
||||
return MarkPrice, nil
|
||||
default:
|
||||
return UnknownPriceType, ErrUnknownPriceType
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user