mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-29 15:10:37 +00:00
Binance,Okx: Add Leverage, MarginType, Positions and CollateralMode support (#1220)
* init * surprise train commit * basic distinctions * the terms of binance are confusing * renames and introduction of allocatedMargin * add new margin funcs * pulling out wires * implement proper getposition stuff * bad coding day * investigate order manager next * a broken mess, but a progressing one * finally completes some usdtmargined stuff * coinMfutures eludes me * expand to okx * imports fix * completes okx wrapper implementations * cleans and polishes before rpc implementations * rpc setup, order manager features, exch features * more rpc, collateral and margin things * mini test * looking at rpc response, expansion of features * reorganising before the storm * changing how futures requests work * cleanup and tests of cli usage * remove silly client side logic * cleanup * collateral package, typo fix, margin err, rpc derive * uses convert.StringToFloat ONLY ON STRUCTS FROM THIS PR * fix binance order history bug * niteroos * adds new funcs to exchange standards testing * more post merge fixes * fix binance * replace simepletimeformat * fix for merge * merge fixes * micro fixes * order side now required for leverage * fix up the rest * global -> portfolio collateral * Update exchanges/collateral/collateral_test.go Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io> * adds fields and todos * rm field redundancy * lint fix oopsie daisy * fixes panic, expands error and cli explanations (sorry shaz) * ensures casing is appropriate for underlying * Adds a shiny TODO --------- Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io>
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/account"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/collateral"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/currencystate"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/deposit"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/fundingrate"
|
||||
@@ -31,6 +32,8 @@ type IBotExchange interface {
|
||||
Shutdown() error
|
||||
GetName() string
|
||||
SetEnabled(bool)
|
||||
GetEnabledFeatures() FeaturesEnabled
|
||||
GetSupportedFeatures() FeaturesSupported
|
||||
FetchTicker(ctx context.Context, p currency.Pair, a asset.Item) (*ticker.Price, error)
|
||||
UpdateTicker(ctx context.Context, p currency.Pair, a asset.Item) (*ticker.Price, error)
|
||||
UpdateTickers(ctx context.Context, a asset.Item) error
|
||||
@@ -92,6 +95,7 @@ type IBotExchange interface {
|
||||
OrderManagement
|
||||
CurrencyStateManagement
|
||||
FuturesManagement
|
||||
MarginManagement
|
||||
}
|
||||
|
||||
// OrderManagement defines functionality for order management
|
||||
@@ -141,14 +145,26 @@ type FunctionalityChecker interface {
|
||||
|
||||
// FuturesManagement manages futures orders, pnl and collateral calculations
|
||||
type FuturesManagement interface {
|
||||
GetPositionSummary(context.Context, *order.PositionSummaryRequest) (*order.PositionSummary, error)
|
||||
ScaleCollateral(ctx context.Context, calculator *order.CollateralCalculator) (*order.CollateralByCurrency, error)
|
||||
ScaleCollateral(ctx context.Context, calculator *order.CollateralCalculator) (*collateral.ByCurrency, error)
|
||||
CalculateTotalCollateral(context.Context, *order.TotalCollateralCalculator) (*order.TotalCollateralResponse, error)
|
||||
GetFuturesPositions(context.Context, *order.PositionsRequest) ([]order.PositionDetails, error)
|
||||
GetFundingRates(context.Context, *fundingrate.RatesRequest) (*fundingrate.Rates, error)
|
||||
GetLatestFundingRate(context.Context, *fundingrate.LatestRateRequest) (*fundingrate.LatestRateResponse, error)
|
||||
IsPerpetualFutureCurrency(asset.Item, currency.Pair) (bool, error)
|
||||
GetCollateralCurrencyForContract(asset.Item, currency.Pair) (currency.Code, asset.Item, error)
|
||||
GetMarginRatesHistory(context.Context, *margin.RateHistoryRequest) (*margin.RateHistoryResponse, error)
|
||||
order.PNLCalculation
|
||||
|
||||
GetFuturesPositionSummary(context.Context, *order.PositionSummaryRequest) (*order.PositionSummary, error)
|
||||
GetFuturesPositionOrders(context.Context, *order.PositionsRequest) ([]order.PositionResponse, error)
|
||||
SetCollateralMode(ctx context.Context, item asset.Item, mode collateral.Mode) error
|
||||
GetCollateralMode(ctx context.Context, item asset.Item) (collateral.Mode, error)
|
||||
SetLeverage(ctx context.Context, item asset.Item, pair currency.Pair, marginType margin.Type, amount float64, orderSide order.Side) error
|
||||
GetLeverage(ctx context.Context, item asset.Item, pair currency.Pair, marginType margin.Type, orderSide order.Side) (float64, error)
|
||||
}
|
||||
|
||||
// MarginManagement manages margin positions and rates
|
||||
type MarginManagement interface {
|
||||
SetMarginType(ctx context.Context, item asset.Item, pair currency.Pair, tp margin.Type) error
|
||||
ChangePositionMargin(ctx context.Context, change *margin.PositionChangeRequest) (*margin.PositionChangeResponse, error)
|
||||
GetMarginRatesHistory(context.Context, *margin.RateHistoryRequest) (*margin.RateHistoryResponse, error)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user