mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-07 15:11:03 +00:00
futures: add GetFuturesContractDetails wrapper function (#1274)
* all in a days work * cleanup * cleanup for real, also stop it binance.json * minor coverage * adds gateio to the slurry * cleanup of types * verbose verbose verbose verbose verbose verbose * fixes huobi parsing issue * fix bybit contract identification * cleanup * merge fixes * addresses many big problems raised by SHAZ * tracking errors and fixes * funding rate if avail, fixes currency formatting * Addresses nits and sneaks in extra fixes * lint * minor fixes after rebase * better contract splitter for currencies like T-USDT * forgot to add the exchange name like a fool * merge fixes x1 * kucoin, direction, contract size * rn direction, fix kucoin time * WHOOPS * Update exchanges/kucoin/kucoin_wrapper.go Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io> * misdirection --------- Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io>
This commit is contained in:
@@ -14,6 +14,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/account"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/deposit"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/futures"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/kline"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
|
||||
@@ -541,4 +542,9 @@ func ({{.Variable}} *{{.CapitalName}}) GetHistoricCandlesExtended(ctx context.Co
|
||||
return nil, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
// GetFuturesContractDetails returns all contracts from the exchange by asset type
|
||||
func ({{.Variable}} *{{.CapitalName}}) GetFuturesContractDetails(context.Context, asset.Item) ([]futures.Contract, error) {
|
||||
return nil, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
{{end}}
|
||||
|
||||
@@ -26,6 +26,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/collateral"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/deposit"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/fundingrate"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/futures"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/kline"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/margin"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
@@ -916,12 +917,12 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
|
||||
Response: marginRateHistoryResponse,
|
||||
})
|
||||
|
||||
positionSummaryRequest := &order.PositionSummaryRequest{
|
||||
positionSummaryRequest := &futures.PositionSummaryRequest{
|
||||
Asset: assetTypes[i],
|
||||
Pair: p,
|
||||
}
|
||||
var positionSummaryResponse *order.PositionSummary
|
||||
positionSummaryResponse, err = e.GetFuturesPositionSummary(context.TODO(), positionSummaryRequest)
|
||||
var positionSummaryResponse *futures.PositionSummary
|
||||
positionSummaryResponse, err = e.GetPositionSummary(context.TODO(), positionSummaryRequest)
|
||||
msg = ""
|
||||
if err != nil {
|
||||
msg = err.Error()
|
||||
@@ -934,7 +935,7 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
|
||||
Response: jsonifyInterface([]interface{}{positionSummaryResponse}),
|
||||
})
|
||||
|
||||
calculatePNLRequest := &order.PNLCalculatorRequest{
|
||||
calculatePNLRequest := &futures.PNLCalculatorRequest{
|
||||
Pair: p,
|
||||
Underlying: p.Base,
|
||||
Asset: assetTypes[i],
|
||||
@@ -946,7 +947,7 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
|
||||
EntryAmount: decimal.NewFromInt(1337),
|
||||
PreviousPrice: decimal.NewFromInt(1337),
|
||||
}
|
||||
var calculatePNLResponse *order.PNLResult
|
||||
var calculatePNLResponse *futures.PNLResult
|
||||
calculatePNLResponse, err = e.CalculatePNL(context.TODO(), calculatePNLRequest)
|
||||
msg = ""
|
||||
if err != nil {
|
||||
@@ -960,7 +961,7 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
|
||||
Response: jsonifyInterface([]interface{}{calculatePNLResponse}),
|
||||
})
|
||||
|
||||
collateralCalculator := &order.CollateralCalculator{
|
||||
collateralCalculator := &futures.CollateralCalculator{
|
||||
CollateralCurrency: p.Quote,
|
||||
Asset: assetTypes[i],
|
||||
Side: testOrderSide,
|
||||
@@ -983,10 +984,10 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
|
||||
Response: jsonifyInterface([]interface{}{scaleCollateralResponse}),
|
||||
})
|
||||
|
||||
totalCollateralCalculator := &order.TotalCollateralCalculator{
|
||||
CollateralAssets: []order.CollateralCalculator{*collateralCalculator},
|
||||
totalCollateralCalculator := &futures.TotalCollateralCalculator{
|
||||
CollateralAssets: []futures.CollateralCalculator{*collateralCalculator},
|
||||
}
|
||||
var calculateTotalCollateralResponse *order.TotalCollateralResponse
|
||||
var calculateTotalCollateralResponse *futures.TotalCollateralResponse
|
||||
calculateTotalCollateralResponse, err = e.CalculateTotalCollateral(context.TODO(), totalCollateralCalculator)
|
||||
msg = ""
|
||||
if err != nil {
|
||||
@@ -1000,8 +1001,8 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
|
||||
Response: jsonifyInterface([]interface{}{calculateTotalCollateralResponse}),
|
||||
})
|
||||
|
||||
var futuresPositionsResponse []order.PositionResponse
|
||||
futuresPositionsRequest := &order.PositionsRequest{
|
||||
var futuresPositionsResponse []futures.PositionResponse
|
||||
futuresPositionsRequest := &futures.PositionsRequest{
|
||||
Asset: assetTypes[i],
|
||||
Pairs: currency.Pairs{p},
|
||||
StartDate: time.Now().Add(-time.Hour),
|
||||
@@ -1030,14 +1031,14 @@ func jsonifyInterface(params []interface{}) json.RawMessage {
|
||||
}
|
||||
|
||||
func loadConfig() (Config, error) {
|
||||
var config Config
|
||||
var cfg Config
|
||||
keys, err := os.ReadFile("wrapperconfig.json")
|
||||
if err != nil {
|
||||
return config, err
|
||||
return cfg, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal(keys, &config)
|
||||
return config, err
|
||||
err = json.Unmarshal(keys, &cfg)
|
||||
return cfg, err
|
||||
}
|
||||
|
||||
func saveConfig(config *Config) {
|
||||
@@ -1097,17 +1098,20 @@ func outputToHTML(exchangeResponses []ExchangeResponses) {
|
||||
}
|
||||
|
||||
log.Printf("Outputting to: %v", filepath.Join(dir, fmt.Sprintf("%v.html", outputFileName)))
|
||||
file, err := os.Create(filepath.Join(dir, fmt.Sprintf("%v.html", outputFileName)))
|
||||
f, err := os.Create(filepath.Join(dir, fmt.Sprintf("%v.html", outputFileName)))
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
return
|
||||
}
|
||||
|
||||
err = tmpl.Execute(file, exchangeResponses)
|
||||
err = tmpl.Execute(f, exchangeResponses)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
err = f.Close()
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
file.Close()
|
||||
}
|
||||
|
||||
func outputToConsole(exchangeResponses []ExchangeResponses) {
|
||||
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/collateral"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/deposit"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/futures"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/kline"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/margin"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
@@ -278,8 +279,8 @@ var (
|
||||
orderCancelsParam = reflect.TypeOf((*[]order.Cancel)(nil)).Elem()
|
||||
getOrdersRequestParam = reflect.TypeOf((**order.MultiOrderRequest)(nil)).Elem()
|
||||
positionChangeRequestParam = reflect.TypeOf((**margin.PositionChangeRequest)(nil)).Elem()
|
||||
positionSummaryRequestParam = reflect.TypeOf((**order.PositionSummaryRequest)(nil)).Elem()
|
||||
positionsRequestParam = reflect.TypeOf((**order.PositionsRequest)(nil)).Elem()
|
||||
positionSummaryRequestParam = reflect.TypeOf((**futures.PositionSummaryRequest)(nil)).Elem()
|
||||
positionsRequestParam = reflect.TypeOf((**futures.PositionsRequest)(nil)).Elem()
|
||||
)
|
||||
|
||||
// generateMethodArg determines the argument type and returns a pre-made
|
||||
@@ -483,13 +484,13 @@ func generateMethodArg(ctx context.Context, t *testing.T, argGenerator *MethodAr
|
||||
NewAllocatedMargin: 1338,
|
||||
})
|
||||
case argGenerator.MethodInputType.AssignableTo(positionSummaryRequestParam):
|
||||
input = reflect.ValueOf(&order.PositionSummaryRequest{
|
||||
input = reflect.ValueOf(&futures.PositionSummaryRequest{
|
||||
Asset: argGenerator.AssetParams.Asset,
|
||||
Pair: argGenerator.AssetParams.Pair,
|
||||
Direction: order.Buy,
|
||||
})
|
||||
case argGenerator.MethodInputType.AssignableTo(positionsRequestParam):
|
||||
input = reflect.ValueOf(&order.PositionsRequest{
|
||||
input = reflect.ValueOf(&futures.PositionsRequest{
|
||||
Asset: argGenerator.AssetParams.Asset,
|
||||
Pairs: currency.Pairs{argGenerator.AssetParams.Pair},
|
||||
StartDate: argGenerator.Start,
|
||||
@@ -575,6 +576,8 @@ var unsupportedExchangeNames = []string{
|
||||
"bitflyer", // Bitflyer has many "ErrNotYetImplemented, which is true, but not what we care to test for here
|
||||
"bittrex", // the api is about to expire in March, and we haven't updated it yet
|
||||
"itbit", // itbit has no way of retrieving pair data
|
||||
"btse", // TODO rm once timeout issues resolved
|
||||
"poloniex", // outdated API // TODO rm once updated
|
||||
}
|
||||
|
||||
// cryptoChainPerExchange holds the deposit address chain per exchange
|
||||
@@ -598,6 +601,7 @@ var acceptableErrors = []error{
|
||||
context.DeadlineExceeded, // If the context deadline is exceeded, it is not an error as only blockedCIExchanges use expired contexts by design
|
||||
order.ErrPairIsEmpty, // Is thrown when the empty pair and asset scenario for an order submission is sent in the Validate() function
|
||||
deposit.ErrAddressNotFound, // Is thrown when an address is not found due to the exchange requiring valid API keys
|
||||
futures.ErrNotFuturesAsset, // Is thrown when a futures function receives a non-futures asset
|
||||
}
|
||||
|
||||
// warningErrors will t.Log(err) when thrown to diagnose things, but not necessarily suggest
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/common"
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/collateral"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/futures"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/margin"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
"github.com/thrasher-corp/gocryptotrader/gctrpc"
|
||||
@@ -568,7 +569,7 @@ func getManagedPosition(c *cli.Context) error {
|
||||
}
|
||||
}
|
||||
|
||||
err = order.CheckFundingRatePrerequisites(getFundingData, includePredictedRate, includeFundingEntries)
|
||||
err = futures.CheckFundingRatePrerequisites(getFundingData, includePredictedRate, includeFundingEntries)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -646,7 +647,7 @@ func getAllManagedPositions(c *cli.Context) error {
|
||||
}
|
||||
}
|
||||
|
||||
err = order.CheckFundingRatePrerequisites(getFundingData, includePredictedRate, includeFundingEntries)
|
||||
err = futures.CheckFundingRatePrerequisites(getFundingData, includePredictedRate, includeFundingEntries)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/futures"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -29,7 +29,7 @@ func isFuturesAsset(a string) error {
|
||||
return err
|
||||
}
|
||||
if !i.IsFutures() {
|
||||
return fmt.Errorf("%w '%s'", order.ErrNotFuturesAsset, a)
|
||||
return fmt.Errorf("%w '%s'", futures.ErrNotFuturesAsset, a)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user