mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-22 15:10:13 +00:00
committed by
Adrian Gallagher
parent
242b02c382
commit
63a9e9fcb1
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/config"
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/sharedtestvalues"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
)
|
||||
@@ -246,7 +247,7 @@ func TestCancelOrders(t *testing.T) {
|
||||
func TestCancelAllOrders(t *testing.T) {
|
||||
_, err := b.CancelAllExistingOrders(OrderCancelAllParams{})
|
||||
if err == nil {
|
||||
t.Error("CancelAllOrders(orderCancellation *exchange.OrderCancellation) (exchange.CancelAllOrdersResponse, error)", err)
|
||||
t.Error("CancelAllOrders(orderCancellation *order.Cancel) (order.CancelAllResponse, error)", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -483,8 +484,8 @@ func TestGetActiveOrders(t *testing.T) {
|
||||
b.SetDefaults()
|
||||
TestSetup(t)
|
||||
|
||||
var getOrdersRequest = exchange.GetOrdersRequest{
|
||||
OrderType: exchange.AnyOrderType,
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
OrderType: order.AnyType,
|
||||
}
|
||||
|
||||
_, err := b.GetActiveOrders(&getOrdersRequest)
|
||||
@@ -499,8 +500,8 @@ func TestGetOrderHistory(t *testing.T) {
|
||||
b.SetDefaults()
|
||||
TestSetup(t)
|
||||
|
||||
var getOrdersRequest = exchange.GetOrdersRequest{
|
||||
OrderType: exchange.AnyOrderType,
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
OrderType: order.AnyType,
|
||||
Currencies: []currency.Pair{currency.NewPair(currency.LTC,
|
||||
currency.BTC)},
|
||||
}
|
||||
@@ -527,13 +528,13 @@ func TestSubmitOrder(t *testing.T) {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
var orderSubmission = &exchange.OrderSubmission{
|
||||
var orderSubmission = &order.Submit{
|
||||
Pair: currency.Pair{
|
||||
Base: currency.XBT,
|
||||
Quote: currency.USD,
|
||||
},
|
||||
OrderSide: exchange.BuyOrderSide,
|
||||
OrderType: exchange.LimitOrderType,
|
||||
OrderSide: order.Buy,
|
||||
OrderType: order.Limit,
|
||||
Price: 1,
|
||||
Amount: 1,
|
||||
ClientID: "meowOrder",
|
||||
@@ -556,7 +557,7 @@ func TestCancelExchangeOrder(t *testing.T) {
|
||||
|
||||
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
|
||||
var orderCancellation = &exchange.OrderCancellation{
|
||||
var orderCancellation = &order.Cancel{
|
||||
OrderID: "123456789012345678901234567890123456",
|
||||
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
AccountID: "1",
|
||||
@@ -582,7 +583,7 @@ func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
|
||||
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
|
||||
var orderCancellation = &exchange.OrderCancellation{
|
||||
var orderCancellation = &order.Cancel{
|
||||
OrderID: "123456789012345678901234567890123456",
|
||||
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
AccountID: "1",
|
||||
@@ -598,8 +599,8 @@ func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
t.Errorf("Could not cancel orders: %v", err)
|
||||
}
|
||||
|
||||
if len(resp.OrderStatus) > 0 {
|
||||
t.Errorf("%v orders failed to cancel", len(resp.OrderStatus))
|
||||
if len(resp.Status) > 0 {
|
||||
t.Errorf("%v orders failed to cancel", len(resp.Status))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -618,7 +619,7 @@ func TestGetAccountInfo(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestModifyOrder(t *testing.T) {
|
||||
_, err := b.ModifyOrder(&exchange.ModifyOrder{OrderID: "1337"})
|
||||
_, err := b.ModifyOrder(&order.Modify{OrderID: "1337"})
|
||||
if err == nil {
|
||||
t.Error("ModifyOrder() error")
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
)
|
||||
|
||||
// RequestError allows for a general error capture from requests
|
||||
@@ -675,15 +675,15 @@ type WalletInfo struct {
|
||||
}
|
||||
|
||||
// orderTypeMap holds order type info based on Bitmex data
|
||||
var orderTypeMap = map[int64]exchange.OrderType{
|
||||
1: exchange.MarketOrderType,
|
||||
2: exchange.LimitOrderType,
|
||||
3: exchange.StopOrderType,
|
||||
7: exchange.TrailingStopOrderType,
|
||||
var orderTypeMap = map[int64]order.Type{
|
||||
1: order.Market,
|
||||
2: order.Limit,
|
||||
3: order.Stop,
|
||||
7: order.TrailingStop,
|
||||
}
|
||||
|
||||
// orderSideMap holds order type info based on Bitmex data
|
||||
var orderSideMap = map[int64]exchange.OrderSide{
|
||||
1: exchange.BuyOrderSide,
|
||||
2: exchange.SellOrderSide,
|
||||
var orderSideMap = map[int64]order.Side{
|
||||
1: order.Buy,
|
||||
2: order.Sell,
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wsorderbook"
|
||||
@@ -340,7 +341,7 @@ func (b *Bitmex) processOrderbook(data []OrderBookL2, action string, currencyPai
|
||||
var newOrderBook orderbook.Base
|
||||
var bids, asks []orderbook.Item
|
||||
for i := range data {
|
||||
if strings.EqualFold(data[i].Side, exchange.SellOrderSide.ToString()) {
|
||||
if strings.EqualFold(data[i].Side, order.Sell.String()) {
|
||||
asks = append(asks, orderbook.Item{
|
||||
Price: data[i].Price,
|
||||
Amount: float64(data[i].Size),
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/protocol"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
|
||||
@@ -345,12 +346,12 @@ func (b *Bitmex) UpdateOrderbook(p currency.Pair, assetType asset.Item) (orderbo
|
||||
}
|
||||
|
||||
for _, ob := range orderbookNew {
|
||||
if strings.EqualFold(ob.Side, exchange.SellOrderSide.ToString()) {
|
||||
if strings.EqualFold(ob.Side, order.Sell.String()) {
|
||||
orderBook.Asks = append(orderBook.Asks,
|
||||
orderbook.Item{Amount: float64(ob.Size), Price: ob.Price})
|
||||
continue
|
||||
}
|
||||
if strings.EqualFold(ob.Side, exchange.BuyOrderSide.ToString()) {
|
||||
if strings.EqualFold(ob.Side, order.Buy.String()) {
|
||||
orderBook.Bids = append(orderBook.Bids,
|
||||
orderbook.Item{Amount: float64(ob.Size), Price: ob.Price})
|
||||
continue
|
||||
@@ -408,30 +409,26 @@ func (b *Bitmex) GetExchangeHistory(p currency.Pair, assetType asset.Item) ([]ex
|
||||
}
|
||||
|
||||
// SubmitOrder submits a new order
|
||||
func (b *Bitmex) SubmitOrder(order *exchange.OrderSubmission) (exchange.SubmitOrderResponse, error) {
|
||||
var submitOrderResponse exchange.SubmitOrderResponse
|
||||
if order == nil {
|
||||
return submitOrderResponse, exchange.ErrOrderSubmissionIsNil
|
||||
}
|
||||
|
||||
if err := order.Validate(); err != nil {
|
||||
func (b *Bitmex) SubmitOrder(s *order.Submit) (order.SubmitResponse, error) {
|
||||
var submitOrderResponse order.SubmitResponse
|
||||
if err := s.Validate(); err != nil {
|
||||
return submitOrderResponse, err
|
||||
}
|
||||
|
||||
if math.Mod(order.Amount, 1) != 0 {
|
||||
if math.Mod(s.Amount, 1) != 0 {
|
||||
return submitOrderResponse,
|
||||
errors.New("order contract amount can not have decimals")
|
||||
}
|
||||
|
||||
var orderNewParams = OrderNewParams{
|
||||
OrdType: order.OrderSide.ToString(),
|
||||
Symbol: order.Pair.String(),
|
||||
OrderQty: order.Amount,
|
||||
Side: order.OrderSide.ToString(),
|
||||
OrdType: s.OrderSide.String(),
|
||||
Symbol: s.Pair.String(),
|
||||
OrderQty: s.Amount,
|
||||
Side: s.OrderSide.String(),
|
||||
}
|
||||
|
||||
if order.OrderType == exchange.LimitOrderType {
|
||||
orderNewParams.Price = order.Price
|
||||
if s.OrderType == order.Limit {
|
||||
orderNewParams.Price = s.Price
|
||||
}
|
||||
|
||||
response, err := b.CreateOrder(&orderNewParams)
|
||||
@@ -448,7 +445,7 @@ func (b *Bitmex) SubmitOrder(order *exchange.OrderSubmission) (exchange.SubmitOr
|
||||
|
||||
// ModifyOrder will allow of changing orderbook placement and limit to
|
||||
// market conversion
|
||||
func (b *Bitmex) ModifyOrder(action *exchange.ModifyOrder) (string, error) {
|
||||
func (b *Bitmex) ModifyOrder(action *order.Modify) (string, error) {
|
||||
var params OrderAmendParams
|
||||
|
||||
if math.Mod(action.Amount, 1) != 0 {
|
||||
@@ -468,19 +465,18 @@ func (b *Bitmex) ModifyOrder(action *exchange.ModifyOrder) (string, error) {
|
||||
}
|
||||
|
||||
// CancelOrder cancels an order by its corresponding ID number
|
||||
func (b *Bitmex) CancelOrder(order *exchange.OrderCancellation) error {
|
||||
func (b *Bitmex) CancelOrder(order *order.Cancel) error {
|
||||
var params = OrderCancelParams{
|
||||
OrderID: order.OrderID,
|
||||
}
|
||||
_, err := b.CancelOrders(¶ms)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// CancelAllOrders cancels all orders associated with a currency pair
|
||||
func (b *Bitmex) CancelAllOrders(_ *exchange.OrderCancellation) (exchange.CancelAllOrdersResponse, error) {
|
||||
cancelAllOrdersResponse := exchange.CancelAllOrdersResponse{
|
||||
OrderStatus: make(map[string]string),
|
||||
func (b *Bitmex) CancelAllOrders(_ *order.Cancel) (order.CancelAllResponse, error) {
|
||||
cancelAllOrdersResponse := order.CancelAllResponse{
|
||||
Status: make(map[string]string),
|
||||
}
|
||||
var emptyParams OrderCancelAllParams
|
||||
orders, err := b.CancelAllExistingOrders(emptyParams)
|
||||
@@ -490,7 +486,7 @@ func (b *Bitmex) CancelAllOrders(_ *exchange.OrderCancellation) (exchange.Cancel
|
||||
|
||||
for i := range orders {
|
||||
if orders[i].OrdRejReason != "" {
|
||||
cancelAllOrdersResponse.OrderStatus[orders[i].OrderID] = orders[i].OrdRejReason
|
||||
cancelAllOrdersResponse.Status[orders[i].OrderID] = orders[i].OrdRejReason
|
||||
}
|
||||
}
|
||||
|
||||
@@ -498,8 +494,8 @@ func (b *Bitmex) CancelAllOrders(_ *exchange.OrderCancellation) (exchange.Cancel
|
||||
}
|
||||
|
||||
// GetOrderInfo returns information on a current open order
|
||||
func (b *Bitmex) GetOrderInfo(orderID string) (exchange.OrderDetail, error) {
|
||||
var orderDetail exchange.OrderDetail
|
||||
func (b *Bitmex) GetOrderInfo(orderID string) (order.Detail, error) {
|
||||
var orderDetail order.Detail
|
||||
return orderDetail, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
@@ -557,8 +553,8 @@ func (b *Bitmex) GetFeeByType(feeBuilder *exchange.FeeBuilder) (float64, error)
|
||||
|
||||
// GetActiveOrders retrieves any orders that are active/open
|
||||
// This function is not concurrency safe due to orderSide/orderType maps
|
||||
func (b *Bitmex) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
var orders []exchange.OrderDetail
|
||||
func (b *Bitmex) GetActiveOrders(req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
var orders []order.Detail
|
||||
params := OrdersRequest{}
|
||||
params.Filter = "{\"open\":true}"
|
||||
|
||||
@@ -571,17 +567,17 @@ func (b *Bitmex) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([
|
||||
orderSide := orderSideMap[resp[i].Side]
|
||||
orderType := orderTypeMap[resp[i].OrdType]
|
||||
if orderType == "" {
|
||||
orderType = exchange.UnknownOrderType
|
||||
orderType = order.Unknown
|
||||
}
|
||||
|
||||
orderDetail := exchange.OrderDetail{
|
||||
orderDetail := order.Detail{
|
||||
Price: resp[i].Price,
|
||||
Amount: float64(resp[i].OrderQty),
|
||||
Exchange: b.Name,
|
||||
ID: resp[i].OrderID,
|
||||
OrderSide: orderSide,
|
||||
OrderType: orderType,
|
||||
Status: resp[i].OrdStatus,
|
||||
Status: order.Status(resp[i].OrdStatus),
|
||||
CurrencyPair: currency.NewPairWithDelimiter(resp[i].Symbol,
|
||||
resp[i].SettlCurrency,
|
||||
b.GetPairFormat(asset.PerpetualContract, false).Delimiter),
|
||||
@@ -590,19 +586,18 @@ func (b *Bitmex) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([
|
||||
orders = append(orders, orderDetail)
|
||||
}
|
||||
|
||||
exchange.FilterOrdersBySide(&orders, getOrdersRequest.OrderSide)
|
||||
exchange.FilterOrdersByType(&orders, getOrdersRequest.OrderType)
|
||||
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks,
|
||||
getOrdersRequest.EndTicks)
|
||||
exchange.FilterOrdersByCurrencies(&orders, getOrdersRequest.Currencies)
|
||||
order.FilterOrdersBySide(&orders, req.OrderSide)
|
||||
order.FilterOrdersByType(&orders, req.OrderType)
|
||||
order.FilterOrdersByTickRange(&orders, req.StartTicks, req.EndTicks)
|
||||
order.FilterOrdersByCurrencies(&orders, req.Currencies)
|
||||
return orders, nil
|
||||
}
|
||||
|
||||
// GetOrderHistory retrieves account order information
|
||||
// Can Limit response to specific order status
|
||||
// This function is not concurrency safe due to orderSide/orderType maps
|
||||
func (b *Bitmex) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
var orders []exchange.OrderDetail
|
||||
func (b *Bitmex) GetOrderHistory(req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
var orders []order.Detail
|
||||
params := OrdersRequest{}
|
||||
resp, err := b.GetOrders(¶ms)
|
||||
if err != nil {
|
||||
@@ -613,17 +608,17 @@ func (b *Bitmex) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([
|
||||
orderSide := orderSideMap[resp[i].Side]
|
||||
orderType := orderTypeMap[resp[i].OrdType]
|
||||
if orderType == "" {
|
||||
orderType = exchange.UnknownOrderType
|
||||
orderType = order.Unknown
|
||||
}
|
||||
|
||||
orderDetail := exchange.OrderDetail{
|
||||
orderDetail := order.Detail{
|
||||
Price: resp[i].Price,
|
||||
Amount: float64(resp[i].OrderQty),
|
||||
Exchange: b.Name,
|
||||
ID: resp[i].OrderID,
|
||||
OrderSide: orderSide,
|
||||
OrderType: orderType,
|
||||
Status: resp[i].OrdStatus,
|
||||
Status: order.Status(resp[i].OrdStatus),
|
||||
CurrencyPair: currency.NewPairWithDelimiter(resp[i].Symbol,
|
||||
resp[i].SettlCurrency,
|
||||
b.GetPairFormat(asset.PerpetualContract, false).Delimiter),
|
||||
@@ -632,10 +627,10 @@ func (b *Bitmex) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([
|
||||
orders = append(orders, orderDetail)
|
||||
}
|
||||
|
||||
exchange.FilterOrdersBySide(&orders, getOrdersRequest.OrderSide)
|
||||
exchange.FilterOrdersByType(&orders, getOrdersRequest.OrderType)
|
||||
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks, getOrdersRequest.EndTicks)
|
||||
exchange.FilterOrdersByCurrencies(&orders, getOrdersRequest.Currencies)
|
||||
order.FilterOrdersBySide(&orders, req.OrderSide)
|
||||
order.FilterOrdersByType(&orders, req.OrderType)
|
||||
order.FilterOrdersByTickRange(&orders, req.StartTicks, req.EndTicks)
|
||||
order.FilterOrdersByCurrencies(&orders, req.Currencies)
|
||||
return orders, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user