diff --git a/pkg/exchange/bitget/bitgetapi/v2/cancel_order_request.go b/pkg/exchange/bitget/bitgetapi/v2/cancel_order_request.go index 301212cd59..a3d6f2f523 100644 --- a/pkg/exchange/bitget/bitgetapi/v2/cancel_order_request.go +++ b/pkg/exchange/bitget/bitgetapi/v2/cancel_order_request.go @@ -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 diff --git a/pkg/exchange/bitget/bitgetapi/v2/get_history_orders_request.go b/pkg/exchange/bitget/bitgetapi/v2/get_history_orders_request.go index 478d802e88..146f154383 100644 --- a/pkg/exchange/bitget/bitgetapi/v2/get_history_orders_request.go +++ b/pkg/exchange/bitget/bitgetapi/v2/get_history_orders_request.go @@ -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" ) @@ -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"` @@ -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 diff --git a/pkg/exchange/bitget/bitgetapi/v2/get_history_orders_request_test.go b/pkg/exchange/bitget/bitgetapi/v2/get_history_orders_request_test.go index 2e3cf9600a..69c1b18cf6 100644 --- a/pkg/exchange/bitget/bitgetapi/v2/get_history_orders_request_test.go +++ b/pkg/exchange/bitget/bitgetapi/v2/get_history_orders_request_test.go @@ -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) { @@ -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), @@ -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), diff --git a/pkg/exchange/bitget/bitgetapi/v2/get_trade_fills.go b/pkg/exchange/bitget/bitgetapi/v2/get_trade_fills.go index fb91bbfc1a..3e89d9fa28 100644 --- a/pkg/exchange/bitget/bitgetapi/v2/get_trade_fills.go +++ b/pkg/exchange/bitget/bitgetapi/v2/get_trade_fills.go @@ -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 @@ -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"` diff --git a/pkg/exchange/bitget/bitgetapi/v2/get_unfilled_orders_request.go b/pkg/exchange/bitget/bitgetapi/v2/get_unfilled_orders_request.go index 3bf57ddc62..afe490f265 100644 --- a/pkg/exchange/bitget/bitgetapi/v2/get_unfilled_orders_request.go +++ b/pkg/exchange/bitget/bitgetapi/v2/get_unfilled_orders_request.go @@ -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 diff --git a/pkg/exchange/bitget/convert_test.go b/pkg/exchange/bitget/convert_test.go index 5aac971df0..75618d2853 100644 --- a/pkg/exchange/bitget/convert_test.go +++ b/pkg/exchange/bitget/convert_test.go @@ -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) { @@ -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), @@ -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), @@ -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), @@ -816,7 +817,7 @@ 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), @@ -824,7 +825,7 @@ func TestOrder_toGlobalOrder(t *testing.T) { 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), @@ -1133,7 +1134,7 @@ 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), @@ -1141,7 +1142,7 @@ func TestOrder_toGlobalTrade(t *testing.T) { 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), diff --git a/pkg/exchange/bitget/exchange.go b/pkg/exchange/bitget/exchange.go index 094b88f6a6..70e830ccf5 100644 --- a/pkg/exchange/bitget/exchange.go +++ b/pkg/exchange/bitget/exchange.go @@ -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 ( @@ -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) diff --git a/pkg/exchange/bitget/types.go b/pkg/exchange/bitget/types.go index 3e186e1c8d..94e3ff955d 100644 --- a/pkg/exchange/bitget/types.go +++ b/pkg/exchange/bitget/types.go @@ -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 @@ -194,7 +195,7 @@ type MarketTrade struct { Price fixedpoint.Value Size fixedpoint.Value Side SideType - TradeId types.StrInt64 + TradeId strint.Int64 } type MarketTradeSlice []MarketTrade @@ -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"` @@ -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, diff --git a/pkg/exchange/okex/convert_test.go b/pkg/exchange/okex/convert_test.go index cf47a1b87d..1e8b727872 100644 --- a/pkg/exchange/okex/convert_test.go +++ b/pkg/exchange/okex/convert_test.go @@ -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) { @@ -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, diff --git a/pkg/exchange/okex/okexapi/client.go b/pkg/exchange/okex/okexapi/client.go index 59fcdbb4dd..edb201323a 100644 --- a/pkg/exchange/okex/okexapi/client.go +++ b/pkg/exchange/okex/okexapi/client.go @@ -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 @@ -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 { diff --git a/pkg/exchange/okex/okexapi/get_account_config_request.go b/pkg/exchange/okex/okexapi/get_account_config_request.go index 71d4b10e3a..27025641c0 100644 --- a/pkg/exchange/okex/okexapi/get_account_config_request.go +++ b/pkg/exchange/okex/okexapi/get_account_config_request.go @@ -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 diff --git a/pkg/exchange/okex/okexapi/get_asset_deposit_history_request.go b/pkg/exchange/okex/okexapi/get_asset_deposit_history_request.go index 73a61a970a..611c03e26b 100644 --- a/pkg/exchange/okex/okexapi/get_asset_deposit_history_request.go +++ b/pkg/exchange/okex/okexapi/get_asset_deposit_history_request.go @@ -7,13 +7,14 @@ 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"` @@ -21,7 +22,7 @@ type DepositRecord struct { 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"` diff --git a/pkg/exchange/okex/okexapi/get_order_history_request.go b/pkg/exchange/okex/okexapi/get_order_history_request.go index f215066322..631047811a 100644 --- a/pkg/exchange/okex/okexapi/get_order_history_request.go +++ b/pkg/exchange/okex/okexapi/get_order_history_request.go @@ -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 @@ -24,7 +25,7 @@ type OrderDetail struct { FillTime types.MillisecondTimestamp `json:"fillTime"` InstrumentID string `json:"instId"` InstrumentType InstrumentType `json:"instType"` - OrderId types.StrInt64 `json:"ordId"` + OrderId strint.Int64 `json:"ordId"` OrderType OrderType `json:"ordType"` Price fixedpoint.Value `json:"px"` Side SideType `json:"side"` diff --git a/pkg/exchange/okex/okexapi/get_transaction_history_request.go b/pkg/exchange/okex/okexapi/get_transaction_history_request.go index 71ddfa487d..2a1dd56f40 100644 --- a/pkg/exchange/okex/okexapi/get_transaction_history_request.go +++ b/pkg/exchange/okex/okexapi/get_transaction_history_request.go @@ -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 @@ -15,15 +16,15 @@ import ( type Trade struct { InstrumentType InstrumentType `json:"instType"` InstrumentId string `json:"instId"` - TradeId types.StrInt64 `json:"tradeId"` - OrderId types.StrInt64 `json:"ordId"` + TradeId strint.Int64 `json:"tradeId"` + OrderId strint.Int64 `json:"ordId"` ClientOrderId string `json:"clOrdId"` // Data generation time, Unix timestamp format in milliseconds, e.g. 1597026383085. Timestamp types.MillisecondTimestamp `json:"ts"` FillTime types.MillisecondTimestamp `json:"fillTime"` FeeCurrency string `json:"feeCcy"` Fee fixedpoint.Value `json:"fee"` - BillId types.StrInt64 `json:"billId"` + BillId strint.Int64 `json:"billId"` Side SideType `json:"side"` ExecutionType LiquidityType `json:"execType"` diff --git a/pkg/exchange/okex/okexapi/place_order_request.go b/pkg/exchange/okex/okexapi/place_order_request.go index ad9318d4de..3c3512fcc1 100644 --- a/pkg/exchange/okex/okexapi/place_order_request.go +++ b/pkg/exchange/okex/okexapi/place_order_request.go @@ -3,7 +3,7 @@ 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 @@ -14,9 +14,9 @@ type OrderResponse struct { ClientOrderID string `json:"clOrdId"` Tag string `json:"tag"` - Timestamp types.StrInt64 `json:"ts"` - Code string `json:"sCode"` - Message string `json:"sMsg"` + Timestamp strint.Int64 `json:"ts"` + Code string `json:"sCode"` + Message string `json:"sMsg"` } //go:generate PostRequest -url "/api/v5/trade/order" -type PlaceOrderRequest -responseDataType []OrderResponse diff --git a/pkg/exchange/okex/okexapi/trade.go b/pkg/exchange/okex/okexapi/trade.go index f9440c80bd..9fb35e9985 100644 --- a/pkg/exchange/okex/okexapi/trade.go +++ b/pkg/exchange/okex/okexapi/trade.go @@ -9,6 +9,7 @@ import ( "github.com/c9s/bbgo/pkg/fixedpoint" "github.com/c9s/bbgo/pkg/types" + "github.com/c9s/bbgo/pkg/types/strint" ) func (c *RestClient) NewBatchPlaceOrderRequest() *BatchPlaceOrderRequest { @@ -151,7 +152,7 @@ type OrderDetails struct { LastFilledFee fixedpoint.Value `json:"fillFee"` LastFilledFeeCurrency string `json:"fillFeeCcy"` LastFilledPnl fixedpoint.Value `json:"fillPnl"` - BillID types.StrInt64 `json:"billId"` + BillID strint.Int64 `json:"billId"` // ExecutionType = liquidity (M = maker or T = taker) ExecutionType string `json:"execType"` diff --git a/pkg/exchange/okex/parse.go b/pkg/exchange/okex/parse.go index 44700f58a7..79d7299402 100644 --- a/pkg/exchange/okex/parse.go +++ b/pkg/exchange/okex/parse.go @@ -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" ) type Channel string @@ -318,7 +319,7 @@ func parseAccount(v []byte) (*okexapi.Account, error) { type OrderTradeEvent struct { okexapi.OrderDetail - Code types.StrInt64 `json:"code"` + Code strint.Int64 `json:"code"` Msg string `json:"msg"` AmendResult string `json:"amendResult"` ExecutionType okexapi.LiquidityType `json:"execType"` @@ -400,12 +401,12 @@ func toGlobalSideType(side okexapi.SideType) (types.SideType, error) { type MarketTradeEvent struct { InstId string `json:"instId"` - TradeId types.StrInt64 `json:"tradeId"` + TradeId strint.Int64 `json:"tradeId"` Px fixedpoint.Value `json:"px"` Sz fixedpoint.Value `json:"sz"` Side okexapi.SideType `json:"side"` Timestamp types.MillisecondTimestamp `json:"ts"` - Count types.StrInt64 `json:"count"` + Count strint.Int64 `json:"count"` } func (m *MarketTradeEvent) toGlobalTrade() (types.Trade, error) { diff --git a/pkg/exchange/okex/parse_test.go b/pkg/exchange/okex/parse_test.go index aa41338c5f..eaa7f301e1 100644 --- a/pkg/exchange/okex/parse_test.go +++ b/pkg/exchange/okex/parse_test.go @@ -9,6 +9,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" . "github.com/c9s/bbgo/pkg/testing/testhelper" ) @@ -1000,7 +1001,7 @@ func TestOrderTradeEvent(t *testing.T) { FillTime: types.NewMillisecondTimestampFromInt(1705384184503), InstrumentID: "OKB-USDT", InstrumentType: okexapi.InstrumentTypeSpot, - OrderId: types.StrInt64(667364871905857536), + OrderId: strint.Int64(667364871905857536), OrderType: okexapi.OrderTypeMarket, Price: fixedpoint.Zero, Side: okexapi.SideTypeBuy, @@ -1037,7 +1038,7 @@ func TestOrderTradeEvent(t *testing.T) { AlgoClOrdId: "", AlgoId: "", }, - Code: types.StrInt64(0), + Code: strint.Int64(0), Msg: "", AmendResult: "", ExecutionType: okexapi.LiquidityTypeTaker, diff --git a/pkg/types/strint.go b/pkg/types/strint.go index 8531dad2ea..ab1254f4c2 100644 --- a/pkg/types/strint.go +++ b/pkg/types/strint.go @@ -1,5 +1 @@ package types - -import "github.com/c9s/bbgo/pkg/types/strint" - -type StrInt64 = strint.Int64 diff --git a/pkg/types/strint/int64.go b/pkg/types/strint/int64.go index e59c4c7c9f..ef8cc3da0f 100644 --- a/pkg/types/strint/int64.go +++ b/pkg/types/strint/int64.go @@ -9,7 +9,7 @@ import ( // Int64 is a string type for int64 type Int64 int64 -func NewStrInt64FromString(ss string) (Int64, error) { +func NewFromString(ss string) (Int64, error) { i, err := strconv.ParseInt(ss, 10, 64) if err != nil { return 0, err @@ -27,7 +27,7 @@ func (s *Int64) UnmarshalYAML(unmarshal func(a interface{}) error) (err error) { var ss string if err = unmarshal(&ss); err == nil { - s2, err2 := NewStrInt64FromString(ss) + s2, err2 := NewFromString(ss) if err2 != nil { return err2 } @@ -45,43 +45,50 @@ func (s *Int64) MarshalJSON() ([]byte, error) { } func (s *Int64) UnmarshalJSON(body []byte) error { - var arg interface{} + var arg any if err := json.Unmarshal(body, &arg); err != nil { return err } + val, err := cast(arg) + if err != nil { + return err + } + + *s = Int64(val) + return nil +} + +func (s *Int64) String() string { + if s == nil { + return "" + } + return strconv.FormatInt(int64(*s), 10) +} + +func cast(arg any) (int64, error) { switch ta := arg.(type) { case string: - s2, err := NewStrInt64FromString(ta) + s2, err := strconv.ParseInt(ta, 10, 64) if err != nil { - return err + return 0, err } - *s = Int64(s2) - + return s2, nil case int64: - *s = Int64(ta) + return ta, nil case int32: - *s = Int64(ta) + return int64(ta), nil case int: - *s = Int64(ta) + return int64(ta), nil case float32: - *s = Int64(ta) + return int64(ta), nil case float64: - *s = Int64(ta) + return int64(ta), nil default: - return fmt.Errorf("Int64 error: unsupported value type %T", ta) - } - - return nil -} - -func (s *Int64) String() string { - if s == nil { - return "" + return 0, fmt.Errorf("strint error: unsupported value type %T", ta) } - return strconv.FormatInt(int64(*s), 10) }