mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-07 15:11:03 +00:00
futures: Implement GetLatestFundingRates across exchanges (#1339)
* adds funding rate implementations and improvements * merge fixes x1 * lint * kucoin funding rates func make * migrate sync-manager to keys * some kucoin work * adds some kucoin wrapper funcs * ehhh, todo * kucoin position * start of orders * adds the kucoin tests yay * multiplier * nits, EWS includes order limits * NotYetImplemented, IsPerp improvements, cleaning * lint, test fix, huobi time * fixes issues, improves testing * fixes linters I WRECKED * local lint but remote lint, lint, lint, lint * fixes err * skip CI * lint * Supported rates, binance endpoints * fixes weird mocktest problems * no, CZ is invalid * fixes some new EWS test errors
This commit is contained in:
@@ -3,6 +3,7 @@ package futures
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/shopspring/decimal"
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/fundingrate"
|
||||
@@ -26,6 +27,8 @@ type Contract struct {
|
||||
Multiplier float64
|
||||
MaxLeverage float64
|
||||
LatestRate fundingrate.Rate
|
||||
FundingRateFloor decimal.Decimal
|
||||
FundingRateCeiling decimal.Decimal
|
||||
}
|
||||
|
||||
// ContractSettlementType holds the various style of contracts offered by futures exchanges
|
||||
|
||||
@@ -134,7 +134,7 @@ func (c *PositionController) GetPositionsForExchange(exch string, item asset.Ite
|
||||
}
|
||||
|
||||
// TrackFundingDetails applies funding rate details to a tracked position
|
||||
func (c *PositionController) TrackFundingDetails(d *fundingrate.Rates) error {
|
||||
func (c *PositionController) TrackFundingDetails(d *fundingrate.HistoricalRates) error {
|
||||
if c == nil {
|
||||
return fmt.Errorf("position controller %w", common.ErrNilPointer)
|
||||
}
|
||||
@@ -459,7 +459,7 @@ func (m *MultiPositionTracker) TrackNewOrder(d *order.Detail) error {
|
||||
}
|
||||
|
||||
// TrackFundingDetails applies funding rate details to a tracked position
|
||||
func (m *MultiPositionTracker) TrackFundingDetails(d *fundingrate.Rates) error {
|
||||
func (m *MultiPositionTracker) TrackFundingDetails(d *fundingrate.HistoricalRates) error {
|
||||
if m == nil {
|
||||
return fmt.Errorf("multi-position tracker %w", common.ErrNilPointer)
|
||||
}
|
||||
@@ -579,7 +579,7 @@ func (p *PositionTracker) GetStats() *Position {
|
||||
if p.fundingRateDetails != nil {
|
||||
frs := make([]fundingrate.Rate, len(p.fundingRateDetails.FundingRates))
|
||||
copy(frs, p.fundingRateDetails.FundingRates)
|
||||
pos.FundingRates = fundingrate.Rates{
|
||||
pos.FundingRates = fundingrate.HistoricalRates{
|
||||
Exchange: p.fundingRateDetails.Exchange,
|
||||
Asset: p.fundingRateDetails.Asset,
|
||||
Pair: p.fundingRateDetails.Pair,
|
||||
@@ -687,7 +687,7 @@ func (p *PositionTracker) GetLatestPNLSnapshot() (PNLResult, error) {
|
||||
}
|
||||
|
||||
// TrackFundingDetails sets funding rates to a position
|
||||
func (p *PositionTracker) TrackFundingDetails(d *fundingrate.Rates) error {
|
||||
func (p *PositionTracker) TrackFundingDetails(d *fundingrate.HistoricalRates) error {
|
||||
if p == nil {
|
||||
return fmt.Errorf("position tracker %w", common.ErrNilPointer)
|
||||
}
|
||||
@@ -715,7 +715,7 @@ func (p *PositionTracker) TrackFundingDetails(d *fundingrate.Rates) error {
|
||||
return fmt.Errorf("%w for timeframe %v %v %v %v-%v", ErrNoPositionsFound, p.exchange, p.asset, p.contractPair, d.StartDate, d.EndDate)
|
||||
}
|
||||
if p.fundingRateDetails == nil {
|
||||
p.fundingRateDetails = &fundingrate.Rates{
|
||||
p.fundingRateDetails = &fundingrate.HistoricalRates{
|
||||
Exchange: d.Exchange,
|
||||
Asset: d.Asset,
|
||||
Pair: d.Pair,
|
||||
|
||||
@@ -541,7 +541,7 @@ func TestGetStats(t *testing.T) {
|
||||
}
|
||||
|
||||
p.exchange = testExchange
|
||||
p.fundingRateDetails = &fundingrate.Rates{
|
||||
p.fundingRateDetails = &fundingrate.HistoricalRates{
|
||||
FundingRates: []fundingrate.Rate{
|
||||
{},
|
||||
},
|
||||
@@ -1274,7 +1274,7 @@ func TestPCTrackFundingDetails(t *testing.T) {
|
||||
}
|
||||
|
||||
p := currency.NewPair(currency.BTC, currency.PERP)
|
||||
rates := &fundingrate.Rates{
|
||||
rates := &fundingrate.HistoricalRates{
|
||||
Asset: asset.Futures,
|
||||
Pair: p,
|
||||
}
|
||||
@@ -1341,7 +1341,7 @@ func TestMPTTrackFundingDetails(t *testing.T) {
|
||||
}
|
||||
|
||||
cp := currency.NewPair(currency.BTC, currency.PERP)
|
||||
rates := &fundingrate.Rates{
|
||||
rates := &fundingrate.HistoricalRates{
|
||||
Asset: asset.Futures,
|
||||
Pair: cp,
|
||||
}
|
||||
@@ -1351,7 +1351,7 @@ func TestMPTTrackFundingDetails(t *testing.T) {
|
||||
}
|
||||
|
||||
mpt.exchange = testExchange
|
||||
rates = &fundingrate.Rates{
|
||||
rates = &fundingrate.HistoricalRates{
|
||||
Exchange: testExchange,
|
||||
Asset: asset.Futures,
|
||||
Pair: cp,
|
||||
@@ -1410,7 +1410,7 @@ func TestPTTrackFundingDetails(t *testing.T) {
|
||||
}
|
||||
|
||||
cp := currency.NewPair(currency.BTC, currency.PERP)
|
||||
rates := &fundingrate.Rates{
|
||||
rates := &fundingrate.HistoricalRates{
|
||||
Exchange: testExchange,
|
||||
Asset: asset.Futures,
|
||||
Pair: cp,
|
||||
|
||||
@@ -156,7 +156,7 @@ type PositionTracker struct {
|
||||
shortPositions []order.Detail
|
||||
longPositions []order.Detail
|
||||
pnlHistory []PNLResult
|
||||
fundingRateDetails *fundingrate.Rates
|
||||
fundingRateDetails *fundingrate.HistoricalRates
|
||||
}
|
||||
|
||||
// PositionTrackerSetup contains all required fields to
|
||||
@@ -264,7 +264,7 @@ type Position struct {
|
||||
CloseDate time.Time
|
||||
Orders []order.Detail
|
||||
PNLHistory []PNLResult
|
||||
FundingRates fundingrate.Rates
|
||||
FundingRates fundingrate.HistoricalRates
|
||||
}
|
||||
|
||||
// PositionSummaryRequest is used to request a summary of an open position
|
||||
@@ -333,7 +333,8 @@ type PositionSummary struct {
|
||||
CollateralMode collateral.Mode
|
||||
// The currency in which the values are quoted against. Isn't always pair.Quote
|
||||
// eg BTC-USDC-230929's quote in GCT is 230929, but the currency should be USDC
|
||||
Currency currency.Code
|
||||
Currency currency.Code
|
||||
StartDate time.Time
|
||||
|
||||
AvailableEquity decimal.Decimal
|
||||
CashBalance decimal.Decimal
|
||||
@@ -345,6 +346,7 @@ type PositionSummary struct {
|
||||
NotionalLeverage decimal.Decimal
|
||||
TotalEquity decimal.Decimal
|
||||
StrategyEquity decimal.Decimal
|
||||
MarginBalance decimal.Decimal
|
||||
|
||||
IsolatedMargin decimal.Decimal
|
||||
NotionalSize decimal.Decimal
|
||||
@@ -359,7 +361,8 @@ type PositionSummary struct {
|
||||
ContractMultiplier decimal.Decimal
|
||||
ContractSettlementType ContractSettlementType
|
||||
AverageOpenPrice decimal.Decimal
|
||||
PositionPNL decimal.Decimal
|
||||
UnrealisedPNL decimal.Decimal
|
||||
RealisedPNL decimal.Decimal
|
||||
MaintenanceMarginFraction decimal.Decimal
|
||||
FreeCollateral decimal.Decimal
|
||||
TotalCollateral decimal.Decimal
|
||||
|
||||
Reference in New Issue
Block a user