Skip to content

Commit

Permalink
Merge pull request #1785 from c9s/edwin/okx/support-broker-id
Browse files Browse the repository at this point in the history
FEATURE: [okx] support broker id
  • Loading branch information
bailantaotao authored Oct 21, 2024
2 parents 5a1249e + b1f86ad commit df37769
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 8 deletions.
24 changes: 21 additions & 3 deletions pkg/exchange/okex/exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,26 +65,40 @@ var log = logrus.WithFields(logrus.Fields{
var ErrSymbolRequired = errors.New("symbol is a required parameter")

type Exchange struct {
key, secret, passphrase string
key, secret, passphrase, brokerId string

client *okexapi.RestClient
timeNowFunc func() time.Time
}

func New(key, secret, passphrase string) *Exchange {
type Option func(exchange *Exchange)

func WithBrokerId(id string) Option {
return func(exchange *Exchange) {
exchange.brokerId = id
}
}

func New(key, secret, passphrase string, opts ...Option) *Exchange {
client := okexapi.NewClient()

if len(key) > 0 && len(secret) > 0 {
client.Auth(key, secret, passphrase)
}

return &Exchange{
ex := &Exchange{
key: key,
secret: secret,
passphrase: passphrase,
client: client,
timeNowFunc: time.Now,
}

for _, o := range opts {
o(ex)
}

return ex
}

func (e *Exchange) Name() types.ExchangeName {
Expand Down Expand Up @@ -263,6 +277,10 @@ func (e *Exchange) SubmitOrder(ctx context.Context, order types.SubmitOrder) (*t
orderReq.ClientOrderID(order.ClientOrderID)
}

if len(e.brokerId) != 0 {
orderReq.Tag(e.brokerId)
}

timeNow := time.Now()
orders, err := orderReq.Do(ctx)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/exchange/okex/okexapi/place_order_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type PlaceOrderRequest struct {
// A combination of case-sensitive alphanumerics, all numbers, or all letters of up to 32 characters.
clientOrderID *string `param:"clOrdId"`

// A combination of case-sensitive alphanumerics, all numbers, or all letters of up to 8 characters.
// A combination of case-sensitive alphanumerics, all numbers, or all letters of up to 16 characters.
tag *string `param:"tag"`

// "buy" or "sell"
Expand Down
22 changes: 18 additions & 4 deletions pkg/exchange/okex/okexapi/place_order_request_requestgen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit df37769

Please sign in to comment.