ftxapi: separate request files

This commit is contained in:
c9s 2022-02-24 10:43:29 +08:00
parent abc425d820
commit cd0ac71b99
4 changed files with 188 additions and 155 deletions

View File

@ -0,0 +1,88 @@
package ftxapi
//go:generate -command GetRequest requestgen -method GET -responseType .APIResponse -responseDataField Result
//go:generate -command PostRequest requestgen -method POST -responseType .APIResponse -responseDataField Result
//go:generate -command DeleteRequest requestgen -method DELETE -responseType .APIResponse -responseDataField Result
import (
"github.com/c9s/requestgen"
"github.com/c9s/bbgo/pkg/fixedpoint"
)
type Position struct {
Cost fixedpoint.Value `json:"cost"`
EntryPrice fixedpoint.Value `json:"entryPrice"`
Future string `json:"future"`
InitialMarginRequirement fixedpoint.Value `json:"initialMarginRequirement"`
LongOrderSize fixedpoint.Value `json:"longOrderSize"`
MaintenanceMarginRequirement fixedpoint.Value `json:"maintenanceMarginRequirement"`
NetSize fixedpoint.Value `json:"netSize"`
OpenSize fixedpoint.Value `json:"openSize"`
ShortOrderSize fixedpoint.Value `json:"shortOrderSize"`
Side string `json:"side"`
Size fixedpoint.Value `json:"size"`
RealizedPnl fixedpoint.Value `json:"realizedPnl"`
UnrealizedPnl fixedpoint.Value `json:"unrealizedPnl"`
}
type Account struct {
BackstopProvider bool `json:"backstopProvider"`
Collateral fixedpoint.Value `json:"collateral"`
FreeCollateral fixedpoint.Value `json:"freeCollateral"`
Leverage fixedpoint.Value `json:"leverage"`
InitialMarginRequirement fixedpoint.Value `json:"initialMarginRequirement"`
MaintenanceMarginRequirement fixedpoint.Value `json:"maintenanceMarginRequirement"`
Liquidating bool `json:"liquidating"`
MakerFee fixedpoint.Value `json:"makerFee"`
MarginFraction fixedpoint.Value `json:"marginFraction"`
OpenMarginFraction fixedpoint.Value `json:"openMarginFraction"`
TakerFee fixedpoint.Value `json:"takerFee"`
TotalAccountValue fixedpoint.Value `json:"totalAccountValue"`
TotalPositionSize fixedpoint.Value `json:"totalPositionSize"`
Username string `json:"username"`
Positions []Position `json:"positions"`
}
//go:generate GetRequest -url "api/account" -type GetAccountRequest -responseDataType .Account
type GetAccountRequest struct {
client requestgen.AuthenticatedAPIClient
}
func (c *RestClient) NewGetAccountRequest() *GetAccountRequest {
return &GetAccountRequest{
client: c,
}
}
//go:generate GetRequest -url "api/positions" -type GetPositionsRequest -responseDataType []Position
type GetPositionsRequest struct {
client requestgen.AuthenticatedAPIClient
}
func (c *RestClient) NewGetPositionsRequest() *GetPositionsRequest {
return &GetPositionsRequest{
client: c,
}
}
type Balance struct {
Coin string `json:"coin"`
Free fixedpoint.Value `json:"free"`
SpotBorrow fixedpoint.Value `json:"spotBorrow"`
Total fixedpoint.Value `json:"total"`
UsdValue fixedpoint.Value `json:"usdValue"`
AvailableWithoutBorrow fixedpoint.Value `json:"availableWithoutBorrow"`
}
//go:generate GetRequest -url "api/balances" -type GetBalancesRequest -responseDataType []Balance
type GetBalancesRequest struct {
client requestgen.AuthenticatedAPIClient
}
func (c *RestClient) NewGetBalancesRequest() *GetBalancesRequest {
return &GetBalancesRequest{
client: c,
}
}

View File

@ -18,8 +18,6 @@ import (
"github.com/c9s/requestgen"
"github.com/pkg/errors"
"github.com/c9s/bbgo/pkg/fixedpoint"
)
const defaultHTTPTimeout = time.Second * 15
@ -203,157 +201,4 @@ func castPayload(payload interface{}) ([]byte, error) {
return nil, nil
}
type Position struct {
Cost fixedpoint.Value `json:"cost"`
EntryPrice fixedpoint.Value `json:"entryPrice"`
Future string `json:"future"`
InitialMarginRequirement fixedpoint.Value `json:"initialMarginRequirement"`
LongOrderSize fixedpoint.Value `json:"longOrderSize"`
MaintenanceMarginRequirement fixedpoint.Value `json:"maintenanceMarginRequirement"`
NetSize fixedpoint.Value `json:"netSize"`
OpenSize fixedpoint.Value `json:"openSize"`
ShortOrderSize fixedpoint.Value `json:"shortOrderSize"`
Side string `json:"side"`
Size fixedpoint.Value `json:"size"`
RealizedPnl fixedpoint.Value `json:"realizedPnl"`
UnrealizedPnl fixedpoint.Value `json:"unrealizedPnl"`
}
type Account struct {
BackstopProvider bool `json:"backstopProvider"`
Collateral fixedpoint.Value `json:"collateral"`
FreeCollateral fixedpoint.Value `json:"freeCollateral"`
Leverage fixedpoint.Value `json:"leverage"`
InitialMarginRequirement fixedpoint.Value `json:"initialMarginRequirement"`
MaintenanceMarginRequirement fixedpoint.Value `json:"maintenanceMarginRequirement"`
Liquidating bool `json:"liquidating"`
MakerFee fixedpoint.Value `json:"makerFee"`
MarginFraction fixedpoint.Value `json:"marginFraction"`
OpenMarginFraction fixedpoint.Value `json:"openMarginFraction"`
TakerFee fixedpoint.Value `json:"takerFee"`
TotalAccountValue fixedpoint.Value `json:"totalAccountValue"`
TotalPositionSize fixedpoint.Value `json:"totalPositionSize"`
Username string `json:"username"`
Positions []Position `json:"positions"`
}
//go:generate GetRequest -url "api/account" -type GetAccountRequest -responseDataType .Account
type GetAccountRequest struct {
client requestgen.AuthenticatedAPIClient
}
func (c *RestClient) NewGetAccountRequest() *GetAccountRequest {
return &GetAccountRequest{
client: c,
}
}
//go:generate GetRequest -url "api/positions" -type GetPositionsRequest -responseDataType []Position
type GetPositionsRequest struct {
client requestgen.AuthenticatedAPIClient
}
func (c *RestClient) NewGetPositionsRequest() *GetPositionsRequest {
return &GetPositionsRequest{
client: c,
}
}
type Market struct {
Name string `json:"name"`
BaseCurrency string `json:"baseCurrency"`
QuoteCurrency string `json:"quoteCurrency"`
QuoteVolume24H fixedpoint.Value `json:"quoteVolume24h"`
Change1H fixedpoint.Value `json:"change1h"`
Change24H fixedpoint.Value `json:"change24h"`
ChangeBod fixedpoint.Value `json:"changeBod"`
VolumeUsd24H fixedpoint.Value `json:"volumeUsd24h"`
HighLeverageFeeExempt bool `json:"highLeverageFeeExempt"`
MinProvideSize fixedpoint.Value `json:"minProvideSize"`
Type string `json:"type"`
Underlying string `json:"underlying"`
Enabled bool `json:"enabled"`
Ask fixedpoint.Value `json:"ask"`
Bid int `json:"bid"`
Last fixedpoint.Value `json:"last"`
PostOnly bool `json:"postOnly"`
Price fixedpoint.Value `json:"price"`
PriceIncrement fixedpoint.Value `json:"priceIncrement"`
SizeIncrement fixedpoint.Value `json:"sizeIncrement"`
Restricted bool `json:"restricted"`
}
//go:generate GetRequest -url "api/markets" -type GetMarketsRequest -responseDataType []Market
type GetMarketsRequest struct {
client requestgen.AuthenticatedAPIClient
}
func (c *RestClient) NewGetMarketsRequest() *GetMarketsRequest {
return &GetMarketsRequest{
client: c,
}
}
//go:generate GetRequest -url "api/markets/:market" -type GetMarketRequest -responseDataType .Market
type GetMarketRequest struct {
client requestgen.AuthenticatedAPIClient
market string `param:"market,slug"`
}
func (c *RestClient) NewGetMarketRequest(market string) *GetMarketRequest {
return &GetMarketRequest{
client: c,
market: market,
}
}
type Coin struct {
Bep2Asset *string `json:"bep2Asset"`
CanConvert bool `json:"canConvert"`
CanDeposit bool `json:"canDeposit"`
CanWithdraw bool `json:"canWithdraw"`
Collateral bool `json:"collateral"`
CollateralWeight fixedpoint.Value `json:"collateralWeight"`
CreditTo *string `json:"creditTo"`
Erc20Contract string `json:"erc20Contract"`
Fiat bool `json:"fiat"`
HasTag bool `json:"hasTag"`
Id string `json:"id"`
IsToken bool `json:"isToken"`
Methods []string `json:"methods"`
Name string `json:"name"`
SplMint string `json:"splMint"`
Trc20Contract string `json:"trc20Contract"`
UsdFungible bool `json:"usdFungible"`
}
//go:generate GetRequest -url "api/coins" -type GetCoinsRequest -responseDataType []Coin
type GetCoinsRequest struct {
client requestgen.AuthenticatedAPIClient
}
func (c *RestClient) NewGetCoinsRequest() *GetCoinsRequest {
return &GetCoinsRequest{
client: c,
}
}
type Balance struct {
Coin string `json:"coin"`
Free fixedpoint.Value `json:"free"`
SpotBorrow fixedpoint.Value `json:"spotBorrow"`
Total fixedpoint.Value `json:"total"`
UsdValue fixedpoint.Value `json:"usdValue"`
AvailableWithoutBorrow fixedpoint.Value `json:"availableWithoutBorrow"`
}
//go:generate GetRequest -url "api/balances" -type GetBalancesRequest -responseDataType []Balance
type GetBalancesRequest struct {
client requestgen.AuthenticatedAPIClient
}
func (c *RestClient) NewGetBalancesRequest() *GetBalancesRequest {
return &GetBalancesRequest{
client: c,
}
}

View File

@ -0,0 +1,42 @@
package ftxapi
//go:generate -command GetRequest requestgen -method GET -responseType .APIResponse -responseDataField Result
//go:generate -command PostRequest requestgen -method POST -responseType .APIResponse -responseDataField Result
//go:generate -command DeleteRequest requestgen -method DELETE -responseType .APIResponse -responseDataField Result
import (
"github.com/c9s/requestgen"
"github.com/c9s/bbgo/pkg/fixedpoint"
)
type Coin struct {
Bep2Asset *string `json:"bep2Asset"`
CanConvert bool `json:"canConvert"`
CanDeposit bool `json:"canDeposit"`
CanWithdraw bool `json:"canWithdraw"`
Collateral bool `json:"collateral"`
CollateralWeight fixedpoint.Value `json:"collateralWeight"`
CreditTo *string `json:"creditTo"`
Erc20Contract string `json:"erc20Contract"`
Fiat bool `json:"fiat"`
HasTag bool `json:"hasTag"`
Id string `json:"id"`
IsToken bool `json:"isToken"`
Methods []string `json:"methods"`
Name string `json:"name"`
SplMint string `json:"splMint"`
Trc20Contract string `json:"trc20Contract"`
UsdFungible bool `json:"usdFungible"`
}
//go:generate GetRequest -url "api/coins" -type GetCoinsRequest -responseDataType []Coin
type GetCoinsRequest struct {
client requestgen.AuthenticatedAPIClient
}
func (c *RestClient) NewGetCoinsRequest() *GetCoinsRequest {
return &GetCoinsRequest{
client: c,
}
}

View File

@ -0,0 +1,58 @@
package ftxapi
//go:generate -command GetRequest requestgen -method GET -responseType .APIResponse -responseDataField Result
//go:generate -command PostRequest requestgen -method POST -responseType .APIResponse -responseDataField Result
//go:generate -command DeleteRequest requestgen -method DELETE -responseType .APIResponse -responseDataField Result
import (
"github.com/c9s/requestgen"
"github.com/c9s/bbgo/pkg/fixedpoint"
)
type Market struct {
Name string `json:"name"`
BaseCurrency string `json:"baseCurrency"`
QuoteCurrency string `json:"quoteCurrency"`
QuoteVolume24H fixedpoint.Value `json:"quoteVolume24h"`
Change1H fixedpoint.Value `json:"change1h"`
Change24H fixedpoint.Value `json:"change24h"`
ChangeBod fixedpoint.Value `json:"changeBod"`
VolumeUsd24H fixedpoint.Value `json:"volumeUsd24h"`
HighLeverageFeeExempt bool `json:"highLeverageFeeExempt"`
MinProvideSize fixedpoint.Value `json:"minProvideSize"`
Type string `json:"type"`
Underlying string `json:"underlying"`
Enabled bool `json:"enabled"`
Ask fixedpoint.Value `json:"ask"`
Bid int `json:"bid"`
Last fixedpoint.Value `json:"last"`
PostOnly bool `json:"postOnly"`
Price fixedpoint.Value `json:"price"`
PriceIncrement fixedpoint.Value `json:"priceIncrement"`
SizeIncrement fixedpoint.Value `json:"sizeIncrement"`
Restricted bool `json:"restricted"`
}
//go:generate GetRequest -url "api/markets" -type GetMarketsRequest -responseDataType []Market
type GetMarketsRequest struct {
client requestgen.AuthenticatedAPIClient
}
func (c *RestClient) NewGetMarketsRequest() *GetMarketsRequest {
return &GetMarketsRequest{
client: c,
}
}
//go:generate GetRequest -url "api/markets/:market" -type GetMarketRequest -responseDataType .Market
type GetMarketRequest struct {
client requestgen.AuthenticatedAPIClient
market string `param:"market,slug"`
}
func (c *RestClient) NewGetMarketRequest(market string) *GetMarketRequest {
return &GetMarketRequest{
client: c,
market: market,
}
}