Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REFACTOR: refactor strint #1898

Merged
merged 3 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pkg/exchange/bitget/bitgetapi/v2/cancel_order_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ package bitgetapi
import (
"github.com/c9s/requestgen"

"github.com/c9s/bbgo/pkg/types"
"github.com/c9s/bbgo/pkg/types/strint"
)

type CancelOrder struct {
// OrderId are always numeric. It's confirmed with official customer service. https://t.me/bitgetOpenapi/24172
OrderId types.StrInt64 `json:"orderId"`
ClientOrderId string `json:"clientOid"`
OrderId strint.Int64 `json:"orderId"`
ClientOrderId string `json:"clientOid"`
}

//go:generate PostRequest -url "/api/v2/spot/trade/cancel-order" -type CancelOrderRequest -responseDataType .CancelOrder
Expand Down
10 changes: 6 additions & 4 deletions pkg/exchange/bitget/bitgetapi/v2/get_history_orders_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (

"github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/c9s/bbgo/pkg/types"
"github.com/c9s/bbgo/pkg/types/strint"

"github.com/c9s/requestgen"
)

Expand All @@ -22,7 +24,7 @@ type FeeDetail struct {
// Amount deducted in BGB (Bitget Coin), unit:BGB
DeductedInBGB fixedpoint.Value `json:"d"`
// If the BGB balance is insufficient to cover the fees, the remaining amount is deducted from the
//currency obtained from the transaction.
// currency obtained from the transaction.
DeductedFromCurrency fixedpoint.Value `json:"r"`
// The total fee amount to be paid, unit :currency obtained from the transaction.
ToBePaid fixedpoint.Value `json:"t"`
Expand All @@ -34,10 +36,10 @@ type FeeDetail struct {
}

type OrderDetail struct {
UserId types.StrInt64 `json:"userId"`
Symbol string `json:"symbol"`
UserId strint.Int64 `json:"userId"`
Symbol string `json:"symbol"`
// OrderId are always numeric. It's confirmed with official customer service. https://t.me/bitgetOpenapi/24172
OrderId types.StrInt64 `json:"orderId"`
OrderId strint.Int64 `json:"orderId"`
ClientOrderId string `json:"clientOid"`
Price fixedpoint.Value `json:"price"`
// Size is base coin when orderType=limit; quote coin when orderType=market
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/c9s/bbgo/pkg/types"
"github.com/c9s/bbgo/pkg/types/strint"
)

func TestOrderDetail_UnmarshalJSON(t *testing.T) {
Expand Down Expand Up @@ -38,9 +39,9 @@ func TestOrderDetail_UnmarshalJSON(t *testing.T) {
err := json.Unmarshal([]byte(input), &od)
assert.NoError(err)
assert.Equal(OrderDetail{
UserId: types.StrInt64(8672173294),
UserId: strint.Int64(8672173294),
Symbol: "APEUSDT",
OrderId: types.StrInt64(1104342023170068480),
OrderId: strint.Int64(1104342023170068480),
ClientOrderId: "f3d6a1ee-4e94-48b5-a6e0-25f3e93d92e1",
Price: fixedpoint.NewFromFloat(1.2),
Size: fixedpoint.NewFromFloat(5),
Expand Down Expand Up @@ -83,9 +84,9 @@ func TestOrderDetail_UnmarshalJSON(t *testing.T) {
err := json.Unmarshal([]byte(input), &od)
assert.NoError(err)
assert.Equal(OrderDetail{
UserId: types.StrInt64(8672173294),
UserId: strint.Int64(8672173294),
Symbol: "APEUSDT",
OrderId: types.StrInt64(1104337778433757184),
OrderId: strint.Int64(1104337778433757184),
ClientOrderId: "8afea7bd-d873-44fe-aff8-6a1fae3cc765",
Price: fixedpoint.NewFromFloat(1.4),
Size: fixedpoint.NewFromFloat(5),
Expand Down
7 changes: 4 additions & 3 deletions pkg/exchange/bitget/bitgetapi/v2/get_trade_fills.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/c9s/bbgo/pkg/types"
"github.com/c9s/bbgo/pkg/types/strint"
)

//go:generate -command GetRequest requestgen -method GET -responseType .APIResponse -responseDataField Data
Expand Down Expand Up @@ -38,10 +39,10 @@ type TradeFee struct {
}

type Trade struct {
UserId types.StrInt64 `json:"userId"`
UserId strint.Int64 `json:"userId"`
Symbol string `json:"symbol"`
OrderId types.StrInt64 `json:"orderId"`
TradeId types.StrInt64 `json:"tradeId"`
OrderId strint.Int64 `json:"orderId"`
TradeId strint.Int64 `json:"tradeId"`
OrderType OrderType `json:"orderType"`
Side SideType `json:"side"`
PriceAvg fixedpoint.Value `json:"priceAvg"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ import (

"github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/c9s/bbgo/pkg/types"
"github.com/c9s/bbgo/pkg/types/strint"
)

type UnfilledOrder struct {
UserId types.StrInt64 `json:"userId"`
Symbol string `json:"symbol"`
UserId strint.Int64 `json:"userId"`
Symbol string `json:"symbol"`
// OrderId are always numeric. It's confirmed with official customer service. https://t.me/bitgetOpenapi/24172
OrderId types.StrInt64 `json:"orderId"`
OrderId strint.Int64 `json:"orderId"`
ClientOrderId string `json:"clientOid"`
PriceAvg fixedpoint.Value `json:"priceAvg"`
// Size is base coin when orderType=limit; quote coin when orderType=market
Expand Down
19 changes: 10 additions & 9 deletions pkg/exchange/bitget/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
v2 "github.com/c9s/bbgo/pkg/exchange/bitget/bitgetapi/v2"
"github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/c9s/bbgo/pkg/types"
"github.com/c9s/bbgo/pkg/types/strint"
)

func Test_toGlobalBalance(t *testing.T) {
Expand Down Expand Up @@ -210,7 +211,7 @@ func Test_unfilledOrderToGlobalOrder(t *testing.T) {
orderId = 1105087175647989764
unfilledOrder = v2.UnfilledOrder{
Symbol: "BTCUSDT",
OrderId: types.StrInt64(orderId),
OrderId: strint.Int64(orderId),
ClientOrderId: "74b86af3-6098-479c-acac-bfb074c067f3",
PriceAvg: fixedpoint.NewFromFloat(1.2),
Size: fixedpoint.NewFromFloat(5),
Expand Down Expand Up @@ -344,7 +345,7 @@ func Test_toGlobalOrder(t *testing.T) {
unfilledOrder = v2.OrderDetail{
UserId: 123456,
Symbol: "BTCUSDT",
OrderId: types.StrInt64(orderId),
OrderId: strint.Int64(orderId),
ClientOrderId: "74b86af3-6098-479c-acac-bfb074c067f3",
Price: fixedpoint.NewFromFloat(1.2),
Size: fixedpoint.NewFromFloat(5),
Expand Down Expand Up @@ -604,10 +605,10 @@ func Test_toGlobalTrade(t *testing.T) {
// "uTime":"1699020564687"
// }
trade := v2.Trade{
UserId: types.StrInt64(8672173294),
UserId: strint.Int64(8672173294),
Symbol: "APEUSDT",
OrderId: types.StrInt64(1104337778433757184),
TradeId: types.StrInt64(1104337778504044545),
OrderId: strint.Int64(1104337778433757184),
TradeId: strint.Int64(1104337778504044545),
OrderType: v2.OrderTypeLimit,
Side: v2.SideTypeSell,
PriceAvg: fixedpoint.NewFromFloat(1.4001),
Expand Down Expand Up @@ -816,15 +817,15 @@ func TestOrder_toGlobalOrder(t *testing.T) {
o := Order{
Trade: Trade{
FillPrice: fixedpoint.NewFromFloat(0.49016),
TradeId: types.StrInt64(1107950490073112582),
TradeId: strint.Int64(1107950490073112582),
BaseVolume: fixedpoint.NewFromFloat(33.6558),
FillTime: types.NewMillisecondTimestampFromInt(1699881902235),
FillFee: fixedpoint.NewFromFloat(-0.0336558),
FillFeeCoin: "BGB",
TradeScope: "T",
},
InstId: "BGBUSDT",
OrderId: types.StrInt64(1107950489998626816),
OrderId: strint.Int64(1107950489998626816),
ClientOrderId: "cc73aab9-1e44-4022-8458-60d8c6a08753",
NewSize: fixedpoint.NewFromFloat(39.0),
Notional: fixedpoint.NewFromFloat(39.0),
Expand Down Expand Up @@ -1133,15 +1134,15 @@ func TestOrder_toGlobalTrade(t *testing.T) {
o := Order{
Trade: Trade{
FillPrice: fixedpoint.NewFromFloat(0.49016),
TradeId: types.StrInt64(1107950490073112582),
TradeId: strint.Int64(1107950490073112582),
BaseVolume: fixedpoint.NewFromFloat(33.6558),
FillTime: types.NewMillisecondTimestampFromInt(1699881902235),
FillFee: fixedpoint.NewFromFloat(-0.0336558),
FillFeeCoin: "BGB",
TradeScope: "T",
},
InstId: "BGBUSDT",
OrderId: types.StrInt64(1107950489998626816),
OrderId: strint.Int64(1107950489998626816),
ClientOrderId: "cc73aab9-1e44-4022-8458-60d8c6a08753",
NewSize: fixedpoint.NewFromFloat(39.0),
Notional: fixedpoint.NewFromFloat(39.0),
Expand Down
3 changes: 2 additions & 1 deletion pkg/exchange/bitget/exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
v2 "github.com/c9s/bbgo/pkg/exchange/bitget/bitgetapi/v2"
"github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/c9s/bbgo/pkg/types"
"github.com/c9s/bbgo/pkg/types/strint"
)

const (
Expand Down Expand Up @@ -376,7 +377,7 @@ func (e *Exchange) SubmitOrder(ctx context.Context, order types.SubmitOrder) (cr
}

func (e *Exchange) QueryOpenOrders(ctx context.Context, symbol string) (orders []types.Order, err error) {
var nextCursor types.StrInt64
var nextCursor strint.Int64
for {
if err := queryOpenOrdersRateLimiter.Wait(ctx); err != nil {
return nil, fmt.Errorf("open order rate limiter wait error: %w", err)
Expand Down
9 changes: 5 additions & 4 deletions pkg/exchange/bitget/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
v2 "github.com/c9s/bbgo/pkg/exchange/bitget/bitgetapi/v2"
"github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/c9s/bbgo/pkg/types"
"github.com/c9s/bbgo/pkg/types/strint"
)

type InstType string
Expand Down Expand Up @@ -194,7 +195,7 @@ type MarketTrade struct {
Price fixedpoint.Value
Size fixedpoint.Value
Side SideType
TradeId types.StrInt64
TradeId strint.Int64
}

type MarketTradeSlice []MarketTrade
Expand Down Expand Up @@ -430,7 +431,7 @@ type AccountEvent struct {
type Trade struct {
// Latest filled price
FillPrice fixedpoint.Value `json:"fillPrice"`
TradeId types.StrInt64 `json:"tradeId"`
TradeId strint.Int64 `json:"tradeId"`
// Number of latest filled orders
BaseVolume fixedpoint.Value `json:"baseVolume"`
FillTime types.MillisecondTimestamp `json:"fillTime"`
Expand All @@ -447,8 +448,8 @@ type Order struct {

InstId string `json:"instId"`
// OrderId are always numeric. It's confirmed with official customer service. https://t.me/bitgetOpenapi/24172
OrderId types.StrInt64 `json:"orderId"`
ClientOrderId string `json:"clientOid"`
OrderId strint.Int64 `json:"orderId"`
ClientOrderId string `json:"clientOid"`
// NewSize represents the order quantity, following the specified rules:
// when orderType=limit, newSize represents the quantity of base coin,
// when orderType=marketandside=buy, newSize represents the quantity of quote coin,
Expand Down
3 changes: 2 additions & 1 deletion pkg/exchange/okex/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/c9s/bbgo/pkg/exchange/okex/okexapi"
"github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/c9s/bbgo/pkg/types"
"github.com/c9s/bbgo/pkg/types/strint"
)

func Test_orderDetailToGlobal(t *testing.T) {
Expand All @@ -30,7 +31,7 @@ func Test_orderDetailToGlobal(t *testing.T) {
FillTime: types.NewMillisecondTimestampFromInt(0),
InstrumentID: "BTC-USDT",
InstrumentType: okexapi.InstrumentTypeSpot,
OrderId: types.StrInt64(orderId),
OrderId: strint.Int64(orderId),
OrderType: okexapi.OrderTypeLimit,
Price: fixedpoint.NewFromFloat(48174.5),
Side: okexapi.SideTypeBuy,
Expand Down
6 changes: 3 additions & 3 deletions pkg/exchange/okex/okexapi/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/pkg/errors"

"github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/c9s/bbgo/pkg/types"
"github.com/c9s/bbgo/pkg/types/strint"
)

const defaultHTTPTimeout = time.Second * 15
Expand Down Expand Up @@ -216,10 +216,10 @@ type APIResponse struct {
Data json.RawMessage `json:"data"`

// InTime is the timestamp at REST gateway when the request is received, Unix timestamp format in microseconds, e.g. 1597026383085123
InTime types.StrInt64 `json:"inTime"`
InTime strint.Int64 `json:"inTime"`

// OutTime is the timestamp at REST gateway when the response is sent, Unix timestamp format in microseconds, e.g. 1597026383085123
OutTime types.StrInt64 `json:"outTime"`
OutTime strint.Int64 `json:"outTime"`
}

func (a APIResponse) Validate() error {
Expand Down
54 changes: 27 additions & 27 deletions pkg/exchange/okex/okexapi/get_account_config_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,42 @@ package okexapi
import (
"github.com/c9s/requestgen"

"github.com/c9s/bbgo/pkg/types"
"github.com/c9s/bbgo/pkg/types/strint"
)

//go:generate -command GetRequest requestgen -method GET -responseType .APIResponse -responseDataField Data
//go:generate -command PostRequest requestgen -method POST -responseType .APIResponse -responseDataField Data

type AccountConfig struct {
AccountLevel types.StrInt64 `json:"acctLv"`
AccountLevel strint.Int64 `json:"acctLv"`

AccountSelfTradePreventionMode string `json:"acctStpMode"`

AutoLoan bool `json:"autoLoan"`
ContractIsolationMode string `json:"ctIsoMode"`
EnableSpotBorrow bool `json:"enableSpotBorrow"`
GreeksType string `json:"greeksType"`
Ip string `json:"ip"`
Type string `json:"type"`
KycLv types.StrInt64 `json:"kycLv"`
Label string `json:"label"`
Level string `json:"level"`
LevelTmp string `json:"levelTmp"`

LiquidationGear types.StrInt64 `json:"liquidationGear"`

MainUid string `json:"mainUid"`
MarginIsoMode string `json:"mgnIsoMode"`
OpAuth string `json:"opAuth"`
Perm string `json:"perm"`
PosMode string `json:"posMode"`
RoleType types.StrInt64 `json:"roleType"`
SpotBorrowAutoRepay bool `json:"spotBorrowAutoRepay"`
SpotOffsetType string `json:"spotOffsetType"`
SpotRoleType string `json:"spotRoleType"`
SpotTraderInsts []interface{} `json:"spotTraderInsts"`
TraderInsts []interface{} `json:"traderInsts"`
Uid string `json:"uid"`
AutoLoan bool `json:"autoLoan"`
ContractIsolationMode string `json:"ctIsoMode"`
EnableSpotBorrow bool `json:"enableSpotBorrow"`
GreeksType string `json:"greeksType"`
Ip string `json:"ip"`
Type string `json:"type"`
KycLv strint.Int64 `json:"kycLv"`
Label string `json:"label"`
Level string `json:"level"`
LevelTmp string `json:"levelTmp"`

LiquidationGear strint.Int64 `json:"liquidationGear"`

MainUid string `json:"mainUid"`
MarginIsoMode string `json:"mgnIsoMode"`
OpAuth string `json:"opAuth"`
Perm string `json:"perm"`
PosMode string `json:"posMode"`
RoleType strint.Int64 `json:"roleType"`
SpotBorrowAutoRepay bool `json:"spotBorrowAutoRepay"`
SpotOffsetType string `json:"spotOffsetType"`
SpotRoleType string `json:"spotRoleType"`
SpotTraderInsts []interface{} `json:"spotTraderInsts"`
TraderInsts []interface{} `json:"traderInsts"`
Uid string `json:"uid"`
}

//go:generate GetRequest -url "/api/v5/account/config" -type GetAccountConfigRequest -responseDataType []AccountConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,22 @@ import (

"github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/c9s/bbgo/pkg/types"
"github.com/c9s/bbgo/pkg/types/strint"
)

//go:generate -command GetRequest requestgen -method GET -responseType .APIResponse -responseDataField Data
//go:generate -command PostRequest requestgen -method POST -responseType .APIResponse -responseDataField Data

type DepositRecord struct {
ActualDepBlkConfirm types.StrInt64 `json:"actualDepBlkConfirm"`
ActualDepBlkConfirm strint.Int64 `json:"actualDepBlkConfirm"`
Amount fixedpoint.Value `json:"amt"`
AreaCodeFrom string `json:"areaCodeFrom"`
Currency string `json:"ccy"`
Chain string `json:"chain"`
DepId string `json:"depId"`
From string `json:"from"`
FromWdId string `json:"fromWdId"`
State types.StrInt64 `json:"state"`
State strint.Int64 `json:"state"`
To string `json:"to"`

Ts types.MillisecondTimestamp `json:"ts"`
Expand Down
Loading
Loading