mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-29 15:10:37 +00:00
committed by
Adrian Gallagher
parent
242b02c382
commit
63a9e9fcb1
@@ -9,6 +9,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"
|
||||
)
|
||||
|
||||
// Please supply your own keys here to do better tests
|
||||
@@ -150,8 +151,8 @@ func TestGetActiveOrders(t *testing.T) {
|
||||
if !areTestAPIKeysSet() {
|
||||
t.Skip("API keys not set, skipping test")
|
||||
}
|
||||
var getOrdersRequest = exchange.GetOrdersRequest{
|
||||
OrderType: exchange.AnyOrderType,
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
OrderType: order.AnyType,
|
||||
}
|
||||
|
||||
_, err := b.GetActiveOrders(&getOrdersRequest)
|
||||
@@ -165,8 +166,8 @@ func TestGetOrderHistory(t *testing.T) {
|
||||
if !areTestAPIKeysSet() {
|
||||
t.Skip("API keys not set, skipping test")
|
||||
}
|
||||
var getOrdersRequest = exchange.GetOrdersRequest{
|
||||
OrderType: exchange.AnyOrderType,
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
OrderType: order.AnyType,
|
||||
}
|
||||
_, err := b.GetOrderHistory(&getOrdersRequest)
|
||||
if err != nil {
|
||||
@@ -279,13 +280,13 @@ func TestSubmitOrder(t *testing.T) {
|
||||
if !areTestAPIKeysSet() || !canManipulateRealOrders {
|
||||
t.Skip("skipping test, either api keys or manipulaterealorders isnt set correctly")
|
||||
}
|
||||
var orderSubmission = &exchange.OrderSubmission{
|
||||
var orderSubmission = &order.Submit{
|
||||
Pair: currency.Pair{
|
||||
Base: currency.BTC,
|
||||
Quote: currency.USD,
|
||||
},
|
||||
OrderSide: exchange.SellOrderSide,
|
||||
OrderType: exchange.LimitOrderType,
|
||||
OrderSide: order.Buy,
|
||||
OrderType: order.Limit,
|
||||
Price: 100000,
|
||||
Amount: 0.1,
|
||||
ClientID: "meowOrder",
|
||||
@@ -307,7 +308,7 @@ func TestCancelExchangeOrder(t *testing.T) {
|
||||
currency.USD.String(),
|
||||
"-")
|
||||
|
||||
var orderCancellation = &exchange.OrderCancellation{
|
||||
var orderCancellation = &order.Cancel{
|
||||
OrderID: "b334ecef-2b42-4998-b8a4-b6b14f6d2671",
|
||||
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
AccountID: "1",
|
||||
@@ -328,7 +329,7 @@ func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
currency.USD.String(),
|
||||
"-")
|
||||
|
||||
var orderCancellation = &exchange.OrderCancellation{
|
||||
var orderCancellation = &order.Cancel{
|
||||
OrderID: "1",
|
||||
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
AccountID: "1",
|
||||
@@ -339,7 +340,7 @@ func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Errorf("Could not cancel orders: %v", err)
|
||||
}
|
||||
for k, v := range resp.OrderStatus {
|
||||
for k, v := range resp.Status {
|
||||
if strings.Contains(v, "Failed") {
|
||||
t.Errorf("order id: %s failed to cancel: %v", k, v)
|
||||
}
|
||||
|
||||
@@ -11,8 +11,8 @@ import (
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/thrasher-corp/gocryptotrader/common"
|
||||
"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"
|
||||
log "github.com/thrasher-corp/gocryptotrader/logger"
|
||||
@@ -82,9 +82,9 @@ func (b *BTSE) WsHandleData() {
|
||||
continue
|
||||
}
|
||||
for x := range tradeHistory.Data {
|
||||
side := exchange.BuyOrderSide.ToString()
|
||||
side := order.Buy.String()
|
||||
if tradeHistory.Data[x].Gain == -1 {
|
||||
side = exchange.SellOrderSide.ToString()
|
||||
side = order.Sell.String()
|
||||
}
|
||||
b.Websocket.DataHandler <- wshandler.TradeData{
|
||||
Timestamp: time.Unix(tradeHistory.Data[x].TransactionTime, 0),
|
||||
|
||||
@@ -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"
|
||||
@@ -233,7 +234,6 @@ func (b *BTSE) UpdateTicker(p currency.Pair, assetType asset.Item) (ticker.Price
|
||||
assetType).String())
|
||||
if err != nil {
|
||||
return tickerPrice, err
|
||||
|
||||
}
|
||||
|
||||
tickerPrice.Pair = p
|
||||
@@ -337,23 +337,19 @@ func (b *BTSE) GetExchangeHistory(p currency.Pair, assetType asset.Item) ([]exch
|
||||
}
|
||||
|
||||
// SubmitOrder submits a new order
|
||||
func (b *BTSE) SubmitOrder(order *exchange.OrderSubmission) (exchange.SubmitOrderResponse, error) {
|
||||
var resp exchange.SubmitOrderResponse
|
||||
if order == nil {
|
||||
return resp, exchange.ErrOrderSubmissionIsNil
|
||||
}
|
||||
|
||||
if err := order.Validate(); err != nil {
|
||||
func (b *BTSE) SubmitOrder(s *order.Submit) (order.SubmitResponse, error) {
|
||||
var resp order.SubmitResponse
|
||||
if err := s.Validate(); err != nil {
|
||||
return resp, err
|
||||
}
|
||||
|
||||
r, err := b.CreateOrder(order.Amount,
|
||||
order.Price,
|
||||
order.OrderSide.ToString(),
|
||||
order.OrderType.ToString(),
|
||||
b.FormatExchangeCurrency(order.Pair, asset.Spot).String(),
|
||||
r, err := b.CreateOrder(s.Amount,
|
||||
s.Price,
|
||||
s.OrderSide.String(),
|
||||
s.OrderType.String(),
|
||||
b.FormatExchangeCurrency(s.Pair, asset.Spot).String(),
|
||||
goodTillCancel,
|
||||
order.ClientID)
|
||||
s.ClientID)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -368,12 +364,12 @@ func (b *BTSE) SubmitOrder(order *exchange.OrderSubmission) (exchange.SubmitOrde
|
||||
|
||||
// ModifyOrder will allow of changing orderbook placement and limit to
|
||||
// market conversion
|
||||
func (b *BTSE) ModifyOrder(action *exchange.ModifyOrder) (string, error) {
|
||||
func (b *BTSE) ModifyOrder(action *order.Modify) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// CancelOrder cancels an order by its corresponding ID number
|
||||
func (b *BTSE) CancelOrder(order *exchange.OrderCancellation) error {
|
||||
func (b *BTSE) CancelOrder(order *order.Cancel) error {
|
||||
r, err := b.CancelExistingOrder(order.OrderID,
|
||||
b.FormatExchangeCurrency(order.CurrencyPair,
|
||||
asset.Spot).String())
|
||||
@@ -394,14 +390,14 @@ func (b *BTSE) CancelOrder(order *exchange.OrderCancellation) error {
|
||||
// CancelAllOrders cancels all orders associated with a currency pair
|
||||
// If product ID is sent, all orders of that specified market will be cancelled
|
||||
// If not specified, all orders of all markets will be cancelled
|
||||
func (b *BTSE) CancelAllOrders(orderCancellation *exchange.OrderCancellation) (exchange.CancelAllOrdersResponse, error) {
|
||||
var resp exchange.CancelAllOrdersResponse
|
||||
func (b *BTSE) CancelAllOrders(orderCancellation *order.Cancel) (order.CancelAllResponse, error) {
|
||||
var resp order.CancelAllResponse
|
||||
markets, err := b.GetMarkets()
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
|
||||
resp.OrderStatus = make(map[string]string)
|
||||
resp.Status = make(map[string]string)
|
||||
for x := range markets {
|
||||
strPair := b.FormatExchangeCurrency(orderCancellation.CurrencyPair,
|
||||
orderCancellation.AssetType).String()
|
||||
@@ -421,7 +417,7 @@ func (b *BTSE) CancelAllOrders(orderCancellation *exchange.OrderCancellation) (e
|
||||
if err != nil {
|
||||
success = "Order Cancellation Failed"
|
||||
}
|
||||
resp.OrderStatus[orders[y].Order.ID] = success
|
||||
resp.Status[orders[y].Order.ID] = success
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -429,13 +425,13 @@ func (b *BTSE) CancelAllOrders(orderCancellation *exchange.OrderCancellation) (e
|
||||
}
|
||||
|
||||
// GetOrderInfo returns information on a current open order
|
||||
func (b *BTSE) GetOrderInfo(orderID string) (exchange.OrderDetail, error) {
|
||||
func (b *BTSE) GetOrderInfo(orderID string) (order.Detail, error) {
|
||||
o, err := b.GetOrders("")
|
||||
if err != nil {
|
||||
return exchange.OrderDetail{}, err
|
||||
return order.Detail{}, err
|
||||
}
|
||||
|
||||
var od exchange.OrderDetail
|
||||
var od order.Detail
|
||||
if len(o) == 0 {
|
||||
return od, errors.New("no orders found")
|
||||
}
|
||||
@@ -445,9 +441,9 @@ func (b *BTSE) GetOrderInfo(orderID string) (exchange.OrderDetail, error) {
|
||||
continue
|
||||
}
|
||||
|
||||
var side = exchange.BuyOrderSide
|
||||
if strings.EqualFold(o[i].Side, exchange.AskOrderSide.ToString()) {
|
||||
side = exchange.SellOrderSide
|
||||
var side = order.Buy
|
||||
if strings.EqualFold(o[i].Side, order.Ask.String()) {
|
||||
side = order.Sell
|
||||
}
|
||||
|
||||
od.CurrencyPair = currency.NewPairDelimiter(o[i].Symbol,
|
||||
@@ -457,24 +453,26 @@ func (b *BTSE) GetOrderInfo(orderID string) (exchange.OrderDetail, error) {
|
||||
od.ID = o[i].ID
|
||||
od.OrderDate = parseOrderTime(o[i].CreatedAt)
|
||||
od.OrderSide = side
|
||||
od.OrderType = exchange.OrderType(strings.ToUpper(o[i].Type))
|
||||
od.OrderType = order.Type(strings.ToUpper(o[i].Type))
|
||||
od.Price = o[i].Price
|
||||
od.Status = o[i].Status
|
||||
od.Status = order.Status(o[i].Status)
|
||||
|
||||
fills, err := b.GetFills(orderID, "", "", "", "", "")
|
||||
if err != nil {
|
||||
return od, fmt.Errorf("unable to get order fills for orderID %s", orderID)
|
||||
return od,
|
||||
fmt.Errorf("unable to get order fills for orderID %s",
|
||||
orderID)
|
||||
}
|
||||
|
||||
for i := range fills {
|
||||
createdAt, _ := time.Parse(time.RFC3339, fills[i].CreatedAt)
|
||||
od.Trades = append(od.Trades, exchange.TradeHistory{
|
||||
od.Trades = append(od.Trades, order.TradeHistory{
|
||||
Timestamp: createdAt,
|
||||
TID: fills[i].ID,
|
||||
Price: fills[i].Price,
|
||||
Amount: fills[i].Amount,
|
||||
Exchange: b.Name,
|
||||
Type: fills[i].Side,
|
||||
Side: order.Side(fills[i].Side),
|
||||
Fee: fills[i].Fee,
|
||||
})
|
||||
}
|
||||
@@ -511,20 +509,20 @@ func (b *BTSE) GetWebsocket() (*wshandler.Websocket, error) {
|
||||
}
|
||||
|
||||
// GetActiveOrders retrieves any orders that are active/open
|
||||
func (b *BTSE) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
func (b *BTSE) GetActiveOrders(req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
resp, err := b.GetOrders("")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var orders []exchange.OrderDetail
|
||||
var orders []order.Detail
|
||||
for i := range resp {
|
||||
var side = exchange.BuyOrderSide
|
||||
if strings.EqualFold(resp[i].Side, exchange.AskOrderSide.ToString()) {
|
||||
side = exchange.SellOrderSide
|
||||
var side = order.Buy
|
||||
if strings.EqualFold(resp[i].Side, order.Ask.String()) {
|
||||
side = order.Sell
|
||||
}
|
||||
|
||||
openOrder := exchange.OrderDetail{
|
||||
openOrder := order.Detail{
|
||||
CurrencyPair: currency.NewPairDelimiter(resp[i].Symbol,
|
||||
b.GetPairFormat(asset.Spot, false).Delimiter),
|
||||
Exchange: b.Name,
|
||||
@@ -532,43 +530,44 @@ func (b *BTSE) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([]e
|
||||
ID: resp[i].ID,
|
||||
OrderDate: parseOrderTime(resp[i].CreatedAt),
|
||||
OrderSide: side,
|
||||
OrderType: exchange.OrderType(strings.ToUpper(resp[i].Type)),
|
||||
OrderType: order.Type(strings.ToUpper(resp[i].Type)),
|
||||
Price: resp[i].Price,
|
||||
Status: resp[i].Status,
|
||||
Status: order.Status(resp[i].Status),
|
||||
}
|
||||
|
||||
fills, err := b.GetFills(resp[i].ID, "", "", "", "", "")
|
||||
if err != nil {
|
||||
log.Errorf(log.ExchangeSys,
|
||||
"%s: Unable to get order fills for orderID %s", b.Name,
|
||||
"%s: Unable to get order fills for orderID %s",
|
||||
b.Name,
|
||||
resp[i].ID)
|
||||
continue
|
||||
}
|
||||
|
||||
for i := range fills {
|
||||
createdAt, _ := time.Parse(time.RFC3339, fills[i].CreatedAt)
|
||||
openOrder.Trades = append(openOrder.Trades, exchange.TradeHistory{
|
||||
openOrder.Trades = append(openOrder.Trades, order.TradeHistory{
|
||||
Timestamp: createdAt,
|
||||
TID: fills[i].ID,
|
||||
Price: fills[i].Price,
|
||||
Amount: fills[i].Amount,
|
||||
Exchange: b.Name,
|
||||
Type: fills[i].Side,
|
||||
Side: order.Side(fills[i].Side),
|
||||
Fee: fills[i].Fee,
|
||||
})
|
||||
}
|
||||
orders = append(orders, openOrder)
|
||||
}
|
||||
|
||||
exchange.FilterOrdersByType(&orders, getOrdersRequest.OrderType)
|
||||
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks, getOrdersRequest.EndTicks)
|
||||
exchange.FilterOrdersBySide(&orders, getOrdersRequest.OrderSide)
|
||||
order.FilterOrdersByType(&orders, req.OrderType)
|
||||
order.FilterOrdersByTickRange(&orders, req.StartTicks, req.EndTicks)
|
||||
order.FilterOrdersBySide(&orders, req.OrderSide)
|
||||
return orders, nil
|
||||
}
|
||||
|
||||
// GetOrderHistory retrieves account order information
|
||||
// Can Limit response to specific order status
|
||||
func (b *BTSE) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
func (b *BTSE) GetOrderHistory(getOrdersRequest *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user