ftx: Support LIMIT_MAKER and IOC_LIMIT order type

This commit is contained in:
Lee 2022-01-12 03:47:12 +08:00
parent 70dec09f26
commit 523d9b3071
3 changed files with 75 additions and 4 deletions

View File

@ -152,3 +152,29 @@ func toGlobalKLine(symbol string, interval types.Interval, h Candle) (types.KLin
Closed: true,
}, nil
}
type OrderType string
const (
OrderTypeLimit OrderType = "limit"
OrderTypeMarket OrderType = "market"
)
func toLocalOrderType(orderType types.OrderType) (OrderType, bool, bool, error) {
switch orderType {
case types.OrderTypeLimitMaker:
return OrderTypeLimit, true, false, nil
case types.OrderTypeLimit:
return OrderTypeLimit, false, false, nil
case types.OrderTypeMarket:
return OrderTypeMarket, false, false, nil
case types.OrderTypeIOCLimit:
return OrderTypeLimit, false, true, nil
}
return "", false, false, fmt.Errorf("order type %s not supported", orderType)
}

View File

@ -100,3 +100,43 @@ func TestTrimLowerString(t *testing.T) {
func Test_toGlobalSymbol(t *testing.T) {
assert.Equal(t, "BTCUSDT", toGlobalSymbol("BTC/USDT"))
}
func Test_toLocalOrderTypeWithLimitMaker(t *testing.T) {
orderType, postOnly, IOC, err := toLocalOrderType(types.OrderTypeLimitMaker)
assert.NoError(t, err)
assert.Equal(t, orderType, OrderTypeLimit)
assert.Equal(t, postOnly, true)
assert.Equal(t, IOC, false)
}
func Test_toLocalOrderTypeWithLimit(t *testing.T) {
orderType, postOnly, IOC, err := toLocalOrderType(types.OrderTypeLimit)
assert.NoError(t, err)
assert.Equal(t, orderType, OrderTypeLimit)
assert.Equal(t, postOnly, false)
assert.Equal(t, IOC, false)
}
func Test_toLocalOrderTypeWithMarket(t *testing.T) {
orderType, postOnly, IOC, err := toLocalOrderType(types.OrderTypeMarket)
assert.NoError(t, err)
assert.Equal(t, orderType, OrderTypeMarket)
assert.Equal(t, postOnly, false)
assert.Equal(t, IOC, false)
}
func Test_toLocalOrderTypeWithIOCLimit(t *testing.T) {
orderType, postOnly, IOC, err := toLocalOrderType(types.OrderTypeIOCLimit)
assert.NoError(t, err)
assert.Equal(t, orderType, OrderTypeLimit)
assert.Equal(t, postOnly, false)
assert.Equal(t, IOC, true)
}

View File

@ -3,13 +3,14 @@ package ftx
import (
"context"
"fmt"
"golang.org/x/time/rate"
"net/http"
"net/url"
"sort"
"strings"
"time"
"golang.org/x/time/rate"
"github.com/google/uuid"
"github.com/sirupsen/logrus"
@ -454,15 +455,19 @@ func (e *Exchange) SubmitOrders(ctx context.Context, orders ...types.SubmitOrder
if err := requestLimit.Wait(ctx); err != nil {
logrus.WithError(err).Error("rate limit error")
}
orderType, postOnly, IOC, err := toLocalOrderType(so.Type)
if err != nil {
logrus.WithError(err).Error("type error")
}
or, err := e.newRest().PlaceOrder(ctx, PlaceOrderPayload{
Market: toLocalSymbol(TrimUpperString(so.Symbol)),
Side: TrimLowerString(string(so.Side)),
Price: so.Price,
Type: TrimLowerString(string(so.Type)),
Type: string(orderType),
Size: so.Quantity,
ReduceOnly: false,
IOC: false,
PostOnly: false,
IOC: IOC,
PostOnly: postOnly,
ClientID: newSpotClientOrderID(so.ClientOrderID),
})
if err != nil {