move Time type to types.Time

This commit is contained in:
c9s 2021-05-20 01:32:26 +08:00
parent 4fde442722
commit 57a78777df
20 changed files with 57 additions and 78 deletions

View File

@ -9,7 +9,6 @@ import (
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/c9s/bbgo/pkg/datatype"
"github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/c9s/bbgo/pkg/types"
)
@ -237,7 +236,7 @@ func (m *SimplePriceMatching) newTradeFromOrder(order types.Order, isMaker bool)
Side: order.Side,
IsBuyer: order.Side == types.SideTypeBuy,
IsMaker: isMaker,
Time: datatype.Time(m.CurrentTime),
Time: types.Time(m.CurrentTime),
Fee: fee,
FeeCurrency: feeCurrency,
}
@ -439,7 +438,7 @@ func (m *SimplePriceMatching) newOrder(o types.SubmitOrder, orderID uint64) type
Status: types.OrderStatusNew,
ExecutedQuantity: 0,
IsWorking: true,
CreationTime: datatype.Time(m.CurrentTime),
UpdateTime: datatype.Time(m.CurrentTime),
CreationTime: types.Time(m.CurrentTime),
UpdateTime: types.Time(m.CurrentTime),
}
}

View File

@ -8,7 +8,6 @@ import (
"github.com/adshao/go-binance/v2"
"github.com/pkg/errors"
"github.com/c9s/bbgo/pkg/datatype"
"github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/c9s/bbgo/pkg/types"
"github.com/c9s/bbgo/pkg/util"
@ -150,8 +149,8 @@ func ToGlobalOrder(binanceOrder *binance.Order, isMargin bool) (*types.Order, er
OrderID: uint64(binanceOrder.OrderID),
Status: toGlobalOrderStatus(binanceOrder.Status),
ExecutedQuantity: util.MustParseFloat(binanceOrder.ExecutedQuantity),
CreationTime: datatype.Time(millisecondTime(binanceOrder.Time)),
UpdateTime: datatype.Time(millisecondTime(binanceOrder.UpdateTime)),
CreationTime: types.Time(millisecondTime(binanceOrder.Time)),
UpdateTime: types.Time(millisecondTime(binanceOrder.UpdateTime)),
IsMargin: isMargin,
IsIsolated: binanceOrder.IsIsolated,
}, nil
@ -208,7 +207,7 @@ func ToGlobalTrade(t binance.TradeV3, isMargin bool) (*types.Trade, error) {
IsMaker: t.IsMaker,
Fee: fee,
FeeCurrency: t.CommissionAsset,
Time: datatype.Time(millisecondTime(t.Time)),
Time: types.Time(millisecondTime(t.Time)),
IsMargin: isMargin,
IsIsolated: t.IsIsolated,
}, nil

View File

@ -14,7 +14,6 @@ import (
"github.com/sirupsen/logrus"
"github.com/c9s/bbgo/pkg/datatype"
"github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/c9s/bbgo/pkg/types"
"github.com/c9s/bbgo/pkg/util"
@ -283,7 +282,7 @@ func (e *Exchange) QueryWithdrawHistory(ctx context.Context, asset string, since
txIDs[d.TxID] = struct{}{}
allWithdraws = append(allWithdraws, types.Withdraw{
Exchange: types.ExchangeBinance,
ApplyTime: datatype.Time(time.Unix(0, d.ApplyTime*int64(time.Millisecond))),
ApplyTime: types.Time(time.Unix(0, d.ApplyTime*int64(time.Millisecond))),
Asset: d.Asset,
Amount: d.Amount,
Address: d.Address,
@ -356,7 +355,7 @@ func (e *Exchange) QueryDepositHistory(ctx context.Context, asset string, since,
txIDs[d.TxID] = struct{}{}
allDeposits = append(allDeposits, types.Deposit{
Exchange: types.ExchangeBinance,
Time: datatype.Time(time.Unix(0, d.InsertTime*int64(time.Millisecond))),
Time: types.Time(time.Unix(0, d.InsertTime*int64(time.Millisecond))),
Asset: d.Asset,
Amount: d.Amount,
Address: d.Address,

View File

@ -9,7 +9,6 @@ import (
"github.com/adshao/go-binance/v2"
"github.com/valyala/fastjson"
"github.com/c9s/bbgo/pkg/datatype"
"github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/c9s/bbgo/pkg/types"
"github.com/c9s/bbgo/pkg/util"
@ -126,7 +125,7 @@ func (e *ExecutionReportEvent) Order() (*types.Order, error) {
OrderID: uint64(e.OrderID),
Status: toGlobalOrderStatus(binance.OrderStatusType(e.CurrentOrderStatus)),
ExecutedQuantity: util.MustParseFloat(e.CumulativeFilledQuantity),
CreationTime: datatype.Time(orderCreationTime),
CreationTime: types.Time(orderCreationTime),
}, nil
}
@ -147,7 +146,7 @@ func (e *ExecutionReportEvent) Trade() (*types.Trade, error) {
QuoteQuantity: util.MustParseFloat(e.LastQuoteAssetTransactedQuantity),
IsBuyer: e.Side == "BUY",
IsMaker: e.IsMaker,
Time: datatype.Time(tt),
Time: types.Time(tt),
Fee: util.MustParseFloat(e.CommissionAmount),
FeeCurrency: e.CommissionAsset,
}, nil

View File

@ -7,7 +7,6 @@ import (
log "github.com/sirupsen/logrus"
"github.com/c9s/bbgo/pkg/datatype"
"github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/c9s/bbgo/pkg/types"
)
@ -52,8 +51,8 @@ func toGlobalOrder(r order) (types.Order, error) {
OrderID: uint64(r.ID),
Status: "",
ExecutedQuantity: r.FilledSize,
CreationTime: datatype.Time(r.CreatedAt.Time),
UpdateTime: datatype.Time(r.CreatedAt.Time),
CreationTime: types.Time(r.CreatedAt.Time),
UpdateTime: types.Time(r.CreatedAt.Time),
}
// `new` (accepted but not processed yet), `open`, or `closed` (filled or cancelled)
@ -93,7 +92,7 @@ func toGlobalDeposit(input depositHistory) (types.Deposit, error) {
d := types.Deposit{
GID: 0,
Exchange: types.ExchangeFTX,
Time: datatype.Time(t.Time),
Time: types.Time(t.Time),
Amount: input.Size,
Asset: toGlobalCurrency(input.Coin),
TransactionID: input.TxID,
@ -126,7 +125,7 @@ func toGlobalTrade(f fill) (types.Trade, error) {
Side: f.Side,
IsBuyer: f.Side == types.SideTypeBuy,
IsMaker: f.Liquidity == "maker",
Time: datatype.Time(f.Time.Time),
Time: types.Time(f.Time.Time),
Fee: f.Fee,
FeeCurrency: f.FeeCurrency,
IsMargin: false,

View File

@ -13,7 +13,6 @@ import (
"github.com/stretchr/testify/assert"
"github.com/c9s/bbgo/pkg/datatype"
"github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/c9s/bbgo/pkg/types"
)
@ -467,7 +466,7 @@ func TestExchange_QueryDepositHistory(t *testing.T) {
assert.Len(t, dh, 1)
assert.Equal(t, types.Deposit{
Exchange: types.ExchangeFTX,
Time: datatype.Time(actualConfirmedTime),
Time: types.Time(actualConfirmedTime),
Amount: 99.0,
Asset: "TUSD",
TransactionID: "0x8078356ae4b06a036d64747546c274af19581f1c78c510b60505798a7ffcaf1",
@ -610,7 +609,7 @@ func TestExchange_QueryTrades(t *testing.T) {
Side: types.SideTypeSell,
IsBuyer: false,
IsMaker: true,
Time: datatype.Time(actualConfirmedTime),
Time: types.Time(actualConfirmedTime),
Fee: -0.0033625,
FeeCurrency: "USD",
IsMargin: false,

View File

@ -6,7 +6,6 @@ import (
"github.com/stretchr/testify/assert"
"github.com/c9s/bbgo/pkg/datatype"
"github.com/c9s/bbgo/pkg/types"
)
@ -55,8 +54,8 @@ func Test_messageHandler_handleMessage(t *testing.T) {
OrderID: 36379,
Status: types.OrderStatusFilled,
ExecutedQuantity: 1.0,
CreationTime: datatype.Time(mustParseDatetime("2021-03-28T06:12:50.991447+00:00")),
UpdateTime: datatype.Time(mustParseDatetime("2021-03-28T06:12:50.991447+00:00")),
CreationTime: types.Time(mustParseDatetime("2021-03-28T06:12:50.991447+00:00")),
UpdateTime: types.Time(mustParseDatetime("2021-03-28T06:12:50.991447+00:00")),
}, order)
})
h.handleMessage(input)
@ -104,7 +103,7 @@ func Test_messageHandler_handleMessage(t *testing.T) {
Side: types.SideTypeBuy,
IsBuyer: true,
IsMaker: false,
Time: datatype.Time(mustParseDatetime("2021-03-28T06:12:34.702926+00:00")),
Time: types.Time(mustParseDatetime("2021-03-28T06:12:34.702926+00:00")),
Fee: 0.00153917575,
FeeCurrency: "USD",
IsMargin: false,

View File

@ -8,7 +8,6 @@ import (
"github.com/pkg/errors"
"github.com/c9s/bbgo/pkg/datatype"
"github.com/c9s/bbgo/pkg/exchange/max/maxapi"
"github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/c9s/bbgo/pkg/types"
@ -201,8 +200,8 @@ func toGlobalOrder(maxOrder max.Order) (*types.Order, error) {
OrderID: maxOrder.ID,
Status: toGlobalOrderStatus(maxOrder.State, executedVolume, remainingVolume),
ExecutedQuantity: executedVolume.Float64(),
CreationTime: datatype.Time(maxOrder.CreatedAt),
UpdateTime: datatype.Time(maxOrder.CreatedAt),
CreationTime: types.Time(maxOrder.CreatedAt),
UpdateTime: types.Time(maxOrder.CreatedAt),
}, nil
}
@ -246,7 +245,7 @@ func toGlobalTrade(t max.Trade) (*types.Trade, error) {
Fee: fee,
FeeCurrency: toGlobalCurrency(t.FeeCurrency),
QuoteQuantity: quoteQuantity,
Time: datatype.Time(mts),
Time: types.Time(mts),
}, nil
}

View File

@ -13,7 +13,6 @@ import (
"github.com/sirupsen/logrus"
"golang.org/x/time/rate"
"github.com/c9s/bbgo/pkg/datatype"
maxapi "github.com/c9s/bbgo/pkg/exchange/max/maxapi"
"github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/c9s/bbgo/pkg/types"
@ -610,7 +609,7 @@ func (e *Exchange) QueryWithdrawHistory(ctx context.Context, asset string, since
txIDs[d.TxID] = struct{}{}
withdraw := types.Withdraw{
Exchange: types.ExchangeMax,
ApplyTime: datatype.Time(time.Unix(d.CreatedAt, 0)),
ApplyTime: types.Time(time.Unix(d.CreatedAt, 0)),
Asset: toGlobalCurrency(d.Currency),
Amount: util.MustParseFloat(d.Amount),
Address: "",
@ -682,7 +681,7 @@ func (e *Exchange) QueryDepositHistory(ctx context.Context, asset string, since,
allDeposits = append(allDeposits, types.Deposit{
Exchange: types.ExchangeMax,
Time: datatype.Time(time.Unix(d.CreatedAt, 0)),
Time: types.Time(time.Unix(d.CreatedAt, 0)),
Amount: util.MustParseFloat(d.Amount),
Asset: toGlobalCurrency(d.Currency),
Address: "", // not supported

View File

@ -6,7 +6,6 @@ import (
"fmt"
"strings"
"github.com/c9s/bbgo/pkg/datatype"
"github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/c9s/bbgo/pkg/types"
)
@ -112,7 +111,7 @@ func (reward Reward) Reward() (*types.Reward, error) {
State: reward.State,
Note: reward.Note,
Spent: false,
CreatedAt: datatype.Time(reward.CreatedAt),
CreatedAt: types.Time(reward.CreatedAt),
}, nil
}

View File

@ -8,7 +8,6 @@ import (
"github.com/gorilla/websocket"
"github.com/c9s/bbgo/pkg/datatype"
max "github.com/c9s/bbgo/pkg/exchange/max/maxapi"
"github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/c9s/bbgo/pkg/types"
@ -226,7 +225,7 @@ func convertWebSocketTrade(t max.TradeUpdate) (*types.Trade, error) {
Fee: fee,
FeeCurrency: toGlobalCurrency(t.FeeCurrency),
QuoteQuantity: quoteQuantity,
Time: datatype.Time(mts),
Time: types.Time(mts),
}, nil
}
@ -257,6 +256,6 @@ func toGlobalOrderUpdate(u max.OrderUpdate) (*types.Order, error) {
OrderID: u.ID,
Status: toGlobalOrderStatus(u.State, executedVolume, remainingVolume),
ExecutedQuantity: executedVolume.Float64(),
CreationTime: datatype.Time(time.Unix(0, u.CreatedAtMs*int64(time.Millisecond))),
CreationTime: types.Time(time.Unix(0, u.CreatedAtMs*int64(time.Millisecond))),
}, nil
}

View File

@ -7,7 +7,6 @@ import (
"github.com/jmoiron/sqlx"
"github.com/stretchr/testify/assert"
"github.com/c9s/bbgo/pkg/datatype"
"github.com/c9s/bbgo/pkg/types"
)
@ -24,7 +23,7 @@ func TestDepositService(t *testing.T) {
err = service.Insert(types.Deposit{
Exchange: types.ExchangeMax,
Time: datatype.Time(time.Now()),
Time: types.Time(time.Now()),
Amount: 0.001,
Asset: "BTC",
Address: "test",

View File

@ -8,7 +8,6 @@ import (
"github.com/jmoiron/sqlx"
"github.com/stretchr/testify/assert"
"github.com/c9s/bbgo/pkg/datatype"
"github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/c9s/bbgo/pkg/types"
)
@ -34,7 +33,7 @@ func TestRewardService_InsertAndQueryUnspent(t *testing.T) {
Quantity: 1,
State: "done",
Spent: false,
CreatedAt: datatype.Time(time.Now()),
CreatedAt: types.Time(time.Now()),
})
assert.NoError(t, err)
@ -52,7 +51,7 @@ func TestRewardService_InsertAndQueryUnspent(t *testing.T) {
Quantity: 1000000,
State: "done",
Spent: false,
CreatedAt: datatype.Time(time.Now()),
CreatedAt: types.Time(time.Now()),
})
assert.NoError(t, err)
@ -99,7 +98,7 @@ func TestRewardService_AggregateUnspentCurrencyPosition(t *testing.T) {
Quantity: 1,
State: "done",
Spent: false,
CreatedAt: datatype.Time(now),
CreatedAt: types.Time(now),
})
assert.NoError(t, err)
@ -111,7 +110,7 @@ func TestRewardService_AggregateUnspentCurrencyPosition(t *testing.T) {
Quantity: 2,
State: "done",
Spent: false,
CreatedAt: datatype.Time(now),
CreatedAt: types.Time(now),
})
assert.NoError(t, err)
@ -123,7 +122,7 @@ func TestRewardService_AggregateUnspentCurrencyPosition(t *testing.T) {
Quantity: 1000000,
State: "done",
Spent: false,
CreatedAt: datatype.Time(now),
CreatedAt: types.Time(now),
})
assert.NoError(t, err)

View File

@ -7,7 +7,6 @@ import (
"github.com/jmoiron/sqlx"
"github.com/stretchr/testify/assert"
"github.com/c9s/bbgo/pkg/datatype"
"github.com/c9s/bbgo/pkg/types"
)
@ -30,7 +29,7 @@ func TestWithdrawService(t *testing.T) {
TransactionID: "01",
TransactionFee: 0.0001,
Network: "omni",
ApplyTime: datatype.Time(time.Now()),
ApplyTime: types.Time(time.Now()),
})
assert.NoError(t, err)

View File

@ -2,8 +2,6 @@ package types
import (
"time"
"github.com/c9s/bbgo/pkg/datatype"
)
type DepositStatus string
@ -26,7 +24,7 @@ const (
type Deposit struct {
GID int64 `json:"gid" db:"gid"`
Exchange ExchangeName `json:"exchange" db:"exchange"`
Time datatype.Time `json:"time" db:"time"`
Time Time `json:"time" db:"time"`
Amount float64 `json:"amount" db:"amount"`
Asset string `json:"asset" db:"asset"`
Address string `json:"address" db:"address"`

View File

@ -9,7 +9,6 @@ import (
"github.com/pkg/errors"
"github.com/slack-go/slack"
"github.com/c9s/bbgo/pkg/datatype"
"github.com/c9s/bbgo/pkg/util"
)
@ -145,14 +144,14 @@ func (o *SubmitOrder) SlackAttachment() slack.Attachment {
type Order struct {
SubmitOrder
Exchange ExchangeName `json:"exchange" db:"exchange"`
GID uint64 `json:"gid" db:"gid"`
OrderID uint64 `json:"orderID" db:"order_id"` // order id
Status OrderStatus `json:"status" db:"status"`
ExecutedQuantity float64 `json:"executedQuantity" db:"executed_quantity"`
IsWorking bool `json:"isWorking" db:"is_working"`
CreationTime datatype.Time `json:"creationTime" db:"created_at"`
UpdateTime datatype.Time `json:"updateTime" db:"updated_at"`
Exchange ExchangeName `json:"exchange" db:"exchange"`
GID uint64 `json:"gid" db:"gid"`
OrderID uint64 `json:"orderID" db:"order_id"` // order id
Status OrderStatus `json:"status" db:"status"`
ExecutedQuantity float64 `json:"executedQuantity" db:"executed_quantity"`
IsWorking bool `json:"isWorking" db:"is_working"`
CreationTime Time `json:"creationTime" db:"created_at"`
UpdateTime Time `json:"updateTime" db:"updated_at"`
IsMargin bool `json:"isMargin" db:"is_margin"`
IsIsolated bool `json:"isIsolated" db:"is_isolated"`

View File

@ -3,7 +3,6 @@ package types
import (
"time"
"github.com/c9s/bbgo/pkg/datatype"
"github.com/c9s/bbgo/pkg/fixedpoint"
)
@ -30,7 +29,7 @@ type Reward struct {
Spent bool `json:"spent" db:"spent"`
// Unix timestamp in seconds
CreatedAt datatype.Time `json:"created_at" db:"created_at"`
CreatedAt Time `json:"created_at" db:"created_at"`
}
type RewardSlice []Reward

View File

@ -1,4 +1,4 @@
package datatype
package types
import (
"database/sql/driver"

View File

@ -9,7 +9,6 @@ import (
"github.com/slack-go/slack"
"github.com/c9s/bbgo/pkg/datatype"
"github.com/c9s/bbgo/pkg/util"
)
@ -59,12 +58,12 @@ type Trade struct {
QuoteQuantity float64 `json:"quoteQuantity" db:"quote_quantity"`
Symbol string `json:"symbol" db:"symbol"`
Side SideType `json:"side" db:"side"`
IsBuyer bool `json:"isBuyer" db:"is_buyer"`
IsMaker bool `json:"isMaker" db:"is_maker"`
Time datatype.Time `json:"tradedAt" db:"traded_at"`
Fee float64 `json:"fee" db:"fee"`
FeeCurrency string `json:"feeCurrency" db:"fee_currency"`
Side SideType `json:"side" db:"side"`
IsBuyer bool `json:"isBuyer" db:"is_buyer"`
IsMaker bool `json:"isMaker" db:"is_maker"`
Time Time `json:"tradedAt" db:"traded_at"`
Fee float64 `json:"fee" db:"fee"`
FeeCurrency string `json:"feeCurrency" db:"fee_currency"`
IsMargin bool `json:"isMargin" db:"is_margin"`
IsIsolated bool `json:"isIsolated" db:"is_isolated"`

View File

@ -3,8 +3,6 @@ package types
import (
"fmt"
"time"
"github.com/c9s/bbgo/pkg/datatype"
)
type Withdraw struct {
@ -16,12 +14,12 @@ type Withdraw struct {
AddressTag string `json:"addressTag"`
Status string `json:"status"`
TransactionID string `json:"transactionID" db:"txn_id"`
TransactionFee float64 `json:"transactionFee" db:"txn_fee"`
TransactionFeeCurrency string `json:"transactionFeeCurrency" db:"txn_fee_currency"`
WithdrawOrderID string `json:"withdrawOrderId"`
ApplyTime datatype.Time `json:"applyTime" db:"time"`
Network string `json:"network" db:"network"`
TransactionID string `json:"transactionID" db:"txn_id"`
TransactionFee float64 `json:"transactionFee" db:"txn_fee"`
TransactionFeeCurrency string `json:"transactionFeeCurrency" db:"txn_fee_currency"`
WithdrawOrderID string `json:"withdrawOrderId"`
ApplyTime Time `json:"applyTime" db:"time"`
Network string `json:"network" db:"network"`
}
func (w Withdraw) String() string {