mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-25 16:25:16 +00:00
Merge pull request #1247 from c9s/c9s/max-fee-discounted-restful-api
FEATURE: [max] add fee_discounted to Trade struct for RESTful api
This commit is contained in:
commit
570ccabe46
|
@ -211,6 +211,7 @@ func toGlobalTradeV3(t v3.Trade) ([]types.Trade, error) {
|
||||||
IsMaker: t.IsMaker(),
|
IsMaker: t.IsMaker(),
|
||||||
Fee: t.Fee,
|
Fee: t.Fee,
|
||||||
FeeCurrency: toGlobalCurrency(t.FeeCurrency),
|
FeeCurrency: toGlobalCurrency(t.FeeCurrency),
|
||||||
|
FeeDiscounted: t.FeeDiscounted,
|
||||||
QuoteQuantity: t.Funds,
|
QuoteQuantity: t.Funds,
|
||||||
Time: types.Time(t.CreatedAt),
|
Time: types.Time(t.CreatedAt),
|
||||||
IsMargin: isMargin,
|
IsMargin: isMargin,
|
||||||
|
@ -227,6 +228,7 @@ func toGlobalTradeV3(t v3.Trade) ([]types.Trade, error) {
|
||||||
bidTrade.OrderID = t.SelfTradeBidOrderID
|
bidTrade.OrderID = t.SelfTradeBidOrderID
|
||||||
bidTrade.Fee = t.SelfTradeBidFee
|
bidTrade.Fee = t.SelfTradeBidFee
|
||||||
bidTrade.FeeCurrency = toGlobalCurrency(t.SelfTradeBidFeeCurrency)
|
bidTrade.FeeCurrency = toGlobalCurrency(t.SelfTradeBidFeeCurrency)
|
||||||
|
bidTrade.FeeDiscounted = t.SelfTradeBidFeeDiscounted
|
||||||
bidTrade.IsBuyer = !trade.IsBuyer
|
bidTrade.IsBuyer = !trade.IsBuyer
|
||||||
bidTrade.IsMaker = !trade.IsMaker
|
bidTrade.IsMaker = !trade.IsMaker
|
||||||
trades = append(trades, bidTrade)
|
trades = append(trades, bidTrade)
|
||||||
|
@ -285,9 +287,6 @@ func convertWebSocketTrade(t max.TradeUpdate) (*types.Trade, error) {
|
||||||
// skip trade ID that is the same. however this should not happen
|
// skip trade ID that is the same. however this should not happen
|
||||||
var side = toGlobalSideType(t.Side)
|
var side = toGlobalSideType(t.Side)
|
||||||
|
|
||||||
// trade time
|
|
||||||
mts := time.Unix(0, t.Timestamp*int64(time.Millisecond))
|
|
||||||
|
|
||||||
return &types.Trade{
|
return &types.Trade{
|
||||||
ID: t.ID,
|
ID: t.ID,
|
||||||
OrderID: t.OrderID,
|
OrderID: t.OrderID,
|
||||||
|
@ -300,8 +299,9 @@ func convertWebSocketTrade(t max.TradeUpdate) (*types.Trade, error) {
|
||||||
IsMaker: t.Maker,
|
IsMaker: t.Maker,
|
||||||
Fee: t.Fee,
|
Fee: t.Fee,
|
||||||
FeeCurrency: toGlobalCurrency(t.FeeCurrency),
|
FeeCurrency: toGlobalCurrency(t.FeeCurrency),
|
||||||
|
FeeDiscounted: t.FeeDiscounted,
|
||||||
QuoteQuantity: t.Price.Mul(t.Volume),
|
QuoteQuantity: t.Price.Mul(t.Volume),
|
||||||
Time: types.Time(mts),
|
Time: types.Time(t.Timestamp.Time()),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -104,8 +104,8 @@ type TradeUpdate struct {
|
||||||
FeeCurrency string `json:"fc"`
|
FeeCurrency string `json:"fc"`
|
||||||
FeeDiscounted bool `json:"fd"`
|
FeeDiscounted bool `json:"fd"`
|
||||||
|
|
||||||
Timestamp int64 `json:"T"`
|
Timestamp types.MillisecondTimestamp `json:"T"`
|
||||||
UpdateTime int64 `json:"TU"`
|
UpdateTime types.MillisecondTimestamp `json:"TU"`
|
||||||
|
|
||||||
OrderID uint64 `json:"oi"`
|
OrderID uint64 `json:"oi"`
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ func Test_parseTradeSnapshotEvent(t *testing.T) {
|
||||||
assert.Equal(t, 1, len(evt.Trades))
|
assert.Equal(t, 1, len(evt.Trades))
|
||||||
assert.Equal(t, "bid", evt.Trades[0].Side)
|
assert.Equal(t, "bid", evt.Trades[0].Side)
|
||||||
assert.Equal(t, "ethtwd", evt.Trades[0].Market)
|
assert.Equal(t, "ethtwd", evt.Trades[0].Market)
|
||||||
assert.Equal(t, int64(1521726960357), evt.Trades[0].Timestamp)
|
assert.Equal(t, int64(1521726960357), evt.Trades[0].Timestamp.Time().UnixMilli())
|
||||||
assert.Equal(t, "3.2", evt.Trades[0].Fee.String())
|
assert.Equal(t, "3.2", evt.Trades[0].Fee.String())
|
||||||
assert.Equal(t, "twd", evt.Trades[0].FeeCurrency)
|
assert.Equal(t, "twd", evt.Trades[0].FeeCurrency)
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/c9s/bbgo/pkg/exchange/max/maxapi"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"reflect"
|
"reflect"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
@ -39,7 +38,7 @@ func (g *GetWalletTradesRequest) Limit(limit uint64) *GetWalletTradesRequest {
|
||||||
return g
|
return g
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GetWalletTradesRequest) WalletType(walletType max.WalletType) *GetWalletTradesRequest {
|
func (g *GetWalletTradesRequest) WalletType(walletType WalletType) *GetWalletTradesRequest {
|
||||||
g.walletType = walletType
|
g.walletType = walletType
|
||||||
return g
|
return g
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,23 +5,32 @@ import (
|
||||||
"github.com/c9s/bbgo/pkg/types"
|
"github.com/c9s/bbgo/pkg/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Liquidity string
|
||||||
|
|
||||||
|
const (
|
||||||
|
LiquidityMaker = "maker"
|
||||||
|
LiquidityTaker = "taker"
|
||||||
|
)
|
||||||
|
|
||||||
type Trade struct {
|
type Trade struct {
|
||||||
ID uint64 `json:"id" db:"exchange_id"`
|
ID uint64 `json:"id" db:"exchange_id"`
|
||||||
WalletType WalletType `json:"wallet_type,omitempty"`
|
WalletType WalletType `json:"wallet_type,omitempty"`
|
||||||
Price fixedpoint.Value `json:"price"`
|
Price fixedpoint.Value `json:"price"`
|
||||||
Volume fixedpoint.Value `json:"volume"`
|
Volume fixedpoint.Value `json:"volume"`
|
||||||
Funds fixedpoint.Value `json:"funds"`
|
Funds fixedpoint.Value `json:"funds"`
|
||||||
Market string `json:"market"`
|
Market string `json:"market"`
|
||||||
MarketName string `json:"market_name"`
|
MarketName string `json:"market_name"`
|
||||||
CreatedAt types.MillisecondTimestamp `json:"created_at"`
|
CreatedAt types.MillisecondTimestamp `json:"created_at"`
|
||||||
Side string `json:"side"`
|
Side string `json:"side"`
|
||||||
OrderID uint64 `json:"order_id"`
|
OrderID uint64 `json:"order_id"`
|
||||||
Fee fixedpoint.Value `json:"fee"` // float number as string
|
Fee fixedpoint.Value `json:"fee"` // float number as string
|
||||||
FeeCurrency string `json:"fee_currency"`
|
FeeCurrency string `json:"fee_currency"`
|
||||||
Liquidity string `json:"liquidity"`
|
FeeDiscounted bool `json:"fee_discounted"`
|
||||||
SelfTradeBidFee fixedpoint.Value `json:"self_trade_bid_fee"`
|
Liquidity Liquidity `json:"liquidity"`
|
||||||
SelfTradeBidFeeCurrency string `json:"self_trade_bid_fee_currency"`
|
SelfTradeBidFee fixedpoint.Value `json:"self_trade_bid_fee"`
|
||||||
SelfTradeBidOrderID uint64 `json:"self_trade_bid_order_id"`
|
SelfTradeBidFeeCurrency string `json:"self_trade_bid_fee_currency"`
|
||||||
|
SelfTradeBidFeeDiscounted bool `json:"self_trade_bid_fee_discounted"`
|
||||||
|
SelfTradeBidOrderID uint64 `json:"self_trade_bid_order_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t Trade) IsBuyer() bool {
|
func (t Trade) IsBuyer() bool {
|
||||||
|
|
|
@ -40,7 +40,7 @@ func placeholdersOf(record interface{}) []string {
|
||||||
for i := 0; i < rt.NumField(); i++ {
|
for i := 0; i < rt.NumField(); i++ {
|
||||||
fieldType := rt.Field(i)
|
fieldType := rt.Field(i)
|
||||||
if tag, ok := fieldType.Tag.Lookup("db"); ok {
|
if tag, ok := fieldType.Tag.Lookup("db"); ok {
|
||||||
if tag == "gid" {
|
if tag == "gid" || tag == "-" || tag == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ func fieldsNamesOf(record interface{}) []string {
|
||||||
for i := 0; i < rt.NumField(); i++ {
|
for i := 0; i < rt.NumField(); i++ {
|
||||||
fieldType := rt.Field(i)
|
fieldType := rt.Field(i)
|
||||||
if tag, ok := fieldType.Tag.Lookup("db"); ok {
|
if tag, ok := fieldType.Tag.Lookup("db"); ok {
|
||||||
if tag == "gid" {
|
if tag == "gid" || tag == "-" || tag == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -67,6 +67,12 @@ type Trade struct {
|
||||||
Fee fixedpoint.Value `json:"fee" db:"fee"`
|
Fee fixedpoint.Value `json:"fee" db:"fee"`
|
||||||
FeeCurrency string `json:"feeCurrency" db:"fee_currency"`
|
FeeCurrency string `json:"feeCurrency" db:"fee_currency"`
|
||||||
|
|
||||||
|
// FeeDiscounted is an optional field which indicates whether the trade is using the platform fee token for discount.
|
||||||
|
// When FeeDiscounted = true, means the fee is deducted outside the trade
|
||||||
|
// By default, it's set to false.
|
||||||
|
// This is only used by the MAX exchange
|
||||||
|
FeeDiscounted bool `json:"feeDiscounted" db:"-"`
|
||||||
|
|
||||||
IsMargin bool `json:"isMargin" db:"is_margin"`
|
IsMargin bool `json:"isMargin" db:"is_margin"`
|
||||||
IsFutures bool `json:"isFutures" db:"is_futures"`
|
IsFutures bool `json:"isFutures" db:"is_futures"`
|
||||||
IsIsolated bool `json:"isIsolated" db:"is_isolated"`
|
IsIsolated bool `json:"isIsolated" db:"is_isolated"`
|
||||||
|
|
Loading…
Reference in New Issue
Block a user