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

FEATURE: [okx] support broker id #1785

Merged
merged 1 commit into from
Oct 21, 2024
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
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.

Loading