preupgrade endpoints

This commit is contained in:
wuhewuhe 2023-11-05 23:55:41 +01:00
parent 5486ffc2e8
commit 72d4c9f0af
6 changed files with 258 additions and 0 deletions

View File

@ -248,3 +248,10 @@ func (c *Client) NewPositionService(params map[string]interface{}) *PositionClie
} }
} }
func (c *Client) NewPreUpgradeService(params map[string]interface{}) *PreUpgradeClient {
return &PreUpgradeClient{
c: c,
params: params,
}
}

View File

@ -0,0 +1,22 @@
package main
import (
"context"
"fmt"
bybit "github.com/wuhewuhe/bybit.go.api"
)
func main() {
PlaceTrade()
}
func PlaceTrade() {
client := bybit.NewBybitHttpClient("8wYkmpLsMg10eNQyPm", "Ouxc34myDnXvei54XsBZgoQzfGxO4bkr2Zsj", bybit.WithBaseURL(bybit.TESTNET))
params := map[string]interface{}{"category": "linear", "settleCoin": "USDT", "limit": 10}
orderResult, err := client.NewPositionService(params).GetPositionList(context.Background())
if err != nil {
fmt.Println(err)
return
}
fmt.Println(bybit.PrettyPrint(orderResult))
}

View File

@ -0,0 +1,22 @@
package main
import (
"context"
"fmt"
bybit "github.com/wuhewuhe/bybit.go.api"
)
func main() {
PlaceTrade()
}
func PlaceTrade() {
client := bybit.NewBybitHttpClient("8wYkmpLsMg10eNQyPm", "Ouxc34myDnXvei54XsBZgoQzfGxO4bkr2Zsj", bybit.WithBaseURL(bybit.TESTNET))
params := map[string]interface{}{"category": "linear", "settleCoin": "USDT", "limit": 10}
orderResult, err := client.NewPreUpgradeService(params).GetPreUpgradeOrderHistory(context.Background())
if err != nil {
fmt.Println(err)
return
}
fmt.Println(bybit.PrettyPrint(orderResult))
}

28
models/accountResponse.go Normal file
View File

@ -0,0 +1,28 @@
package models
type TransactionLogInfo struct {
List []TransactionLogEntry `json:"list"`
NextPageCursor string `json:"nextPageCursor"`
}
type TransactionLogEntry struct {
Symbol string `json:"symbol"`
Category string `json:"category"`
Side string `json:"side"`
TransactionTime string `json:"transactionTime"`
Type string `json:"type"`
Qty string `json:"qty"`
Size string `json:"size"`
Currency string `json:"currency"`
TradePrice string `json:"tradePrice"`
Funding string `json:"funding"`
Fee string `json:"fee"`
CashFlow string `json:"cashFlow"`
Change string `json:"change"`
CashBalance string `json:"cashBalance"`
FeeRate string `json:"feeRate"`
BonusChange string `json:"bonusChange"`
TradeID string `json:"tradeId"`
OrderID string `json:"orderId"`
OrderLinkId string `json:"orderLinkId"`
}

34
models/assetResponse.go Normal file
View File

@ -0,0 +1,34 @@
package models
type DeliveryRecordInfo struct {
Category string `json:"category"`
List []DeliveryRecordEntry `json:"list"`
NextPageCursor string `json:"nextPageCursor"`
}
type DeliveryRecordEntry struct {
DeliveryTime int64 `json:"deliveryTime"`
Symbol string `json:"symbol"`
Side string `json:"side"`
Position string `json:"position"`
DeliveryPrice string `json:"deliveryPrice"`
Strike string `json:"strike"`
Fee string `json:"fee"`
DeliveryPnl string `json:"deliveryRpl"`
}
type USDCSettlementInfo struct {
Category string `json:"category"`
List []SettlementEntry `json:"list"`
NextPageCursor string `json:"nextPageCursor"`
}
type SettlementEntry struct {
Symbol string `json:"symbol"`
Side string `json:"side"`
Size string `json:"size"`
SessionAvgPrice string `json:"sessionAvgPrice"`
MarkPrice string `json:"markPrice"`
RealisedPnl string `json:"realisedPnl"`
CreatedTime string `json:"createdTime"`
}

145
pre_upgrade.go Normal file
View File

@ -0,0 +1,145 @@
package bybit_connector
import (
"context"
"encoding/json"
"github.com/wuhewuhe/bybit.go.api/handlers"
"net/http"
)
type PreUpgradeClient struct {
c *Client
params map[string]interface{}
}
func (s *PreUpgradeClient) GetPreUpgradeOrderHistory(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) {
if err = handlers.ValidateParams(s.params); err != nil {
return nil, err
}
r := &request{
method: http.MethodGet,
endpoint: "/v5/pre-upgrade/order/history",
secType: secTypeSigned,
}
r.setParams(s.params)
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
}
res = new(ServerResponse)
err = json.Unmarshal(data, res)
if err != nil {
return nil, err
}
return res, nil
}
func (s *PreUpgradeClient) GetPreUpgradeExecutionList(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) {
if err = handlers.ValidateParams(s.params); err != nil {
return nil, err
}
r := &request{
method: http.MethodGet,
endpoint: "/v5/pre-upgrade/execution/list",
secType: secTypeSigned,
}
r.setParams(s.params)
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
}
res = new(ServerResponse)
err = json.Unmarshal(data, res)
if err != nil {
return nil, err
}
return res, nil
}
func (s *PreUpgradeClient) GetPreUpgradeClosedPnl(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) {
if err = handlers.ValidateParams(s.params); err != nil {
return nil, err
}
r := &request{
method: http.MethodGet,
endpoint: "/v5/pre-upgrade/position/closed-pnl",
secType: secTypeSigned,
}
r.setParams(s.params)
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
}
res = new(ServerResponse)
err = json.Unmarshal(data, res)
if err != nil {
return nil, err
}
return res, nil
}
func (s *PreUpgradeClient) GetPreUpgradeTransactionLog(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) {
if err = handlers.ValidateParams(s.params); err != nil {
return nil, err
}
r := &request{
method: http.MethodGet,
endpoint: "/v5/pre-upgrade/account/transaction-log",
secType: secTypeSigned,
}
r.setParams(s.params)
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
}
res = new(ServerResponse)
err = json.Unmarshal(data, res)
if err != nil {
return nil, err
}
return res, nil
}
func (s *PreUpgradeClient) GetPreUpgradeOptionDeliveryRecord(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) {
if err = handlers.ValidateParams(s.params); err != nil {
return nil, err
}
r := &request{
method: http.MethodGet,
endpoint: "/v5/pre-upgrade/asset/delivery-record",
secType: secTypeSigned,
}
r.setParams(s.params)
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
}
res = new(ServerResponse)
err = json.Unmarshal(data, res)
if err != nil {
return nil, err
}
return res, nil
}
func (s *PreUpgradeClient) GetPreUpgradeUsdcSettlement(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) {
if err = handlers.ValidateParams(s.params); err != nil {
return nil, err
}
r := &request{
method: http.MethodGet,
endpoint: "/v5/pre-upgrade/asset/settlement-record",
secType: secTypeSigned,
}
r.setParams(s.params)
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
}
res = new(ServerResponse)
err = json.Unmarshal(data, res)
if err != nil {
return nil, err
}
return res, nil
}