Skip to content

Commit

Permalink
Merge pull request #871 from c9s/improvements/maxapi
Browse files Browse the repository at this point in the history
improve: improve maxapi, add v2 order api back
  • Loading branch information
c9s committed Aug 10, 2022
2 parents 3bdc6c7 + e735362 commit d31b812
Show file tree
Hide file tree
Showing 18 changed files with 750 additions and 39 deletions.
14 changes: 14 additions & 0 deletions pkg/cmd/kline.go
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"syscall"
"time"

log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -54,6 +55,19 @@ var klineCmd = &cobra.Command{
return err
}

now := time.Now()
kLines, err := session.Exchange.QueryKLines(ctx, symbol, types.Interval(interval), types.KLineQueryOptions{
Limit: 50,
EndTime: &now,
})
if err != nil {
return err
}
log.Infof("kLines from RESTful API")
for _, k := range kLines {
log.Info(k.String())
}

s := session.Exchange.NewStream()
s.SetPublicOnly()
s.Subscribe(types.KLineChannel, symbol, types.SubscribeOptions{Interval: types.Interval(interval)})
Expand Down
2 changes: 1 addition & 1 deletion pkg/exchange/max/exchange.go
Expand Up @@ -515,7 +515,7 @@ func (e *Exchange) SubmitOrders(ctx context.Context, orders ...types.SubmitOrder
req.Market(toLocalSymbol(o.Symbol)).
Side(toLocalSideType(o.Side)).
Volume(quantityString).
OrderType(string(orderType)).
OrderType(orderType).
ClientOrderID(clientOrderID)

switch o.Type {
Expand Down
2 changes: 1 addition & 1 deletion pkg/exchange/max/maxapi/account.go
Expand Up @@ -11,7 +11,7 @@ import (
)

type AccountService struct {
client *RestClient
client requestgen.AuthenticatedAPIClient
}

// Account is for max rest api v2, Balance and Type will be conflict with types.PrivateBalanceUpdate
Expand Down
19 changes: 19 additions & 0 deletions pkg/exchange/max/maxapi/cancel_order_request.go
@@ -0,0 +1,19 @@
package max

//go:generate -command GetRequest requestgen -method GET
//go:generate -command PostRequest requestgen -method POST
//go:generate -command DeleteRequest requestgen -method DELETE

import "github.com/c9s/requestgen"

func (s *OrderService) NewCancelOrderRequest() *CancelOrderRequest {
return &CancelOrderRequest{client: s.client}
}

//go:generate PostRequest -url "/api/v2/order/delete" -type CancelOrderRequest -responseType .Order
type CancelOrderRequest struct {
client requestgen.AuthenticatedAPIClient

id *uint64 `param:"id,omitempty"`
clientOrderID *string `param:"client_oid,omitempty"`
}
163 changes: 163 additions & 0 deletions pkg/exchange/max/maxapi/cancel_order_request_requestgen.go

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

26 changes: 26 additions & 0 deletions pkg/exchange/max/maxapi/create_order_request.go
@@ -0,0 +1,26 @@
package max

import "github.com/c9s/requestgen"

//go:generate -command GetRequest requestgen -method GET
//go:generate -command PostRequest requestgen -method POST
//go:generate -command DeleteRequest requestgen -method DELETE

//go:generate PostRequest -url "/api/v2/orders" -type CreateOrderRequest -responseType .Order
type CreateOrderRequest struct {
client requestgen.AuthenticatedAPIClient

market string `param:"market,required"`
side string `param:"side,required"`
volume string `param:"volume,required"`
orderType OrderType `param:"ord_type"`

price *string `param:"price"`
stopPrice *string `param:"stop_price"`
clientOrderID *string `param:"client_oid"`
groupID *string `param:"group_id"`
}

func (s *OrderService) NewCreateOrderRequest() *CreateOrderRequest {
return &CreateOrderRequest{client: s.client}
}

0 comments on commit d31b812

Please sign in to comment.