mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 00:35:15 +00:00
max: implement basic max exchange skeleton
This commit is contained in:
parent
e06a480b04
commit
ba499645f6
|
@ -1,9 +1,86 @@
|
|||
package max
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
maxapi "github.com/c9s/bbgo/exchange/max/maxapi"
|
||||
"github.com/c9s/bbgo/types"
|
||||
)
|
||||
|
||||
var log = logrus.WithFields(logrus.Fields{
|
||||
"exchange": "max",
|
||||
})
|
||||
|
||||
type Exchange struct {
|
||||
client *maxapi.RestClient
|
||||
key, secret string
|
||||
}
|
||||
|
||||
func NewExchange(key, secret string) *Exchange {
|
||||
func New(key, secret string) *Exchange {
|
||||
client := maxapi.NewRestClient(maxapi.ProductionAPIURL)
|
||||
client.Auth(key, secret)
|
||||
return &Exchange{
|
||||
client: client,
|
||||
key: key,
|
||||
secret: secret,
|
||||
}
|
||||
}
|
||||
|
||||
func (e *Exchange) NewStream() types.Stream {
|
||||
return NewStream(e.key, e.secret)
|
||||
}
|
||||
|
||||
func (e *Exchange) SubmitOrder(ctx context.Context, order *types.SubmitOrder) error {
|
||||
orderType, err := toLocalOrderType(order.Type)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
retOrder, err := e.client.OrderService.Create(
|
||||
order.Symbol,
|
||||
toLocalSideType(order.Side),
|
||||
order.Quantity,
|
||||
order.Price,
|
||||
string(orderType),
|
||||
maxapi.Options{})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Infof("order created: %+v", retOrder)
|
||||
return err
|
||||
}
|
||||
|
||||
// PlatformFeeCurrency
|
||||
func (e *Exchange) PlatformFeeCurrency() string {
|
||||
return "max"
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
func toLocalCurrency(currency string) string {
|
||||
return strings.ToLower(currency)
|
||||
}
|
||||
|
||||
func toLocalSideType(side types.SideType) string {
|
||||
return strings.ToLower(string(side))
|
||||
}
|
||||
|
||||
func toLocalOrderType(orderType types.OrderType) (maxapi.OrderType, error) {
|
||||
switch orderType {
|
||||
case types.OrderTypeLimit:
|
||||
return maxapi.OrderTypeLimit, nil
|
||||
|
||||
case types.OrderTypeMarket:
|
||||
return maxapi.OrderTypeMarket, nil
|
||||
}
|
||||
|
||||
return "", fmt.Errorf("order type %s not supported", orderType)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user