mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +00:00
committed by
Adrian Gallagher
parent
242b02c382
commit
63a9e9fcb1
@@ -116,29 +116,29 @@ func ({{.Variable}} *{{.CapitalName}}) GetExchangeHistory(p currency.Pair, asset
|
||||
}
|
||||
|
||||
// SubmitOrder submits a new order
|
||||
func ({{.Variable}} *{{.CapitalName}}) SubmitOrder(p currency.Pair, side exchange.OrderSide, orderType exchange.OrderType, amount, price float64, clientID string) (exchange.SubmitOrderResponse, error) {
|
||||
return exchange.SubmitOrderResponse{}, common.ErrNotYetImplemented
|
||||
func ({{.Variable}} *{{.CapitalName}}) SubmitOrder(p currency.Pair, side order.Side, orderType order.Type, amount, price float64, clientID string) (order.SubmitResponse, error) {
|
||||
return order.SubmitResponse{}, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
// ModifyOrder will allow of changing orderbook placement and limit to
|
||||
// market conversion
|
||||
func ({{.Variable}} *{{.CapitalName}}) ModifyOrder(action *exchange.ModifyOrder) (string, error) {
|
||||
func ({{.Variable}} *{{.CapitalName}}) ModifyOrder(action *order.Modify) (string, error) {
|
||||
return "", common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
// CancelOrder cancels an order by its corresponding ID number
|
||||
func ({{.Variable}} *{{.CapitalName}}) CancelOrder(order *exchange.OrderCancellation) error {
|
||||
func ({{.Variable}} *{{.CapitalName}}) CancelOrder(order *order.Cancel) error {
|
||||
return common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
// CancelAllOrders cancels all orders associated with a currency pair
|
||||
func ({{.Variable}} *{{.CapitalName}}) CancelAllOrders(orderCancellation *exchange.OrderCancellation) (exchange.CancelAllOrdersResponse, error) {
|
||||
return exchange.CancelAllOrdersResponse{}, common.ErrNotYetImplemented
|
||||
func ({{.Variable}} *{{.CapitalName}}) CancelAllOrders(orderCancellation *order.Cancel) (order.CancelAllResponse, error) {
|
||||
return order.CancelAllResponse{}, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
// GetOrderInfo returns information on a current open order
|
||||
func ({{.Variable}} *{{.CapitalName}}) GetOrderInfo(orderID string) (exchange.OrderDetail, error) {
|
||||
return exchange.OrderDetail{}, common.ErrNotYetImplemented
|
||||
func ({{.Variable}} *{{.CapitalName}}) GetOrderInfo(orderID string) (order.Detail, error) {
|
||||
return order.Detail{}, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
// GetDepositAddress returns a deposit address for a specified currency
|
||||
@@ -170,13 +170,13 @@ func ({{.Variable}} *{{.CapitalName}}) GetWebsocket() (*exchange.Websocket, erro
|
||||
}
|
||||
|
||||
// GetActiveOrders retrieves any orders that are active/open
|
||||
func ({{.Variable}} *{{.CapitalName}}) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
func ({{.Variable}} *{{.CapitalName}}) GetActiveOrders(getOrdersRequest *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
return nil, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
// GetOrderHistory retrieves account order information
|
||||
// Can Limit response to specific order status
|
||||
func ({{.Variable}} *{{.CapitalName}}) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
func ({{.Variable}} *{{.CapitalName}}) GetOrderHistory(getOrdersRequest *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
return nil, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/engine"
|
||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -116,10 +117,10 @@ func testWrappers(e exchange.IBotExchange) []string {
|
||||
funcs = append(funcs, "GetFundingHistory")
|
||||
}
|
||||
|
||||
s := &exchange.OrderSubmission{
|
||||
s := &order.Submit{
|
||||
Pair: p,
|
||||
OrderSide: exchange.BuyOrderSide,
|
||||
OrderType: exchange.LimitOrderType,
|
||||
OrderSide: order.Buy,
|
||||
OrderType: order.Limit,
|
||||
Amount: 1000000,
|
||||
Price: 10000000000,
|
||||
ClientID: "meow",
|
||||
@@ -129,17 +130,17 @@ func testWrappers(e exchange.IBotExchange) []string {
|
||||
funcs = append(funcs, "SubmitOrder")
|
||||
}
|
||||
|
||||
_, err = e.ModifyOrder(&exchange.ModifyOrder{})
|
||||
_, err = e.ModifyOrder(&order.Modify{})
|
||||
if err == common.ErrNotYetImplemented {
|
||||
funcs = append(funcs, "ModifyOrder")
|
||||
}
|
||||
|
||||
err = e.CancelOrder(&exchange.OrderCancellation{})
|
||||
err = e.CancelOrder(&order.Cancel{})
|
||||
if err == common.ErrNotYetImplemented {
|
||||
funcs = append(funcs, "CancelOrder")
|
||||
}
|
||||
|
||||
_, err = e.CancelAllOrders(&exchange.OrderCancellation{})
|
||||
_, err = e.CancelAllOrders(&order.Cancel{})
|
||||
if err == common.ErrNotYetImplemented {
|
||||
funcs = append(funcs, "CancelAllOrders")
|
||||
}
|
||||
@@ -149,12 +150,12 @@ func testWrappers(e exchange.IBotExchange) []string {
|
||||
funcs = append(funcs, "GetOrderInfo")
|
||||
}
|
||||
|
||||
_, err = e.GetOrderHistory(&exchange.GetOrdersRequest{})
|
||||
_, err = e.GetOrderHistory(&order.GetOrdersRequest{})
|
||||
if err == common.ErrNotYetImplemented {
|
||||
funcs = append(funcs, "GetOrderHistory")
|
||||
}
|
||||
|
||||
_, err = e.GetActiveOrders(&exchange.GetOrdersRequest{})
|
||||
_, err = e.GetActiveOrders(&order.GetOrdersRequest{})
|
||||
if err == common.ErrNotYetImplemented {
|
||||
funcs = append(funcs, "GetActiveOrders")
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/engine"
|
||||
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/ticker"
|
||||
)
|
||||
@@ -225,43 +226,44 @@ func setExchangeAPIKeys(name string, keys map[string]*config.APICredentialsConfi
|
||||
return base.ValidateAPICredentials()
|
||||
}
|
||||
|
||||
func parseOrderSide(orderSide string) exchange.OrderSide {
|
||||
func parseOrderSide(orderSide string) order.Side {
|
||||
switch orderSide {
|
||||
case exchange.AnyOrderSide.ToString():
|
||||
return exchange.AnyOrderSide
|
||||
case exchange.BuyOrderSide.ToString():
|
||||
return exchange.BuyOrderSide
|
||||
case exchange.SellOrderSide.ToString():
|
||||
return exchange.SellOrderSide
|
||||
case exchange.BidOrderSide.ToString():
|
||||
return exchange.BidOrderSide
|
||||
case exchange.AskOrderSide.ToString():
|
||||
return exchange.AskOrderSide
|
||||
case order.AnySide.String():
|
||||
return order.AnySide
|
||||
case order.Buy.String():
|
||||
return order.Buy
|
||||
case order.Sell.String():
|
||||
return order.Sell
|
||||
case order.Bid.String():
|
||||
return order.Bid
|
||||
case order.Ask.String():
|
||||
return order.Ask
|
||||
default:
|
||||
log.Printf("Orderside '%v' not recognised, defaulting to BUY", orderSide)
|
||||
return exchange.BuyOrderSide
|
||||
return order.Buy
|
||||
}
|
||||
}
|
||||
|
||||
func parseOrderType(orderType string) exchange.OrderType {
|
||||
func parseOrderType(orderType string) order.Type {
|
||||
switch orderType {
|
||||
case exchange.AnyOrderType.ToString():
|
||||
return exchange.AnyOrderType
|
||||
case exchange.LimitOrderType.ToString():
|
||||
return exchange.LimitOrderType
|
||||
case exchange.MarketOrderType.ToString():
|
||||
return exchange.MarketOrderType
|
||||
case exchange.ImmediateOrCancelOrderType.ToString():
|
||||
return exchange.ImmediateOrCancelOrderType
|
||||
case exchange.StopOrderType.ToString():
|
||||
return exchange.StopOrderType
|
||||
case exchange.TrailingStopOrderType.ToString():
|
||||
return exchange.TrailingStopOrderType
|
||||
case exchange.UnknownOrderType.ToString():
|
||||
return exchange.UnknownOrderType
|
||||
case order.AnyType.String():
|
||||
return order.AnyType
|
||||
case order.Limit.String():
|
||||
return order.Limit
|
||||
case order.Market.String():
|
||||
return order.Market
|
||||
case order.ImmediateOrCancel.String():
|
||||
return order.ImmediateOrCancel
|
||||
case order.Stop.String():
|
||||
return order.Stop
|
||||
case order.TrailingStop.String():
|
||||
return order.TrailingStop
|
||||
case order.Unknown.String():
|
||||
return order.Unknown
|
||||
default:
|
||||
log.Printf("OrderType '%v' not recognised, defaulting to LIMIT", orderTypeOverride)
|
||||
return exchange.LimitOrderType
|
||||
log.Printf("OrderType '%v' not recognised, defaulting to LIMIT",
|
||||
orderTypeOverride)
|
||||
return order.Limit
|
||||
}
|
||||
}
|
||||
|
||||
@@ -457,7 +459,7 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
|
||||
Response: jsonifyInterface([]interface{}{r10}),
|
||||
})
|
||||
|
||||
s := &exchange.OrderSubmission{
|
||||
s := &order.Submit{
|
||||
Pair: p,
|
||||
OrderSide: testOrderSide,
|
||||
OrderType: testOrderType,
|
||||
@@ -465,7 +467,7 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
|
||||
Price: config.OrderSubmission.Price,
|
||||
ClientID: config.OrderSubmission.OrderID,
|
||||
}
|
||||
var r11 exchange.SubmitOrderResponse
|
||||
var r11 order.SubmitResponse
|
||||
r11, err = e.SubmitOrder(s)
|
||||
msg = ""
|
||||
if err != nil {
|
||||
@@ -479,10 +481,10 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
|
||||
Response: jsonifyInterface([]interface{}{r11}),
|
||||
})
|
||||
|
||||
modifyRequest := exchange.ModifyOrder{
|
||||
modifyRequest := order.Modify{
|
||||
OrderID: config.OrderSubmission.OrderID,
|
||||
OrderType: testOrderType,
|
||||
OrderSide: testOrderSide,
|
||||
Type: testOrderType,
|
||||
Side: testOrderSide,
|
||||
CurrencyPair: p,
|
||||
Price: config.OrderSubmission.Price,
|
||||
Amount: config.OrderSubmission.Amount,
|
||||
@@ -501,7 +503,7 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
|
||||
Response: r12,
|
||||
})
|
||||
// r13
|
||||
cancelRequest := exchange.OrderCancellation{
|
||||
cancelRequest := order.Cancel{
|
||||
Side: testOrderSide,
|
||||
CurrencyPair: p,
|
||||
OrderID: config.OrderSubmission.OrderID,
|
||||
@@ -519,7 +521,7 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
|
||||
Response: jsonifyInterface([]interface{}{nil}),
|
||||
})
|
||||
|
||||
var r14 exchange.CancelAllOrdersResponse
|
||||
var r14 order.CancelAllResponse
|
||||
r14, err = e.CancelAllOrders(&cancelRequest)
|
||||
msg = ""
|
||||
if err != nil {
|
||||
@@ -533,7 +535,7 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
|
||||
Response: jsonifyInterface([]interface{}{r14}),
|
||||
})
|
||||
|
||||
var r15 exchange.OrderDetail
|
||||
var r15 order.Detail
|
||||
r15, err = e.GetOrderInfo(config.OrderSubmission.OrderID)
|
||||
msg = ""
|
||||
if err != nil {
|
||||
@@ -547,12 +549,12 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
|
||||
Response: jsonifyInterface([]interface{}{r15}),
|
||||
})
|
||||
|
||||
historyRequest := exchange.GetOrdersRequest{
|
||||
historyRequest := order.GetOrdersRequest{
|
||||
OrderType: testOrderType,
|
||||
OrderSide: testOrderSide,
|
||||
Currencies: []currency.Pair{p},
|
||||
}
|
||||
var r16 []exchange.OrderDetail
|
||||
var r16 []order.Detail
|
||||
r16, err = e.GetOrderHistory(&historyRequest)
|
||||
msg = ""
|
||||
if err != nil {
|
||||
@@ -566,12 +568,12 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
|
||||
Response: jsonifyInterface([]interface{}{r16}),
|
||||
})
|
||||
|
||||
orderRequest := exchange.GetOrdersRequest{
|
||||
orderRequest := order.GetOrdersRequest{
|
||||
OrderType: testOrderType,
|
||||
OrderSide: testOrderSide,
|
||||
Currencies: []currency.Pair{p},
|
||||
}
|
||||
var r17 []exchange.OrderDetail
|
||||
var r17 []order.Detail
|
||||
r17, err = e.GetActiveOrders(&orderRequest)
|
||||
msg = ""
|
||||
if err != nil {
|
||||
|
||||
@@ -37,12 +37,18 @@ func (a *databaseManager) Start() (err error) {
|
||||
|
||||
if Bot.Config.Database.Enabled {
|
||||
if Bot.Config.Database.Driver == database.DBPostgreSQL {
|
||||
log.Debugf(log.DatabaseMgr, "Attempting to establish database connection to host %s/%s utilising %s driver\n",
|
||||
Bot.Config.Database.Host, Bot.Config.Database.Database, Bot.Config.Database.Driver)
|
||||
log.Debugf(log.DatabaseMgr,
|
||||
"Attempting to establish database connection to host %s/%s utilising %s driver\n",
|
||||
Bot.Config.Database.Host,
|
||||
Bot.Config.Database.Database,
|
||||
Bot.Config.Database.Driver)
|
||||
dbConn, err = dbpsql.Connect()
|
||||
} else if Bot.Config.Database.Driver == database.DBSQLite || Bot.Config.Database.Driver == database.DBSQLite3 {
|
||||
log.Debugf(log.DatabaseMgr, "Attempting to establish database connection to %s utilising %s driver\n",
|
||||
Bot.Config.Database.Database, Bot.Config.Database.Driver)
|
||||
} else if Bot.Config.Database.Driver == database.DBSQLite ||
|
||||
Bot.Config.Database.Driver == database.DBSQLite3 {
|
||||
log.Debugf(log.DatabaseMgr,
|
||||
"Attempting to establish database connection to %s utilising %s driver\n",
|
||||
Bot.Config.Database.Database,
|
||||
Bot.Config.Database.Driver)
|
||||
dbConn, err = dbsqlite3.Connect()
|
||||
}
|
||||
if err != nil {
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/common"
|
||||
"github.com/thrasher-corp/gocryptotrader/communications/base"
|
||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
log "github.com/thrasher-corp/gocryptotrader/logger"
|
||||
)
|
||||
|
||||
@@ -18,13 +18,13 @@ var (
|
||||
ErrOrdersAlreadyExists = errors.New("order already exists")
|
||||
)
|
||||
|
||||
func (o *orderStore) Get() map[string][]exchange.OrderDetail {
|
||||
func (o *orderStore) Get() map[string][]order.Detail {
|
||||
o.m.Lock()
|
||||
defer o.m.Unlock()
|
||||
return o.Orders
|
||||
}
|
||||
|
||||
func (o *orderStore) exists(order *exchange.OrderDetail) bool {
|
||||
func (o *orderStore) exists(order *order.Detail) bool {
|
||||
r, ok := o.Orders[order.Exchange]
|
||||
if !ok {
|
||||
return false
|
||||
@@ -39,7 +39,7 @@ func (o *orderStore) exists(order *exchange.OrderDetail) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (o *orderStore) Add(order *exchange.OrderDetail) error {
|
||||
func (o *orderStore) Add(order *order.Detail) error {
|
||||
o.m.Lock()
|
||||
defer o.m.Unlock()
|
||||
|
||||
@@ -65,7 +65,7 @@ func (o *orderManager) Start() error {
|
||||
log.Debugln(log.OrderBook, "Order manager starting...")
|
||||
|
||||
o.shutdown = make(chan struct{})
|
||||
o.orderStore.Orders = make(map[string][]exchange.OrderDetail)
|
||||
o.orderStore.Orders = make(map[string][]order.Detail)
|
||||
go o.run()
|
||||
return nil
|
||||
}
|
||||
@@ -100,7 +100,7 @@ func (o *orderManager) gracefulShutdown() {
|
||||
for y := range v {
|
||||
log.Debugf(log.OrderMgr, "order manager: Cancelling order ID %v [%v]",
|
||||
v[y].ID, v[y])
|
||||
err := o.Cancel(k, &exchange.OrderCancellation{
|
||||
err := o.Cancel(k, &order.Cancel{
|
||||
OrderID: v[y].ID,
|
||||
})
|
||||
if err != nil {
|
||||
@@ -149,16 +149,16 @@ func (o *orderManager) run() {
|
||||
|
||||
func (o *orderManager) CancelAllOrders() {}
|
||||
|
||||
func (o *orderManager) Cancel(exchName string, order *exchange.OrderCancellation) error {
|
||||
func (o *orderManager) Cancel(exchName string, cancel *order.Cancel) error {
|
||||
if exchName == "" {
|
||||
return errors.New("order exchange name is empty")
|
||||
}
|
||||
|
||||
if order == nil {
|
||||
if cancel == nil {
|
||||
return errors.New("order cancel param is nil")
|
||||
}
|
||||
|
||||
if order.OrderID == "" {
|
||||
if cancel.OrderID == "" {
|
||||
return errors.New("order id is empty")
|
||||
}
|
||||
|
||||
@@ -167,32 +167,28 @@ func (o *orderManager) Cancel(exchName string, order *exchange.OrderCancellation
|
||||
return errors.New("unable to get exchange by name")
|
||||
}
|
||||
|
||||
if order.AssetType.String() != "" && !exch.GetAssetTypes().Contains(order.AssetType) {
|
||||
if cancel.AssetType.String() != "" && !exch.GetAssetTypes().Contains(cancel.AssetType) {
|
||||
return errors.New("order asset type not supported by exchange")
|
||||
}
|
||||
|
||||
return exch.CancelOrder(order)
|
||||
return exch.CancelOrder(cancel)
|
||||
}
|
||||
|
||||
func (o *orderManager) Submit(exchName string, order *exchange.OrderSubmission) (*orderSubmitResponse, error) {
|
||||
func (o *orderManager) Submit(exchName string, newOrder *order.Submit) (*orderSubmitResponse, error) {
|
||||
if exchName == "" {
|
||||
return nil, errors.New("order exchange name must be specified")
|
||||
}
|
||||
|
||||
if order == nil {
|
||||
return nil, exchange.ErrOrderSubmissionIsNil
|
||||
}
|
||||
|
||||
if err := order.Validate(); err != nil {
|
||||
if err := newOrder.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if o.cfg.EnforceLimitConfig {
|
||||
if !o.cfg.AllowMarketOrders && order.OrderType == exchange.MarketOrderType {
|
||||
if !o.cfg.AllowMarketOrders && newOrder.OrderType == order.Market {
|
||||
return nil, errors.New("order market type is not allowed")
|
||||
}
|
||||
|
||||
if o.cfg.LimitAmount > 0 && order.Amount > o.cfg.LimitAmount {
|
||||
if o.cfg.LimitAmount > 0 && newOrder.Amount > o.cfg.LimitAmount {
|
||||
return nil, errors.New("order limit exceeds allowed limit")
|
||||
}
|
||||
|
||||
@@ -201,7 +197,7 @@ func (o *orderManager) Submit(exchName string, order *exchange.OrderSubmission)
|
||||
return nil, errors.New("order exchange not found in allowed list")
|
||||
}
|
||||
|
||||
if len(o.cfg.AllowedPairs) > 0 && !o.cfg.AllowedPairs.Contains(order.Pair, true) {
|
||||
if len(o.cfg.AllowedPairs) > 0 && !o.cfg.AllowedPairs.Contains(newOrder.Pair, true) {
|
||||
return nil, errors.New("order pair not found in allowed list")
|
||||
}
|
||||
}
|
||||
@@ -213,10 +209,12 @@ func (o *orderManager) Submit(exchName string, order *exchange.OrderSubmission)
|
||||
|
||||
id, err := common.GetV4UUID()
|
||||
if err != nil {
|
||||
log.Warnf(log.OrderMgr, "Order manager: Unable to generate UUID. Err: %s\n", err)
|
||||
log.Warnf(log.OrderMgr,
|
||||
"Order manager: Unable to generate UUID. Err: %s\n",
|
||||
err)
|
||||
}
|
||||
|
||||
result, err := exch.SubmitOrder(order)
|
||||
result, err := exch.SubmitOrder(newOrder)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -226,7 +224,15 @@ func (o *orderManager) Submit(exchName string, order *exchange.OrderSubmission)
|
||||
}
|
||||
|
||||
msg := fmt.Sprintf("Order manager: Exchange %s submitted order ID=%v [Ours: %v] pair=%v price=%v amount=%v side=%v type=%v.",
|
||||
exchName, result.OrderID, id.String(), order.Pair, order.Price, order.Amount, order.OrderSide, order.OrderType)
|
||||
exchName,
|
||||
result.OrderID,
|
||||
id.String(),
|
||||
newOrder.Pair,
|
||||
newOrder.Price,
|
||||
newOrder.Amount,
|
||||
newOrder.OrderSide,
|
||||
newOrder.OrderType)
|
||||
|
||||
log.Debugln(log.OrderMgr, msg)
|
||||
Bot.CommsManager.PushEvent(base.Event{
|
||||
Type: "order",
|
||||
@@ -234,7 +240,7 @@ func (o *orderManager) Submit(exchName string, order *exchange.OrderSubmission)
|
||||
})
|
||||
|
||||
return &orderSubmitResponse{
|
||||
SubmitOrderResponse: exchange.SubmitOrderResponse{
|
||||
SubmitResponse: order.SubmitResponse{
|
||||
OrderID: result.OrderID,
|
||||
},
|
||||
OurOrderID: id.String(),
|
||||
@@ -246,9 +252,9 @@ func (o *orderManager) processOrders() {
|
||||
for x := range authExchanges {
|
||||
log.Debugf(log.OrderMgr, "Order manager: Procesing orders for exchange %v.\n", authExchanges[x])
|
||||
exch := GetExchangeByName(authExchanges[x])
|
||||
req := exchange.GetOrdersRequest{
|
||||
OrderSide: exchange.AnyOrderSide,
|
||||
OrderType: exchange.AnyOrderType,
|
||||
req := order.GetOrdersRequest{
|
||||
OrderSide: order.AnySide,
|
||||
OrderType: order.AnyType,
|
||||
}
|
||||
result, err := exch.GetActiveOrders(&req)
|
||||
if err != nil {
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
)
|
||||
|
||||
type orderManagerConfig struct {
|
||||
@@ -19,7 +19,7 @@ type orderManagerConfig struct {
|
||||
|
||||
type orderStore struct {
|
||||
m sync.Mutex
|
||||
Orders map[string][]exchange.OrderDetail
|
||||
Orders map[string][]order.Detail
|
||||
}
|
||||
|
||||
type orderManager struct {
|
||||
@@ -31,6 +31,6 @@ type orderManager struct {
|
||||
}
|
||||
|
||||
type orderSubmitResponse struct {
|
||||
exchange.SubmitOrderResponse
|
||||
order.SubmitResponse
|
||||
OurOrderID string
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/database/models/postgres"
|
||||
"github.com/thrasher-corp/gocryptotrader/database/models/sqlite3"
|
||||
"github.com/thrasher-corp/gocryptotrader/database/repository/audit"
|
||||
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/ticker"
|
||||
"github.com/thrasher-corp/gocryptotrader/gctrpc"
|
||||
@@ -621,7 +621,7 @@ func (s *RPCServer) GetOrders(ctx context.Context, r *gctrpc.GetOrdersRequest) (
|
||||
return nil, errors.New("exchange is not loaded/doesn't exist")
|
||||
}
|
||||
|
||||
resp, err := exch.GetActiveOrders(&exchange.GetOrdersRequest{})
|
||||
resp, err := exch.GetActiveOrders(&order.GetOrdersRequest{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -634,10 +634,10 @@ func (s *RPCServer) GetOrders(ctx context.Context, r *gctrpc.GetOrdersRequest) (
|
||||
BaseCurrency: resp[x].CurrencyPair.Base.String(),
|
||||
QuoteCurrency: resp[x].CurrencyPair.Quote.String(),
|
||||
AssetType: asset.Spot.String(),
|
||||
OrderType: resp[x].OrderType.ToString(),
|
||||
OrderSide: resp[x].OrderSide.ToString(),
|
||||
OrderType: resp[x].OrderType.String(),
|
||||
OrderSide: resp[x].OrderSide.String(),
|
||||
CreationTime: resp[x].OrderDate.Unix(),
|
||||
Status: resp[x].Status,
|
||||
Status: resp[x].Status.String(),
|
||||
Price: resp[x].Price,
|
||||
Amount: resp[x].Amount,
|
||||
})
|
||||
@@ -660,10 +660,10 @@ func (s *RPCServer) SubmitOrder(ctx context.Context, r *gctrpc.SubmitOrderReques
|
||||
}
|
||||
|
||||
p := currency.NewPairFromStrings(r.Pair.Base, r.Pair.Quote)
|
||||
submission := &exchange.OrderSubmission{
|
||||
submission := &order.Submit{
|
||||
Pair: p,
|
||||
OrderSide: exchange.OrderSide(r.Side),
|
||||
OrderType: exchange.OrderType(r.OrderType),
|
||||
OrderSide: order.Side(r.Side),
|
||||
OrderType: order.Type(r.OrderType),
|
||||
Amount: r.Amount,
|
||||
Price: r.Price,
|
||||
ClientID: r.ClientId,
|
||||
@@ -690,8 +690,8 @@ func (s *RPCServer) SimulateOrder(ctx context.Context, r *gctrpc.SimulateOrderRe
|
||||
}
|
||||
|
||||
var buy = true
|
||||
if !strings.EqualFold(r.Side, exchange.BuyOrderSide.ToString()) &&
|
||||
!strings.EqualFold(r.Side, exchange.BidOrderSide.ToString()) {
|
||||
if !strings.EqualFold(r.Side, order.Buy.String()) &&
|
||||
!strings.EqualFold(r.Side, order.Bid.String()) {
|
||||
buy = false
|
||||
}
|
||||
|
||||
@@ -727,8 +727,8 @@ func (s *RPCServer) WhaleBomb(ctx context.Context, r *gctrpc.WhaleBombRequest) (
|
||||
}
|
||||
|
||||
var buy = true
|
||||
if !strings.EqualFold(r.Side, exchange.BuyOrderSide.ToString()) &&
|
||||
!strings.EqualFold(r.Side, exchange.BidOrderSide.ToString()) {
|
||||
if !strings.EqualFold(r.Side, order.Buy.String()) &&
|
||||
!strings.EqualFold(r.Side, order.Bid.String()) {
|
||||
buy = false
|
||||
}
|
||||
|
||||
@@ -757,10 +757,10 @@ func (s *RPCServer) CancelOrder(ctx context.Context, r *gctrpc.CancelOrderReques
|
||||
return nil, errors.New("exchange is not loaded/doesn't exist")
|
||||
}
|
||||
|
||||
err := exch.CancelOrder(&exchange.OrderCancellation{
|
||||
err := exch.CancelOrder(&order.Cancel{
|
||||
AccountID: r.AccountId,
|
||||
OrderID: r.OrderId,
|
||||
Side: exchange.OrderSide(r.Side),
|
||||
Side: order.Side(r.Side),
|
||||
WalletAddress: r.WalletAddress,
|
||||
})
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/common"
|
||||
"github.com/thrasher-corp/gocryptotrader/common/crypto"
|
||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -345,7 +346,7 @@ func (a *Alphapoint) WithdrawCoins(symbol, product, address string, amount float
|
||||
}
|
||||
|
||||
func (a *Alphapoint) convertOrderTypeToOrderTypeNumber(orderType string) (orderTypeNumber int64) {
|
||||
if orderType == exchange.MarketOrderType.ToString() {
|
||||
if orderType == order.Market.String() {
|
||||
orderTypeNumber = 1
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"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/order"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -412,7 +413,7 @@ func TestCreateOrder(t *testing.T) {
|
||||
return
|
||||
}
|
||||
|
||||
_, err := a.CreateOrder("", "", exchange.LimitOrderType.ToString(), 0.01, 0)
|
||||
_, err := a.CreateOrder("", "", order.Limit.String(), 0.01, 0)
|
||||
if err == nil {
|
||||
t.Error("GetUserInfo() Expected error")
|
||||
}
|
||||
@@ -494,8 +495,8 @@ func TestGetActiveOrders(t *testing.T) {
|
||||
a := &Alphapoint{}
|
||||
a.SetDefaults()
|
||||
|
||||
var getOrdersRequest = exchange.GetOrdersRequest{
|
||||
OrderType: exchange.AnyOrderType,
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
OrderType: order.AnyType,
|
||||
}
|
||||
|
||||
_, err := a.GetActiveOrders(&getOrdersRequest)
|
||||
@@ -510,8 +511,8 @@ func TestGetOrderHistory(t *testing.T) {
|
||||
a := &Alphapoint{}
|
||||
a.SetDefaults()
|
||||
|
||||
var getOrdersRequest = exchange.GetOrdersRequest{
|
||||
OrderType: exchange.AnyOrderType,
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
OrderType: order.AnyType,
|
||||
}
|
||||
|
||||
_, err := a.GetOrderHistory(&getOrdersRequest)
|
||||
@@ -537,14 +538,14 @@ 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{
|
||||
Delimiter: "_",
|
||||
Base: currency.BTC,
|
||||
Quote: currency.USD,
|
||||
},
|
||||
OrderSide: exchange.BuyOrderSide,
|
||||
OrderType: exchange.LimitOrderType,
|
||||
OrderSide: order.Buy,
|
||||
OrderType: order.Limit,
|
||||
Price: 1,
|
||||
Amount: 1,
|
||||
ClientID: "meowOrder",
|
||||
@@ -573,7 +574,7 @@ func TestCancelExchangeOrder(t *testing.T) {
|
||||
|
||||
currencyPair := currency.NewPair(currency.BTC, currency.LTC)
|
||||
|
||||
var orderCancellation = &exchange.OrderCancellation{
|
||||
var orderCancellation = &order.Cancel{
|
||||
OrderID: "1",
|
||||
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
AccountID: "1",
|
||||
@@ -599,7 +600,7 @@ func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
|
||||
currencyPair := currency.NewPair(currency.BTC, currency.LTC)
|
||||
|
||||
var orderCancellation = &exchange.OrderCancellation{
|
||||
var orderCancellation = &order.Cancel{
|
||||
OrderID: "1",
|
||||
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
AccountID: "1",
|
||||
@@ -615,8 +616,8 @@ func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
t.Errorf("Withdraw failed to be placed: %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))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -624,7 +625,7 @@ func TestModifyOrder(t *testing.T) {
|
||||
a := &Alphapoint{}
|
||||
a.SetDefaults()
|
||||
|
||||
_, err := a.ModifyOrder(&exchange.ModifyOrder{})
|
||||
_, err := a.ModifyOrder(&order.Modify{})
|
||||
if err == nil {
|
||||
t.Error("ModifyOrder() Expected error")
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package alphapoint
|
||||
|
||||
import exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
)
|
||||
|
||||
// Response contains general responses from the exchange
|
||||
type Response struct {
|
||||
@@ -198,15 +200,15 @@ type WebsocketTicker struct {
|
||||
}
|
||||
|
||||
// orderSideMap holds order type info based on Alphapoint 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,
|
||||
}
|
||||
|
||||
// orderTypeMap holds order type info based on Alphapoint data
|
||||
var orderTypeMap = map[int]exchange.OrderType{
|
||||
1: exchange.MarketOrderType,
|
||||
2: exchange.LimitOrderType,
|
||||
3: exchange.StopOrderType,
|
||||
6: exchange.TrailingStopOrderType,
|
||||
var orderTypeMap = map[int]order.Type{
|
||||
1: order.Market,
|
||||
2: order.Limit,
|
||||
3: order.Stop,
|
||||
6: order.TrailingStop,
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package alphapoint
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
@@ -11,6 +10,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"
|
||||
@@ -200,23 +200,20 @@ func (a *Alphapoint) GetExchangeHistory(p currency.Pair, assetType asset.Item) (
|
||||
|
||||
// SubmitOrder submits a new order and returns a true value when
|
||||
// successfully submitted
|
||||
func (a *Alphapoint) 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 (a *Alphapoint) SubmitOrder(s *order.Submit) (order.SubmitResponse, error) {
|
||||
var submitOrderResponse order.SubmitResponse
|
||||
if err := s.Validate(); err != nil {
|
||||
return submitOrderResponse, err
|
||||
}
|
||||
|
||||
response, err := a.CreateOrder(order.Pair.String(),
|
||||
order.OrderSide.ToString(),
|
||||
order.OrderSide.ToString(),
|
||||
order.Amount, order.Price)
|
||||
response, err := a.CreateOrder(s.Pair.String(),
|
||||
s.OrderSide.String(),
|
||||
s.OrderSide.String(),
|
||||
s.Amount,
|
||||
s.Price)
|
||||
|
||||
if response > 0 {
|
||||
submitOrderResponse.OrderID = fmt.Sprintf("%v", response)
|
||||
submitOrderResponse.OrderID = strconv.FormatInt(response, 10)
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
@@ -228,25 +225,23 @@ func (a *Alphapoint) SubmitOrder(order *exchange.OrderSubmission) (exchange.Subm
|
||||
|
||||
// ModifyOrder will allow of changing orderbook placement and limit to
|
||||
// market conversion
|
||||
func (a *Alphapoint) ModifyOrder(_ *exchange.ModifyOrder) (string, error) {
|
||||
func (a *Alphapoint) ModifyOrder(_ *order.Modify) (string, error) {
|
||||
return "", common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
// CancelOrder cancels an order by its corresponding ID number
|
||||
func (a *Alphapoint) CancelOrder(order *exchange.OrderCancellation) error {
|
||||
func (a *Alphapoint) CancelOrder(order *order.Cancel) error {
|
||||
orderIDInt, err := strconv.ParseInt(order.OrderID, 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = a.CancelExistingOrder(orderIDInt, order.AccountID)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// CancelAllOrders cancels all orders for a given account
|
||||
func (a *Alphapoint) CancelAllOrders(orderCancellation *exchange.OrderCancellation) (exchange.CancelAllOrdersResponse, error) {
|
||||
return exchange.CancelAllOrdersResponse{},
|
||||
func (a *Alphapoint) CancelAllOrders(orderCancellation *order.Cancel) (order.CancelAllResponse, error) {
|
||||
return order.CancelAllResponse{},
|
||||
a.CancelAllExistingOrders(orderCancellation.AccountID)
|
||||
}
|
||||
|
||||
@@ -311,84 +306,84 @@ func (a *Alphapoint) GetFeeByType(feeBuilder *exchange.FeeBuilder) (float64, err
|
||||
|
||||
// GetActiveOrders retrieves any orders that are active/open
|
||||
// This function is not concurrency safe due to orderSide/orderType maps
|
||||
func (a *Alphapoint) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
func (a *Alphapoint) GetActiveOrders(req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
resp, err := a.GetOrders()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var orders []exchange.OrderDetail
|
||||
var orders []order.Detail
|
||||
for x := range resp {
|
||||
for _, order := range resp[x].OpenOrders {
|
||||
if order.State != 1 {
|
||||
for y := range resp[x].OpenOrders {
|
||||
if resp[x].OpenOrders[y].State != 1 {
|
||||
continue
|
||||
}
|
||||
|
||||
orderDetail := exchange.OrderDetail{
|
||||
Amount: order.QtyTotal,
|
||||
orderDetail := order.Detail{
|
||||
Amount: resp[x].OpenOrders[y].QtyTotal,
|
||||
Exchange: a.Name,
|
||||
AccountID: fmt.Sprintf("%v", order.AccountID),
|
||||
ID: fmt.Sprintf("%v", order.ServerOrderID),
|
||||
Price: order.Price,
|
||||
RemainingAmount: order.QtyRemaining,
|
||||
AccountID: strconv.FormatInt(int64(resp[x].OpenOrders[y].AccountID), 10),
|
||||
ID: strconv.FormatInt(int64(resp[x].OpenOrders[y].ServerOrderID), 10),
|
||||
Price: resp[x].OpenOrders[y].Price,
|
||||
RemainingAmount: resp[x].OpenOrders[y].QtyRemaining,
|
||||
}
|
||||
|
||||
orderDetail.OrderSide = orderSideMap[order.Side]
|
||||
orderDetail.OrderDate = time.Unix(order.ReceiveTime, 0)
|
||||
orderDetail.OrderType = orderTypeMap[order.OrderType]
|
||||
orderDetail.OrderSide = orderSideMap[resp[x].OpenOrders[y].Side]
|
||||
orderDetail.OrderDate = time.Unix(resp[x].OpenOrders[y].ReceiveTime, 0)
|
||||
orderDetail.OrderType = orderTypeMap[resp[x].OpenOrders[y].OrderType]
|
||||
if orderDetail.OrderType == "" {
|
||||
orderDetail.OrderType = exchange.UnknownOrderType
|
||||
orderDetail.OrderType = order.Unknown
|
||||
}
|
||||
|
||||
orders = append(orders, orderDetail)
|
||||
}
|
||||
}
|
||||
|
||||
exchange.FilterOrdersByType(&orders, getOrdersRequest.OrderType)
|
||||
exchange.FilterOrdersBySide(&orders, getOrdersRequest.OrderSide)
|
||||
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks, getOrdersRequest.EndTicks)
|
||||
order.FilterOrdersByType(&orders, req.OrderType)
|
||||
order.FilterOrdersBySide(&orders, req.OrderSide)
|
||||
order.FilterOrdersByTickRange(&orders, req.StartTicks, req.EndTicks)
|
||||
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 (a *Alphapoint) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
func (a *Alphapoint) GetOrderHistory(req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
resp, err := a.GetOrders()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var orders []exchange.OrderDetail
|
||||
var orders []order.Detail
|
||||
for x := range resp {
|
||||
for _, order := range resp[x].OpenOrders {
|
||||
if order.State == 1 {
|
||||
for y := range resp[x].OpenOrders {
|
||||
if resp[x].OpenOrders[y].State == 1 {
|
||||
continue
|
||||
}
|
||||
|
||||
orderDetail := exchange.OrderDetail{
|
||||
Amount: order.QtyTotal,
|
||||
AccountID: fmt.Sprintf("%v", order.AccountID),
|
||||
orderDetail := order.Detail{
|
||||
Amount: resp[x].OpenOrders[y].QtyTotal,
|
||||
AccountID: strconv.FormatInt(int64(resp[x].OpenOrders[y].AccountID), 10),
|
||||
Exchange: a.Name,
|
||||
ID: fmt.Sprintf("%v", order.ServerOrderID),
|
||||
Price: order.Price,
|
||||
RemainingAmount: order.QtyRemaining,
|
||||
ID: strconv.FormatInt(int64(resp[x].OpenOrders[y].ServerOrderID), 10),
|
||||
Price: resp[x].OpenOrders[y].Price,
|
||||
RemainingAmount: resp[x].OpenOrders[y].QtyRemaining,
|
||||
}
|
||||
|
||||
orderDetail.OrderSide = orderSideMap[order.Side]
|
||||
orderDetail.OrderDate = time.Unix(order.ReceiveTime, 0)
|
||||
orderDetail.OrderType = orderTypeMap[order.OrderType]
|
||||
orderDetail.OrderSide = orderSideMap[resp[x].OpenOrders[y].Side]
|
||||
orderDetail.OrderDate = time.Unix(resp[x].OpenOrders[y].ReceiveTime, 0)
|
||||
orderDetail.OrderType = orderTypeMap[resp[x].OpenOrders[y].OrderType]
|
||||
if orderDetail.OrderType == "" {
|
||||
orderDetail.OrderType = exchange.UnknownOrderType
|
||||
orderDetail.OrderType = order.Unknown
|
||||
}
|
||||
|
||||
orders = append(orders, orderDetail)
|
||||
}
|
||||
}
|
||||
|
||||
exchange.FilterOrdersByType(&orders, getOrdersRequest.OrderType)
|
||||
exchange.FilterOrdersBySide(&orders, getOrdersRequest.OrderSide)
|
||||
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks, getOrdersRequest.EndTicks)
|
||||
order.FilterOrdersByType(&orders, req.OrderType)
|
||||
order.FilterOrdersBySide(&orders, req.OrderSide)
|
||||
order.FilterOrdersByTickRange(&orders, req.StartTicks, req.EndTicks)
|
||||
return orders, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,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"
|
||||
)
|
||||
|
||||
// Please supply your own keys here for due diligence testing
|
||||
@@ -180,8 +181,8 @@ func TestFormatWithdrawPermissions(t *testing.T) {
|
||||
|
||||
func TestGetActiveOrders(t *testing.T) {
|
||||
t.Parallel()
|
||||
var getOrdersRequest = exchange.GetOrdersRequest{
|
||||
OrderType: exchange.AnyOrderType,
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
OrderType: order.AnyType,
|
||||
}
|
||||
|
||||
_, err := a.GetActiveOrders(&getOrdersRequest)
|
||||
@@ -197,8 +198,8 @@ func TestGetActiveOrders(t *testing.T) {
|
||||
|
||||
func TestGetOrderHistory(t *testing.T) {
|
||||
t.Parallel()
|
||||
var getOrdersRequest = exchange.GetOrdersRequest{
|
||||
OrderType: exchange.AnyOrderType,
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
OrderType: order.AnyType,
|
||||
}
|
||||
|
||||
_, err := a.GetOrderHistory(&getOrdersRequest)
|
||||
@@ -225,14 +226,14 @@ 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{
|
||||
Delimiter: "_",
|
||||
Base: currency.BTC,
|
||||
Quote: currency.USD,
|
||||
},
|
||||
OrderSide: exchange.BuyOrderSide,
|
||||
OrderType: exchange.MarketOrderType,
|
||||
OrderSide: order.Buy,
|
||||
OrderType: order.Market,
|
||||
Price: 1,
|
||||
Amount: 1,
|
||||
ClientID: "meowOrder",
|
||||
@@ -254,7 +255,7 @@ func TestCancelExchangeOrder(t *testing.T) {
|
||||
|
||||
currencyPair := currency.NewPair(currency.BTC, currency.LTC)
|
||||
|
||||
var orderCancellation = &exchange.OrderCancellation{
|
||||
var orderCancellation = &order.Cancel{
|
||||
OrderID: "1",
|
||||
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
AccountID: "1",
|
||||
@@ -280,7 +281,7 @@ func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
|
||||
currencyPair := currency.NewPair(currency.BTC, currency.LTC)
|
||||
|
||||
var orderCancellation = &exchange.OrderCancellation{
|
||||
var orderCancellation = &order.Cancel{
|
||||
OrderID: "1",
|
||||
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
AccountID: "1",
|
||||
@@ -297,8 +298,8 @@ func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
t.Errorf("QA pass needs to be completed and mock needs to be updated error cannot be nil")
|
||||
}
|
||||
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -317,7 +318,7 @@ func TestGetAccountInfo(t *testing.T) {
|
||||
|
||||
func TestModifyOrder(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := a.ModifyOrder(&exchange.ModifyOrder{})
|
||||
_, err := a.ModifyOrder(&order.Modify{})
|
||||
if err == nil {
|
||||
t.Error("ModifyOrder() Expected error")
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
@@ -319,33 +320,29 @@ func (a *ANX) GetExchangeHistory(p currency.Pair, assetType asset.Item) ([]excha
|
||||
}
|
||||
|
||||
// SubmitOrder submits a new order
|
||||
func (a *ANX) 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 (a *ANX) SubmitOrder(s *order.Submit) (order.SubmitResponse, error) {
|
||||
var submitOrderResponse order.SubmitResponse
|
||||
if err := s.Validate(); err != nil {
|
||||
return submitOrderResponse, err
|
||||
}
|
||||
|
||||
var isBuying bool
|
||||
var limitPriceInSettlementCurrency float64
|
||||
|
||||
if order.OrderSide == exchange.BuyOrderSide {
|
||||
if s.OrderSide == order.Buy {
|
||||
isBuying = true
|
||||
}
|
||||
|
||||
if order.OrderType == exchange.LimitOrderType {
|
||||
limitPriceInSettlementCurrency = order.Price
|
||||
if s.OrderType == order.Limit {
|
||||
limitPriceInSettlementCurrency = s.Price
|
||||
}
|
||||
|
||||
response, err := a.NewOrder(order.OrderType.ToString(),
|
||||
response, err := a.NewOrder(s.OrderType.String(),
|
||||
isBuying,
|
||||
order.Pair.Base.String(),
|
||||
order.Amount,
|
||||
order.Pair.Quote.String(),
|
||||
order.Amount,
|
||||
s.Pair.Base.String(),
|
||||
s.Amount,
|
||||
s.Pair.Quote.String(),
|
||||
s.Amount,
|
||||
limitPriceInSettlementCurrency,
|
||||
false,
|
||||
"",
|
||||
@@ -364,21 +361,21 @@ func (a *ANX) SubmitOrder(order *exchange.OrderSubmission) (exchange.SubmitOrder
|
||||
|
||||
// ModifyOrder will allow of changing orderbook placement and limit to
|
||||
// market conversion
|
||||
func (a *ANX) ModifyOrder(action *exchange.ModifyOrder) (string, error) {
|
||||
func (a *ANX) ModifyOrder(action *order.Modify) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// CancelOrder cancels an order by its corresponding ID number
|
||||
func (a *ANX) CancelOrder(order *exchange.OrderCancellation) error {
|
||||
func (a *ANX) CancelOrder(order *order.Cancel) error {
|
||||
orderIDs := []string{order.OrderID}
|
||||
_, err := a.CancelOrderByIDs(orderIDs)
|
||||
return err
|
||||
}
|
||||
|
||||
// CancelAllOrders cancels all orders associated with a currency pair
|
||||
func (a *ANX) CancelAllOrders(_ *exchange.OrderCancellation) (exchange.CancelAllOrdersResponse, error) {
|
||||
cancelAllOrdersResponse := exchange.CancelAllOrdersResponse{
|
||||
OrderStatus: make(map[string]string),
|
||||
func (a *ANX) CancelAllOrders(_ *order.Cancel) (order.CancelAllResponse, error) {
|
||||
cancelAllOrdersResponse := order.CancelAllResponse{
|
||||
Status: make(map[string]string),
|
||||
}
|
||||
placedOrders, err := a.GetOrderList(true)
|
||||
if err != nil {
|
||||
@@ -397,7 +394,7 @@ func (a *ANX) CancelAllOrders(_ *exchange.OrderCancellation) (exchange.CancelAll
|
||||
|
||||
for _, order := range resp.OrderCancellationResponses {
|
||||
if order.Error != CancelRequestSubmitted {
|
||||
cancelAllOrdersResponse.OrderStatus[order.UUID] = order.Error
|
||||
cancelAllOrdersResponse.Status[order.UUID] = order.Error
|
||||
}
|
||||
}
|
||||
|
||||
@@ -405,8 +402,8 @@ func (a *ANX) CancelAllOrders(_ *exchange.OrderCancellation) (exchange.CancelAll
|
||||
}
|
||||
|
||||
// GetOrderInfo returns information on a current open order
|
||||
func (a *ANX) GetOrderInfo(orderID string) (exchange.OrderDetail, error) {
|
||||
var orderDetail exchange.OrderDetail
|
||||
func (a *ANX) GetOrderInfo(orderID string) (order.Detail, error) {
|
||||
var orderDetail order.Detail
|
||||
return orderDetail, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
@@ -450,18 +447,18 @@ func (a *ANX) GetFeeByType(feeBuilder *exchange.FeeBuilder) (float64, error) {
|
||||
}
|
||||
|
||||
// GetActiveOrders retrieves any orders that are active/open
|
||||
func (a *ANX) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
func (a *ANX) GetActiveOrders(getOrdersRequest *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
resp, err := a.GetOrderList(true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var orders []exchange.OrderDetail
|
||||
var orders []order.Detail
|
||||
for i := range resp {
|
||||
orderDate := time.Unix(resp[i].Timestamp, 0)
|
||||
orderType := exchange.OrderType(strings.ToUpper(resp[i].OrderType))
|
||||
orderType := order.Type(strings.ToUpper(resp[i].OrderType))
|
||||
|
||||
orderDetail := exchange.OrderDetail{
|
||||
orderDetail := order.Detail{
|
||||
Amount: resp[i].TradedCurrencyAmount,
|
||||
CurrencyPair: currency.NewPairWithDelimiter(resp[i].TradedCurrency,
|
||||
resp[i].SettlementCurrency,
|
||||
@@ -471,40 +468,40 @@ func (a *ANX) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([]ex
|
||||
ID: resp[i].OrderID,
|
||||
OrderType: orderType,
|
||||
Price: resp[i].SettlementCurrencyAmount,
|
||||
Status: resp[i].OrderStatus,
|
||||
Status: order.Status(resp[i].OrderStatus),
|
||||
}
|
||||
|
||||
orders = append(orders, orderDetail)
|
||||
}
|
||||
|
||||
exchange.FilterOrdersByType(&orders, getOrdersRequest.OrderType)
|
||||
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks,
|
||||
order.FilterOrdersByType(&orders, getOrdersRequest.OrderType)
|
||||
order.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks,
|
||||
getOrdersRequest.EndTicks)
|
||||
exchange.FilterOrdersByCurrencies(&orders, getOrdersRequest.Currencies)
|
||||
order.FilterOrdersByCurrencies(&orders, getOrdersRequest.Currencies)
|
||||
return orders, nil
|
||||
}
|
||||
|
||||
// GetOrderHistory retrieves account order information
|
||||
// Can Limit response to specific order status
|
||||
func (a *ANX) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
func (a *ANX) GetOrderHistory(req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
resp, err := a.GetOrderList(false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var orders []exchange.OrderDetail
|
||||
var orders []order.Detail
|
||||
for i := range resp {
|
||||
orderDate := time.Unix(resp[i].Timestamp, 0)
|
||||
orderType := exchange.OrderType(strings.ToUpper(resp[i].OrderType))
|
||||
orderType := order.Type(strings.ToUpper(resp[i].OrderType))
|
||||
|
||||
orderDetail := exchange.OrderDetail{
|
||||
orderDetail := order.Detail{
|
||||
Amount: resp[i].TradedCurrencyAmount,
|
||||
OrderDate: orderDate,
|
||||
Exchange: a.Name,
|
||||
ID: resp[i].OrderID,
|
||||
OrderType: orderType,
|
||||
Price: resp[i].SettlementCurrencyAmount,
|
||||
Status: resp[i].OrderStatus,
|
||||
Status: order.Status(resp[i].OrderStatus),
|
||||
CurrencyPair: currency.NewPairWithDelimiter(resp[i].TradedCurrency,
|
||||
resp[i].SettlementCurrency,
|
||||
a.GetPairFormat(asset.Spot, false).Delimiter),
|
||||
@@ -513,10 +510,9 @@ func (a *ANX) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([]ex
|
||||
orders = append(orders, orderDetail)
|
||||
}
|
||||
|
||||
exchange.FilterOrdersByType(&orders, getOrdersRequest.OrderType)
|
||||
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks,
|
||||
getOrdersRequest.EndTicks)
|
||||
exchange.FilterOrdersByCurrencies(&orders, getOrdersRequest.Currencies)
|
||||
order.FilterOrdersByType(&orders, req.OrderType)
|
||||
order.FilterOrdersByTickRange(&orders, req.StartTicks, req.EndTicks)
|
||||
order.FilterOrdersByCurrencies(&orders, req.Currencies)
|
||||
return orders, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,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"
|
||||
)
|
||||
|
||||
// Please supply your own keys here for due diligence testing
|
||||
@@ -292,8 +293,8 @@ func TestFormatWithdrawPermissions(t *testing.T) {
|
||||
func TestGetActiveOrders(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var getOrdersRequest = exchange.GetOrdersRequest{
|
||||
OrderType: exchange.AnyOrderType,
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
OrderType: order.AnyType,
|
||||
}
|
||||
_, err := b.GetActiveOrders(&getOrdersRequest)
|
||||
if err == nil {
|
||||
@@ -318,8 +319,8 @@ func TestGetActiveOrders(t *testing.T) {
|
||||
func TestGetOrderHistory(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var getOrdersRequest = exchange.GetOrdersRequest{
|
||||
OrderType: exchange.AnyOrderType,
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
OrderType: order.AnyType,
|
||||
}
|
||||
|
||||
_, err := b.GetOrderHistory(&getOrdersRequest)
|
||||
@@ -352,14 +353,14 @@ 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{
|
||||
Delimiter: "_",
|
||||
Base: currency.LTC,
|
||||
Quote: currency.BTC,
|
||||
},
|
||||
OrderSide: exchange.BuyOrderSide,
|
||||
OrderType: exchange.MarketOrderType,
|
||||
OrderSide: order.Buy,
|
||||
OrderType: order.Market,
|
||||
Price: 1,
|
||||
Amount: 1000000000,
|
||||
ClientID: "meowOrder",
|
||||
@@ -383,7 +384,7 @@ func TestCancelExchangeOrder(t *testing.T) {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
var orderCancellation = &exchange.OrderCancellation{
|
||||
var orderCancellation = &order.Cancel{
|
||||
OrderID: "1",
|
||||
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
AccountID: "1",
|
||||
@@ -408,7 +409,7 @@ func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
var orderCancellation = &exchange.OrderCancellation{
|
||||
var orderCancellation = &order.Cancel{
|
||||
OrderID: "1",
|
||||
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
AccountID: "1",
|
||||
@@ -443,7 +444,7 @@ func TestGetAccountInfo(t *testing.T) {
|
||||
func TestModifyOrder(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
_, err := b.ModifyOrder(&exchange.ModifyOrder{})
|
||||
_, err := b.ModifyOrder(&order.Modify{})
|
||||
if err == nil {
|
||||
t.Error("ModifyOrder() error cannot be nil")
|
||||
}
|
||||
|
||||
@@ -13,6 +13,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"
|
||||
@@ -182,7 +183,10 @@ func (b *Binance) Start(wg *sync.WaitGroup) {
|
||||
func (b *Binance) Run() {
|
||||
if b.Verbose {
|
||||
log.Debugf(log.ExchangeSys,
|
||||
"%s Websocket: %s. (url: %s).\n", b.GetName(), common.IsEnabled(b.Websocket.IsEnabled()), b.Websocket.GetWebsocketURL())
|
||||
"%s Websocket: %s. (url: %s).\n",
|
||||
b.GetName(),
|
||||
common.IsEnabled(b.Websocket.IsEnabled()),
|
||||
b.Websocket.GetWebsocketURL())
|
||||
b.PrintEnabledPairs()
|
||||
}
|
||||
|
||||
@@ -196,7 +200,9 @@ func (b *Binance) Run() {
|
||||
|
||||
err := b.UpdatePairs(enabledPairs, asset.Spot, true, true)
|
||||
if err != nil {
|
||||
log.Errorf(log.ExchangeSys, "%s failed to update currencies. Err: %s\n", b.Name, err)
|
||||
log.Errorf(log.ExchangeSys,
|
||||
"%s failed to update currencies. Err: %s\n",
|
||||
b.Name, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,7 +212,10 @@ func (b *Binance) Run() {
|
||||
|
||||
err := b.UpdateTradablePairs(forceUpdate)
|
||||
if err != nil {
|
||||
log.Errorf(log.ExchangeSys, "%s failed to update tradable pairs. Err: %s", b.Name, err)
|
||||
log.Errorf(log.ExchangeSys,
|
||||
"%s failed to update tradable pairs. Err: %s",
|
||||
b.Name,
|
||||
err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -303,14 +312,20 @@ func (b *Binance) UpdateOrderbook(p currency.Pair, assetType asset.Item) (orderb
|
||||
return orderBook, err
|
||||
}
|
||||
|
||||
for _, bids := range orderbookNew.Bids {
|
||||
for x := range orderbookNew.Bids {
|
||||
orderBook.Bids = append(orderBook.Bids,
|
||||
orderbook.Item{Amount: bids.Quantity, Price: bids.Price})
|
||||
orderbook.Item{
|
||||
Amount: orderbookNew.Bids[x].Quantity,
|
||||
Price: orderbookNew.Bids[x].Price,
|
||||
})
|
||||
}
|
||||
|
||||
for _, asks := range orderbookNew.Asks {
|
||||
for x := range orderbookNew.Asks {
|
||||
orderBook.Asks = append(orderBook.Asks,
|
||||
orderbook.Item{Amount: asks.Quantity, Price: asks.Price})
|
||||
orderbook.Item{
|
||||
Amount: orderbookNew.Asks[x].Quantity,
|
||||
Price: orderbookNew.Asks[x].Price,
|
||||
})
|
||||
}
|
||||
|
||||
orderBook.Pair = p
|
||||
@@ -335,19 +350,19 @@ func (b *Binance) GetAccountInfo() (exchange.AccountInfo, error) {
|
||||
}
|
||||
|
||||
var currencyBalance []exchange.AccountCurrencyInfo
|
||||
for _, balance := range raw.Balances {
|
||||
freeCurrency, err := strconv.ParseFloat(balance.Free, 64)
|
||||
for i := range raw.Balances {
|
||||
freeCurrency, err := strconv.ParseFloat(raw.Balances[i].Free, 64)
|
||||
if err != nil {
|
||||
return info, err
|
||||
}
|
||||
|
||||
lockedCurrency, err := strconv.ParseFloat(balance.Locked, 64)
|
||||
lockedCurrency, err := strconv.ParseFloat(raw.Balances[i].Locked, 64)
|
||||
if err != nil {
|
||||
return info, err
|
||||
}
|
||||
|
||||
currencyBalance = append(currencyBalance, exchange.AccountCurrencyInfo{
|
||||
CurrencyName: currency.NewCode(balance.Asset),
|
||||
CurrencyName: currency.NewCode(raw.Balances[i].Asset),
|
||||
TotalValue: freeCurrency + lockedCurrency,
|
||||
Hold: freeCurrency,
|
||||
})
|
||||
@@ -374,28 +389,24 @@ func (b *Binance) GetExchangeHistory(p currency.Pair, assetType asset.Item) ([]e
|
||||
}
|
||||
|
||||
// SubmitOrder submits a new order
|
||||
func (b *Binance) 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 *Binance) SubmitOrder(s *order.Submit) (order.SubmitResponse, error) {
|
||||
var submitOrderResponse order.SubmitResponse
|
||||
if err := s.Validate(); err != nil {
|
||||
return submitOrderResponse, err
|
||||
}
|
||||
|
||||
var sideType string
|
||||
if order.OrderSide == exchange.BuyOrderSide {
|
||||
sideType = exchange.BuyOrderSide.ToString()
|
||||
if s.OrderSide == order.Buy {
|
||||
sideType = order.Buy.String()
|
||||
} else {
|
||||
sideType = exchange.SellOrderSide.ToString()
|
||||
sideType = order.Sell.String()
|
||||
}
|
||||
|
||||
var requestParamsOrderType RequestParamsOrderType
|
||||
switch order.OrderType {
|
||||
case exchange.MarketOrderType:
|
||||
switch s.OrderType {
|
||||
case order.Market:
|
||||
requestParamsOrderType = BinanceRequestParamsOrderMarket
|
||||
case exchange.LimitOrderType:
|
||||
case order.Limit:
|
||||
requestParamsOrderType = BinanceRequestParamsOrderLimit
|
||||
default:
|
||||
submitOrderResponse.IsOrderPlaced = false
|
||||
@@ -403,10 +414,10 @@ func (b *Binance) SubmitOrder(order *exchange.OrderSubmission) (exchange.SubmitO
|
||||
}
|
||||
|
||||
var orderRequest = NewOrderRequest{
|
||||
Symbol: order.Pair.Base.String() + order.Pair.Quote.String(),
|
||||
Symbol: s.Pair.Base.String() + s.Pair.Quote.String(),
|
||||
Side: sideType,
|
||||
Price: order.Price,
|
||||
Quantity: order.Amount,
|
||||
Price: s.Price,
|
||||
Quantity: s.Amount,
|
||||
TradeType: requestParamsOrderType,
|
||||
TimeInForce: BinanceRequestParamsTimeGTC,
|
||||
}
|
||||
@@ -414,7 +425,7 @@ func (b *Binance) SubmitOrder(order *exchange.OrderSubmission) (exchange.SubmitO
|
||||
response, err := b.NewOrder(&orderRequest)
|
||||
|
||||
if response.OrderID > 0 {
|
||||
submitOrderResponse.OrderID = fmt.Sprintf("%v", response.OrderID)
|
||||
submitOrderResponse.OrderID = strconv.FormatInt(response.OrderID, 10)
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
@@ -426,27 +437,28 @@ func (b *Binance) SubmitOrder(order *exchange.OrderSubmission) (exchange.SubmitO
|
||||
|
||||
// ModifyOrder will allow of changing orderbook placement and limit to
|
||||
// market conversion
|
||||
func (b *Binance) ModifyOrder(action *exchange.ModifyOrder) (string, error) {
|
||||
func (b *Binance) ModifyOrder(action *order.Modify) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// CancelOrder cancels an order by its corresponding ID number
|
||||
func (b *Binance) CancelOrder(order *exchange.OrderCancellation) error {
|
||||
func (b *Binance) CancelOrder(order *order.Cancel) error {
|
||||
orderIDInt, err := strconv.ParseInt(order.OrderID, 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = b.CancelExistingOrder(b.FormatExchangeCurrency(order.CurrencyPair,
|
||||
order.AssetType).String(), orderIDInt, order.AccountID)
|
||||
|
||||
order.AssetType).String(),
|
||||
orderIDInt,
|
||||
order.AccountID)
|
||||
return err
|
||||
}
|
||||
|
||||
// CancelAllOrders cancels all orders associated with a currency pair
|
||||
func (b *Binance) CancelAllOrders(_ *exchange.OrderCancellation) (exchange.CancelAllOrdersResponse, error) {
|
||||
cancelAllOrdersResponse := exchange.CancelAllOrdersResponse{
|
||||
OrderStatus: make(map[string]string),
|
||||
func (b *Binance) CancelAllOrders(_ *order.Cancel) (order.CancelAllResponse, error) {
|
||||
cancelAllOrdersResponse := order.CancelAllResponse{
|
||||
Status: make(map[string]string),
|
||||
}
|
||||
openOrders, err := b.OpenOrders("")
|
||||
if err != nil {
|
||||
@@ -454,9 +466,11 @@ func (b *Binance) CancelAllOrders(_ *exchange.OrderCancellation) (exchange.Cance
|
||||
}
|
||||
|
||||
for i := range openOrders {
|
||||
_, err = b.CancelExistingOrder(openOrders[i].Symbol, openOrders[i].OrderID, "")
|
||||
_, err = b.CancelExistingOrder(openOrders[i].Symbol,
|
||||
openOrders[i].OrderID,
|
||||
"")
|
||||
if err != nil {
|
||||
cancelAllOrdersResponse.OrderStatus[strconv.FormatInt(openOrders[i].OrderID, 10)] = err.Error()
|
||||
cancelAllOrdersResponse.Status[strconv.FormatInt(openOrders[i].OrderID, 10)] = err.Error()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -464,8 +478,8 @@ func (b *Binance) CancelAllOrders(_ *exchange.OrderCancellation) (exchange.Cance
|
||||
}
|
||||
|
||||
// GetOrderInfo returns information on a current open order
|
||||
func (b *Binance) GetOrderInfo(orderID string) (exchange.OrderDetail, error) {
|
||||
var orderDetail exchange.OrderDetail
|
||||
func (b *Binance) GetOrderInfo(orderID string) (order.Detail, error) {
|
||||
var orderDetail order.Detail
|
||||
return orderDetail, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
@@ -511,85 +525,87 @@ func (b *Binance) GetFeeByType(feeBuilder *exchange.FeeBuilder) (float64, error)
|
||||
}
|
||||
|
||||
// GetActiveOrders retrieves any orders that are active/open
|
||||
func (b *Binance) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
if len(getOrdersRequest.Currencies) == 0 {
|
||||
func (b *Binance) GetActiveOrders(req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
if len(req.Currencies) == 0 {
|
||||
return nil, errors.New("at least one currency is required to fetch order history")
|
||||
}
|
||||
|
||||
var orders []exchange.OrderDetail
|
||||
for _, c := range getOrdersRequest.Currencies {
|
||||
resp, err := b.OpenOrders(b.FormatExchangeCurrency(c,
|
||||
var orders []order.Detail
|
||||
for x := range req.Currencies {
|
||||
resp, err := b.OpenOrders(b.FormatExchangeCurrency(req.Currencies[x],
|
||||
asset.Spot).String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for i := range resp {
|
||||
orderSide := exchange.OrderSide(strings.ToUpper(resp[i].Side))
|
||||
orderType := exchange.OrderType(strings.ToUpper(resp[i].Type))
|
||||
orderSide := order.Side(strings.ToUpper(resp[i].Side))
|
||||
orderType := order.Type(strings.ToUpper(resp[i].Type))
|
||||
orderDate := time.Unix(0, int64(resp[i].Time)*int64(time.Millisecond))
|
||||
|
||||
orders = append(orders, exchange.OrderDetail{
|
||||
orders = append(orders, order.Detail{
|
||||
Amount: resp[i].OrigQty,
|
||||
OrderDate: orderDate,
|
||||
Exchange: b.Name,
|
||||
ID: fmt.Sprintf("%v", resp[i].OrderID),
|
||||
ID: strconv.FormatInt(resp[i].OrderID, 10),
|
||||
OrderSide: orderSide,
|
||||
OrderType: orderType,
|
||||
Price: resp[i].Price,
|
||||
Status: resp[i].Status,
|
||||
Status: order.Status(resp[i].Status),
|
||||
CurrencyPair: currency.NewPairFromString(resp[i].Symbol),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
exchange.FilterOrdersByType(&orders, getOrdersRequest.OrderType)
|
||||
exchange.FilterOrdersBySide(&orders, getOrdersRequest.OrderSide)
|
||||
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks, getOrdersRequest.EndTicks)
|
||||
order.FilterOrdersByType(&orders, req.OrderType)
|
||||
order.FilterOrdersBySide(&orders, req.OrderSide)
|
||||
order.FilterOrdersByTickRange(&orders, req.StartTicks, req.EndTicks)
|
||||
return orders, nil
|
||||
}
|
||||
|
||||
// GetOrderHistory retrieves account order information
|
||||
// Can Limit response to specific order status
|
||||
func (b *Binance) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
if len(getOrdersRequest.Currencies) == 0 {
|
||||
func (b *Binance) GetOrderHistory(req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
if len(req.Currencies) == 0 {
|
||||
return nil, errors.New("at least one currency is required to fetch order history")
|
||||
}
|
||||
|
||||
var orders []exchange.OrderDetail
|
||||
for _, c := range getOrdersRequest.Currencies {
|
||||
resp, err := b.AllOrders(b.FormatExchangeCurrency(c,
|
||||
asset.Spot).String(), "", "1000")
|
||||
var orders []order.Detail
|
||||
for x := range req.Currencies {
|
||||
resp, err := b.AllOrders(b.FormatExchangeCurrency(req.Currencies[x],
|
||||
asset.Spot).String(),
|
||||
"",
|
||||
"1000")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for i := range resp {
|
||||
orderSide := exchange.OrderSide(strings.ToUpper(resp[i].Side))
|
||||
orderType := exchange.OrderType(strings.ToUpper(resp[i].Type))
|
||||
orderSide := order.Side(strings.ToUpper(resp[i].Side))
|
||||
orderType := order.Type(strings.ToUpper(resp[i].Type))
|
||||
orderDate := time.Unix(0, int64(resp[i].Time)*int64(time.Millisecond))
|
||||
// New orders are covered in GetOpenOrders
|
||||
if resp[i].Status == "NEW" {
|
||||
continue
|
||||
}
|
||||
|
||||
orders = append(orders, exchange.OrderDetail{
|
||||
orders = append(orders, order.Detail{
|
||||
Amount: resp[i].OrigQty,
|
||||
OrderDate: orderDate,
|
||||
Exchange: b.Name,
|
||||
ID: fmt.Sprintf("%v", resp[i].OrderID),
|
||||
ID: strconv.FormatInt(resp[i].OrderID, 10),
|
||||
OrderSide: orderSide,
|
||||
OrderType: orderType,
|
||||
Price: resp[i].Price,
|
||||
CurrencyPair: currency.NewPairFromString(resp[i].Symbol),
|
||||
Status: resp[i].Status,
|
||||
Status: order.Status(resp[i].Status),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
exchange.FilterOrdersByType(&orders, getOrdersRequest.OrderType)
|
||||
exchange.FilterOrdersBySide(&orders, getOrdersRequest.OrderSide)
|
||||
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks, getOrdersRequest.EndTicks)
|
||||
order.FilterOrdersByType(&orders, req.OrderType)
|
||||
order.FilterOrdersBySide(&orders, req.OrderSide)
|
||||
order.FilterOrdersByTickRange(&orders, req.StartTicks, req.EndTicks)
|
||||
return orders, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/common/crypto"
|
||||
"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/websocket/wshandler"
|
||||
log "github.com/thrasher-corp/gocryptotrader/logger"
|
||||
)
|
||||
@@ -362,10 +363,10 @@ func (b *Bitfinex) GetTradesV2(currencyPair string, timestampStart, timestampEnd
|
||||
tempHistory.Amount = data[2].(float64)
|
||||
tempHistory.Price = data[3].(float64)
|
||||
tempHistory.Exchange = b.Name
|
||||
tempHistory.Type = exchange.BuyOrderSide.ToString()
|
||||
tempHistory.Type = order.Buy.String()
|
||||
|
||||
if tempHistory.Amount < 0 {
|
||||
tempHistory.Type = exchange.SellOrderSide.ToString()
|
||||
tempHistory.Type = order.Sell.String()
|
||||
tempHistory.Amount *= -1
|
||||
}
|
||||
|
||||
@@ -582,9 +583,9 @@ func (b *Bitfinex) NewOrder(currencyPair string, amount, price float64, buy bool
|
||||
req["is_hidden"] = hidden
|
||||
|
||||
if buy {
|
||||
req["side"] = exchange.BuyOrderSide.ToLower().ToString()
|
||||
req["side"] = order.Buy.Lower()
|
||||
} else {
|
||||
req["side"] = exchange.SellOrderSide.ToLower().ToString()
|
||||
req["side"] = order.Sell.Lower()
|
||||
}
|
||||
|
||||
return response,
|
||||
@@ -657,9 +658,9 @@ func (b *Bitfinex) ReplaceOrder(orderID int64, symbol string, amount, price floa
|
||||
req["is_hidden"] = hidden
|
||||
|
||||
if buy {
|
||||
req["side"] = exchange.BuyOrderSide.ToLower().ToString()
|
||||
req["side"] = order.Buy.Lower()
|
||||
} else {
|
||||
req["side"] = exchange.SellOrderSide.ToLower().ToString()
|
||||
req["side"] = order.Sell.Lower()
|
||||
}
|
||||
|
||||
return response,
|
||||
|
||||
@@ -12,6 +12,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"
|
||||
)
|
||||
@@ -365,8 +366,12 @@ func TestNewOrder(t *testing.T) {
|
||||
}
|
||||
t.Parallel()
|
||||
|
||||
_, err := b.NewOrder("BTCUSD", 1, 2, true,
|
||||
exchange.LimitOrderType.ToLower().ToString(), false)
|
||||
_, err := b.NewOrder("BTCUSD",
|
||||
1,
|
||||
2,
|
||||
true,
|
||||
order.Limit.Lower(),
|
||||
false)
|
||||
if err == nil {
|
||||
t.Error("NewOrder() Expected error")
|
||||
}
|
||||
@@ -384,8 +389,8 @@ func TestNewOrderMulti(t *testing.T) {
|
||||
Amount: 1,
|
||||
Price: 1,
|
||||
Exchange: "bitfinex",
|
||||
Side: exchange.BuyOrderSide.ToLower().ToString(),
|
||||
Type: exchange.LimitOrderType.ToLower().ToString(),
|
||||
Side: order.Buy.Lower(),
|
||||
Type: order.Limit.Lower(),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -438,7 +443,7 @@ func TestReplaceOrder(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
_, err := b.ReplaceOrder(1337, "BTCUSD",
|
||||
1, 1, true, exchange.LimitOrderType.ToLower().ToString(), false)
|
||||
1, 1, true, order.Limit.Lower(), false)
|
||||
if err == nil {
|
||||
t.Error("ReplaceOrder() Expected error")
|
||||
}
|
||||
@@ -748,8 +753,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)
|
||||
@@ -764,8 +769,8 @@ func TestGetOrderHistory(t *testing.T) {
|
||||
b.SetDefaults()
|
||||
TestSetup(t)
|
||||
|
||||
var getOrdersRequest = exchange.GetOrdersRequest{
|
||||
OrderType: exchange.AnyOrderType,
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
OrderType: order.AnyType,
|
||||
}
|
||||
|
||||
_, err := b.GetOrderHistory(&getOrdersRequest)
|
||||
@@ -789,14 +794,14 @@ func TestSubmitOrder(t *testing.T) {
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
var orderSubmission = &exchange.OrderSubmission{
|
||||
var orderSubmission = &order.Submit{
|
||||
Pair: currency.Pair{
|
||||
Delimiter: "_",
|
||||
Base: currency.BTC,
|
||||
Quote: currency.USD,
|
||||
},
|
||||
OrderSide: exchange.BuyOrderSide,
|
||||
OrderType: exchange.LimitOrderType,
|
||||
OrderSide: order.Buy,
|
||||
OrderType: order.Limit,
|
||||
Price: 1,
|
||||
Amount: 1,
|
||||
ClientID: "meowOrder",
|
||||
@@ -819,7 +824,7 @@ func TestCancelExchangeOrder(t *testing.T) {
|
||||
|
||||
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
|
||||
var orderCancellation = &exchange.OrderCancellation{
|
||||
var orderCancellation = &order.Cancel{
|
||||
OrderID: "1",
|
||||
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
AccountID: "1",
|
||||
@@ -845,7 +850,7 @@ func TestCancelAllExchangeOrdera(t *testing.T) {
|
||||
|
||||
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
|
||||
var orderCancellation = &exchange.OrderCancellation{
|
||||
var orderCancellation = &order.Cancel{
|
||||
OrderID: "1",
|
||||
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
AccountID: "1",
|
||||
@@ -861,13 +866,13 @@ func TestCancelAllExchangeOrdera(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))
|
||||
}
|
||||
}
|
||||
|
||||
func TestModifyOrder(t *testing.T) {
|
||||
_, err := b.ModifyOrder(&exchange.ModifyOrder{})
|
||||
_, err := b.ModifyOrder(&order.Modify{})
|
||||
if err == nil {
|
||||
t.Error("ModifyOrder() Expected error")
|
||||
}
|
||||
|
||||
@@ -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/protocol"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
|
||||
@@ -189,7 +190,9 @@ func (b *Bitfinex) Start(wg *sync.WaitGroup) {
|
||||
func (b *Bitfinex) Run() {
|
||||
if b.Verbose {
|
||||
log.Debugf(log.ExchangeSys,
|
||||
"%s Websocket: %s.", b.GetName(), common.IsEnabled(b.Websocket.IsEnabled()))
|
||||
"%s Websocket: %s.",
|
||||
b.GetName(),
|
||||
common.IsEnabled(b.Websocket.IsEnabled()))
|
||||
b.PrintEnabledPairs()
|
||||
}
|
||||
|
||||
@@ -326,14 +329,14 @@ func (b *Bitfinex) GetAccountInfo() (exchange.AccountInfo, error) {
|
||||
{ID: "trading"},
|
||||
}
|
||||
|
||||
for _, bal := range accountBalance {
|
||||
for x := range accountBalance {
|
||||
for i := range Accounts {
|
||||
if Accounts[i].ID == bal.Type {
|
||||
if Accounts[i].ID == accountBalance[x].Type {
|
||||
Accounts[i].Currencies = append(Accounts[i].Currencies,
|
||||
exchange.AccountCurrencyInfo{
|
||||
CurrencyName: currency.NewCode(bal.Currency),
|
||||
TotalValue: bal.Amount,
|
||||
Hold: bal.Amount - bal.Available,
|
||||
CurrencyName: currency.NewCode(accountBalance[x].Currency),
|
||||
TotalValue: accountBalance[x].Amount,
|
||||
Hold: accountBalance[x].Amount - accountBalance[x].Available,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -356,30 +359,26 @@ func (b *Bitfinex) GetExchangeHistory(p currency.Pair, assetType asset.Item) ([]
|
||||
}
|
||||
|
||||
// SubmitOrder submits a new order
|
||||
func (b *Bitfinex) 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 *Bitfinex) SubmitOrder(s *order.Submit) (order.SubmitResponse, error) {
|
||||
var submitOrderResponse order.SubmitResponse
|
||||
if err := s.Validate(); err != nil {
|
||||
return submitOrderResponse, err
|
||||
}
|
||||
|
||||
var isBuying bool
|
||||
if order.OrderSide == exchange.BuyOrderSide {
|
||||
if s.OrderSide == order.Buy {
|
||||
isBuying = true
|
||||
}
|
||||
b.appendOptionalDelimiter(&order.Pair)
|
||||
response, err := b.NewOrder(order.Pair.String(),
|
||||
order.Amount,
|
||||
order.Price,
|
||||
b.appendOptionalDelimiter(&s.Pair)
|
||||
response, err := b.NewOrder(s.Pair.String(),
|
||||
s.Amount,
|
||||
s.Price,
|
||||
isBuying,
|
||||
order.OrderType.ToString(),
|
||||
s.OrderType.String(),
|
||||
false)
|
||||
|
||||
if response.OrderID > 0 {
|
||||
submitOrderResponse.OrderID = fmt.Sprintf("%v", response.OrderID)
|
||||
submitOrderResponse.OrderID = strconv.FormatInt(response.OrderID, 10)
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
@@ -391,31 +390,29 @@ func (b *Bitfinex) SubmitOrder(order *exchange.OrderSubmission) (exchange.Submit
|
||||
|
||||
// ModifyOrder will allow of changing orderbook placement and limit to
|
||||
// market conversion
|
||||
func (b *Bitfinex) ModifyOrder(action *exchange.ModifyOrder) (string, error) {
|
||||
func (b *Bitfinex) ModifyOrder(action *order.Modify) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// CancelOrder cancels an order by its corresponding ID number
|
||||
func (b *Bitfinex) CancelOrder(order *exchange.OrderCancellation) error {
|
||||
func (b *Bitfinex) CancelOrder(order *order.Cancel) error {
|
||||
orderIDInt, err := strconv.ParseInt(order.OrderID, 10, 64)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = b.CancelExistingOrder(orderIDInt)
|
||||
return err
|
||||
}
|
||||
|
||||
// CancelAllOrders cancels all orders associated with a currency pair
|
||||
func (b *Bitfinex) CancelAllOrders(_ *exchange.OrderCancellation) (exchange.CancelAllOrdersResponse, error) {
|
||||
func (b *Bitfinex) CancelAllOrders(_ *order.Cancel) (order.CancelAllResponse, error) {
|
||||
_, err := b.CancelAllExistingOrders()
|
||||
return exchange.CancelAllOrdersResponse{}, err
|
||||
return order.CancelAllResponse{}, err
|
||||
}
|
||||
|
||||
// GetOrderInfo returns information on a current open order
|
||||
func (b *Bitfinex) GetOrderInfo(orderID string) (exchange.OrderDetail, error) {
|
||||
var orderDetail exchange.OrderDetail
|
||||
func (b *Bitfinex) GetOrderInfo(orderID string) (order.Detail, error) {
|
||||
var orderDetail order.Detail
|
||||
return orderDetail, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
@@ -454,7 +451,7 @@ func (b *Bitfinex) WithdrawCryptocurrencyFunds(withdrawRequest *exchange.CryptoW
|
||||
return "", errors.New("no withdrawID returned. Check order status")
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%v", resp[0].WithdrawalID), err
|
||||
return strconv.FormatInt(resp[0].WithdrawalID, 10), err
|
||||
}
|
||||
|
||||
// WithdrawFiatFunds returns a withdrawal ID when a withdrawal is submitted
|
||||
@@ -511,26 +508,28 @@ func (b *Bitfinex) GetFeeByType(feeBuilder *exchange.FeeBuilder) (float64, error
|
||||
}
|
||||
|
||||
// GetActiveOrders retrieves any orders that are active/open
|
||||
func (b *Bitfinex) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
var orders []exchange.OrderDetail
|
||||
func (b *Bitfinex) GetActiveOrders(req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
var orders []order.Detail
|
||||
resp, err := b.GetOpenOrders()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for i := range resp {
|
||||
orderSide := exchange.OrderSide(strings.ToUpper(resp[i].Side))
|
||||
orderSide := order.Side(strings.ToUpper(resp[i].Side))
|
||||
timestamp, err := strconv.ParseInt(resp[i].Timestamp, 10, 64)
|
||||
if err != nil {
|
||||
log.Warnf(log.ExchangeSys, "Unable to convert timestamp '%v', leaving blank", resp[i].Timestamp)
|
||||
log.Warnf(log.ExchangeSys,
|
||||
"Unable to convert timestamp '%s', leaving blank",
|
||||
resp[i].Timestamp)
|
||||
}
|
||||
orderDate := time.Unix(timestamp, 0)
|
||||
|
||||
orderDetail := exchange.OrderDetail{
|
||||
orderDetail := order.Detail{
|
||||
Amount: resp[i].OriginalAmount,
|
||||
OrderDate: orderDate,
|
||||
Exchange: b.Name,
|
||||
ID: fmt.Sprintf("%v", resp[i].OrderID),
|
||||
ID: strconv.FormatInt(resp[i].OrderID, 10),
|
||||
OrderSide: orderSide,
|
||||
Price: resp[i].Price,
|
||||
RemainingAmount: resp[i].RemainingAmount,
|
||||
@@ -540,56 +539,56 @@ func (b *Bitfinex) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest)
|
||||
|
||||
switch {
|
||||
case resp[i].IsLive:
|
||||
orderDetail.Status = string(exchange.ActiveOrderStatus)
|
||||
orderDetail.Status = order.Active
|
||||
case resp[i].IsCancelled:
|
||||
orderDetail.Status = string(exchange.CancelledOrderStatus)
|
||||
orderDetail.Status = order.Cancelled
|
||||
case resp[i].IsHidden:
|
||||
orderDetail.Status = string(exchange.HiddenOrderStatus)
|
||||
orderDetail.Status = order.Hidden
|
||||
default:
|
||||
orderDetail.Status = string(exchange.UnknownOrderStatus)
|
||||
orderDetail.Status = order.UnknownStatus
|
||||
}
|
||||
|
||||
// API docs discrepency. Example contains prefixed "exchange "
|
||||
// Return type suggests “market” / “limit” / “stop” / “trailing-stop”
|
||||
orderType := strings.Replace(resp[i].Type, "exchange ", "", 1)
|
||||
if orderType == "trailing-stop" {
|
||||
orderDetail.OrderType = exchange.TrailingStopOrderType
|
||||
orderDetail.OrderType = order.TrailingStop
|
||||
} else {
|
||||
orderDetail.OrderType = exchange.OrderType(strings.ToUpper(orderType))
|
||||
orderDetail.OrderType = order.Type(strings.ToUpper(orderType))
|
||||
}
|
||||
|
||||
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
|
||||
func (b *Bitfinex) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
var orders []exchange.OrderDetail
|
||||
func (b *Bitfinex) GetOrderHistory(req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
var orders []order.Detail
|
||||
resp, err := b.GetInactiveOrders()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for i := range resp {
|
||||
orderSide := exchange.OrderSide(strings.ToUpper(resp[i].Side))
|
||||
orderSide := order.Side(strings.ToUpper(resp[i].Side))
|
||||
timestamp, err := strconv.ParseInt(resp[i].Timestamp, 10, 64)
|
||||
if err != nil {
|
||||
log.Warnf(log.ExchangeSys, "Unable to convert timestamp '%v', leaving blank", resp[i].Timestamp)
|
||||
}
|
||||
orderDate := time.Unix(timestamp, 0)
|
||||
|
||||
orderDetail := exchange.OrderDetail{
|
||||
orderDetail := order.Detail{
|
||||
Amount: resp[i].OriginalAmount,
|
||||
OrderDate: orderDate,
|
||||
Exchange: b.Name,
|
||||
ID: fmt.Sprintf("%v", resp[i].OrderID),
|
||||
ID: strconv.FormatInt(resp[i].OrderID, 10),
|
||||
OrderSide: orderSide,
|
||||
Price: resp[i].Price,
|
||||
RemainingAmount: resp[i].RemainingAmount,
|
||||
@@ -599,34 +598,34 @@ func (b *Bitfinex) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest)
|
||||
|
||||
switch {
|
||||
case resp[i].IsLive:
|
||||
orderDetail.Status = string(exchange.ActiveOrderStatus)
|
||||
orderDetail.Status = order.Active
|
||||
case resp[i].IsCancelled:
|
||||
orderDetail.Status = string(exchange.CancelledOrderStatus)
|
||||
orderDetail.Status = order.Cancelled
|
||||
case resp[i].IsHidden:
|
||||
orderDetail.Status = string(exchange.HiddenOrderStatus)
|
||||
orderDetail.Status = order.Hidden
|
||||
default:
|
||||
orderDetail.Status = string(exchange.UnknownOrderStatus)
|
||||
orderDetail.Status = order.UnknownStatus
|
||||
}
|
||||
|
||||
// API docs discrepency. Example contains prefixed "exchange "
|
||||
// Return type suggests “market” / “limit” / “stop” / “trailing-stop”
|
||||
orderType := strings.Replace(resp[i].Type, "exchange ", "", 1)
|
||||
if orderType == "trailing-stop" {
|
||||
orderDetail.OrderType = exchange.TrailingStopOrderType
|
||||
orderDetail.OrderType = order.TrailingStop
|
||||
} else {
|
||||
orderDetail.OrderType = exchange.OrderType(strings.ToUpper(orderType))
|
||||
orderDetail.OrderType = order.Type(strings.ToUpper(orderType))
|
||||
}
|
||||
|
||||
orders = append(orders, orderDetail)
|
||||
}
|
||||
|
||||
exchange.FilterOrdersBySide(&orders, getOrdersRequest.OrderSide)
|
||||
exchange.FilterOrdersByType(&orders, getOrdersRequest.OrderType)
|
||||
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks, getOrdersRequest.EndTicks)
|
||||
for i := range getOrdersRequest.Currencies {
|
||||
b.appendOptionalDelimiter(&getOrdersRequest.Currencies[i])
|
||||
order.FilterOrdersBySide(&orders, req.OrderSide)
|
||||
order.FilterOrdersByType(&orders, req.OrderType)
|
||||
order.FilterOrdersByTickRange(&orders, req.StartTicks, req.EndTicks)
|
||||
for i := range req.Currencies {
|
||||
b.appendOptionalDelimiter(&req.Currencies[i])
|
||||
}
|
||||
exchange.FilterOrdersByCurrencies(&orders, getOrdersRequest.Currencies)
|
||||
order.FilterOrdersByCurrencies(&orders, req.Currencies)
|
||||
return orders, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,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"
|
||||
log "github.com/thrasher-corp/gocryptotrader/logger"
|
||||
)
|
||||
|
||||
@@ -269,8 +270,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)
|
||||
@@ -285,8 +286,8 @@ func TestGetOrderHistory(t *testing.T) {
|
||||
b.SetDefaults()
|
||||
TestSetup(t)
|
||||
|
||||
var getOrdersRequest = exchange.GetOrdersRequest{
|
||||
OrderType: exchange.AnyOrderType,
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
OrderType: order.AnyType,
|
||||
}
|
||||
|
||||
_, err := b.GetOrderHistory(&getOrdersRequest)
|
||||
@@ -309,13 +310,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.BTC,
|
||||
Quote: currency.LTC,
|
||||
},
|
||||
OrderSide: exchange.BuyOrderSide,
|
||||
OrderType: exchange.LimitOrderType,
|
||||
OrderSide: order.Buy,
|
||||
OrderType: order.Limit,
|
||||
Price: 1,
|
||||
Amount: 1,
|
||||
ClientID: "meowOrder",
|
||||
@@ -335,7 +336,7 @@ func TestCancelExchangeOrder(t *testing.T) {
|
||||
}
|
||||
|
||||
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
var orderCancellation = &exchange.OrderCancellation{
|
||||
var orderCancellation = &order.Cancel{
|
||||
OrderID: "1",
|
||||
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
AccountID: "1",
|
||||
@@ -358,7 +359,7 @@ func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
}
|
||||
|
||||
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
var orderCancellation = &exchange.OrderCancellation{
|
||||
var orderCancellation = &order.Cancel{
|
||||
OrderID: "1",
|
||||
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
AccountID: "1",
|
||||
@@ -395,7 +396,7 @@ func TestWithdraw(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestModifyOrder(t *testing.T) {
|
||||
_, err := b.ModifyOrder(&exchange.ModifyOrder{})
|
||||
_, err := b.ModifyOrder(&order.Modify{})
|
||||
if err == nil {
|
||||
t.Error("ModifyOrder() Expected error")
|
||||
}
|
||||
|
||||
@@ -10,6 +10,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"
|
||||
@@ -139,11 +140,14 @@ func (b *Bitflyer) FetchTradablePairs(assetType asset.Item) ([]string, error) {
|
||||
}
|
||||
|
||||
var products []string
|
||||
for _, info := range pairs {
|
||||
if info.Alias != "" && assetType == asset.Futures {
|
||||
products = append(products, info.Alias)
|
||||
} else if info.Alias == "" && assetType == asset.Spot && strings.Contains(info.ProductCode, b.GetPairFormat(assetType, false).Delimiter) {
|
||||
products = append(products, info.ProductCode)
|
||||
for i := range pairs {
|
||||
if pairs[i].Alias != "" && assetType == asset.Futures {
|
||||
products = append(products, pairs[i].Alias)
|
||||
} else if pairs[i].Alias == "" &&
|
||||
assetType == asset.Spot &&
|
||||
strings.Contains(pairs[i].ProductCode,
|
||||
b.GetPairFormat(assetType, false).Delimiter) {
|
||||
products = append(products, pairs[i].ProductCode)
|
||||
}
|
||||
}
|
||||
return products, nil
|
||||
@@ -159,7 +163,10 @@ func (b *Bitflyer) UpdateTradablePairs(forceUpdate bool) error {
|
||||
return err
|
||||
}
|
||||
|
||||
err = b.UpdatePairs(currency.NewPairsFromStrings(pairs), a, false, forceUpdate)
|
||||
err = b.UpdatePairs(currency.NewPairsFromStrings(pairs),
|
||||
a,
|
||||
false,
|
||||
forceUpdate)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -267,31 +274,31 @@ func (b *Bitflyer) GetExchangeHistory(p currency.Pair, assetType asset.Item) ([]
|
||||
}
|
||||
|
||||
// SubmitOrder submits a new order
|
||||
func (b *Bitflyer) SubmitOrder(order *exchange.OrderSubmission) (exchange.SubmitOrderResponse, error) {
|
||||
return exchange.SubmitOrderResponse{}, common.ErrNotYetImplemented
|
||||
func (b *Bitflyer) SubmitOrder(s *order.Submit) (order.SubmitResponse, error) {
|
||||
return order.SubmitResponse{}, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
// ModifyOrder will allow of changing orderbook placement and limit to
|
||||
// market conversion
|
||||
func (b *Bitflyer) ModifyOrder(action *exchange.ModifyOrder) (string, error) {
|
||||
func (b *Bitflyer) ModifyOrder(action *order.Modify) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// CancelOrder cancels an order by its corresponding ID number
|
||||
func (b *Bitflyer) CancelOrder(order *exchange.OrderCancellation) error {
|
||||
func (b *Bitflyer) CancelOrder(order *order.Cancel) error {
|
||||
return common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
// CancelAllOrders cancels all orders associated with a currency pair
|
||||
func (b *Bitflyer) CancelAllOrders(_ *exchange.OrderCancellation) (exchange.CancelAllOrdersResponse, error) {
|
||||
func (b *Bitflyer) CancelAllOrders(_ *order.Cancel) (order.CancelAllResponse, error) {
|
||||
// TODO, implement BitFlyer API
|
||||
b.CancelAllExistingOrders()
|
||||
return exchange.CancelAllOrdersResponse{}, common.ErrNotYetImplemented
|
||||
return order.CancelAllResponse{}, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
// GetOrderInfo returns information on a current open order
|
||||
func (b *Bitflyer) GetOrderInfo(orderID string) (exchange.OrderDetail, error) {
|
||||
var orderDetail exchange.OrderDetail
|
||||
func (b *Bitflyer) GetOrderInfo(orderID string) (order.Detail, error) {
|
||||
var orderDetail order.Detail
|
||||
return orderDetail, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
@@ -324,13 +331,13 @@ func (b *Bitflyer) GetWebsocket() (*wshandler.Websocket, error) {
|
||||
}
|
||||
|
||||
// GetActiveOrders retrieves any orders that are active/open
|
||||
func (b *Bitflyer) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
func (b *Bitflyer) GetActiveOrders(getOrdersRequest *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
return nil, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
// GetOrderHistory retrieves account order information
|
||||
// Can Limit response to specific order status
|
||||
func (b *Bitflyer) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
func (b *Bitflyer) GetOrderHistory(getOrdersRequest *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
return nil, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,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 for due diligence testing
|
||||
@@ -308,9 +309,9 @@ func TestGetActiveOrders(t *testing.T) {
|
||||
b.SetDefaults()
|
||||
TestSetup(t)
|
||||
|
||||
var getOrdersRequest = exchange.GetOrdersRequest{
|
||||
OrderType: exchange.AnyOrderType,
|
||||
OrderSide: exchange.SellOrderSide,
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
OrderType: order.AnyType,
|
||||
OrderSide: order.Sell,
|
||||
}
|
||||
|
||||
_, err := b.GetActiveOrders(&getOrdersRequest)
|
||||
@@ -325,8 +326,8 @@ func TestGetOrderHistory(t *testing.T) {
|
||||
b.SetDefaults()
|
||||
TestSetup(t)
|
||||
|
||||
var getOrdersRequest = exchange.GetOrdersRequest{
|
||||
OrderType: exchange.AnyOrderType,
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
OrderType: order.AnyType,
|
||||
}
|
||||
|
||||
_, err := b.GetOrderHistory(&getOrdersRequest)
|
||||
@@ -351,13 +352,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.BTC,
|
||||
Quote: currency.LTC,
|
||||
},
|
||||
OrderSide: exchange.BuyOrderSide,
|
||||
OrderType: exchange.LimitOrderType,
|
||||
OrderSide: order.Buy,
|
||||
OrderType: order.Limit,
|
||||
Price: 1,
|
||||
Amount: 1,
|
||||
ClientID: "meowOrder",
|
||||
@@ -380,7 +381,7 @@ func TestCancelExchangeOrder(t *testing.T) {
|
||||
|
||||
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
|
||||
var orderCancellation = &exchange.OrderCancellation{
|
||||
var orderCancellation = &order.Cancel{
|
||||
OrderID: "1",
|
||||
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
AccountID: "1",
|
||||
@@ -406,7 +407,7 @@ func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
|
||||
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
|
||||
var orderCancellation = &exchange.OrderCancellation{
|
||||
var orderCancellation = &order.Cancel{
|
||||
OrderID: "1",
|
||||
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
AccountID: "1",
|
||||
@@ -422,8 +423,8 @@ func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
t.Errorf("Could not cancel order: %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))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -444,10 +445,11 @@ func TestGetAccountInfo(t *testing.T) {
|
||||
|
||||
func TestModifyOrder(t *testing.T) {
|
||||
curr := currency.NewPairFromString("BTCUSD")
|
||||
_, err := b.ModifyOrder(&exchange.ModifyOrder{OrderID: "1337",
|
||||
_, err := b.ModifyOrder(&order.Modify{
|
||||
OrderID: "1337",
|
||||
Price: 100,
|
||||
Amount: 1000,
|
||||
OrderSide: exchange.SellOrderSide,
|
||||
Side: order.Sell,
|
||||
CurrencyPair: curr})
|
||||
if err == nil {
|
||||
t.Error("ModifyOrder() Expected error")
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"fmt"
|
||||
"math"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -14,6 +13,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"
|
||||
@@ -180,15 +180,16 @@ func (b *Bithumb) UpdateTicker(p currency.Pair, assetType asset.Item) (ticker.Pr
|
||||
pairs := b.GetEnabledPairs(assetType)
|
||||
for i := range pairs {
|
||||
curr := pairs[i].Base.String()
|
||||
if _, ok := tickers[curr]; !ok {
|
||||
t, ok := tickers[curr]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
tp := ticker.Price{
|
||||
High: tickers[curr].MaxPrice,
|
||||
Low: tickers[curr].MinPrice,
|
||||
Volume: tickers[curr].UnitsTraded24Hr,
|
||||
Open: tickers[curr].OpeningPrice,
|
||||
Close: tickers[curr].ClosingPrice,
|
||||
High: t.MaxPrice,
|
||||
Low: t.MinPrice,
|
||||
Volume: t.UnitsTraded24Hr,
|
||||
Open: t.OpeningPrice,
|
||||
Close: t.ClosingPrice,
|
||||
Pair: pairs[i],
|
||||
}
|
||||
err = ticker.ProcessTicker(b.Name, &tp, assetType)
|
||||
@@ -227,12 +228,20 @@ func (b *Bithumb) UpdateOrderbook(p currency.Pair, assetType asset.Item) (orderb
|
||||
return orderBook, err
|
||||
}
|
||||
|
||||
for _, bids := range orderbookNew.Data.Bids {
|
||||
orderBook.Bids = append(orderBook.Bids, orderbook.Item{Amount: bids.Quantity, Price: bids.Price})
|
||||
for i := range orderbookNew.Data.Bids {
|
||||
orderBook.Bids = append(orderBook.Bids,
|
||||
orderbook.Item{
|
||||
Amount: orderbookNew.Data.Bids[i].Quantity,
|
||||
Price: orderbookNew.Data.Bids[i].Price,
|
||||
})
|
||||
}
|
||||
|
||||
for _, asks := range orderbookNew.Data.Asks {
|
||||
orderBook.Asks = append(orderBook.Asks, orderbook.Item{Amount: asks.Quantity, Price: asks.Price})
|
||||
for i := range orderbookNew.Data.Asks {
|
||||
orderBook.Asks = append(orderBook.Asks,
|
||||
orderbook.Item{
|
||||
Amount: orderbookNew.Data.Asks[i].Quantity,
|
||||
Price: orderbookNew.Data.Asks[i].Price,
|
||||
})
|
||||
}
|
||||
|
||||
orderBook.Pair = p
|
||||
@@ -293,30 +302,26 @@ func (b *Bithumb) GetExchangeHistory(p currency.Pair, assetType asset.Item) ([]e
|
||||
|
||||
// SubmitOrder submits a new order
|
||||
// TODO: Fill this out to support limit orders
|
||||
func (b *Bithumb) 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 *Bithumb) SubmitOrder(s *order.Submit) (order.SubmitResponse, error) {
|
||||
var submitOrderResponse order.SubmitResponse
|
||||
if err := s.Validate(); err != nil {
|
||||
return submitOrderResponse, err
|
||||
}
|
||||
|
||||
var orderID string
|
||||
var err error
|
||||
if order.OrderSide == exchange.BuyOrderSide {
|
||||
if s.OrderSide == order.Buy {
|
||||
var result MarketBuy
|
||||
result, err = b.MarketBuyOrder(order.Pair.Base.String(), order.Amount)
|
||||
result, err = b.MarketBuyOrder(s.Pair.Base.String(), s.Amount)
|
||||
orderID = result.OrderID
|
||||
} else if order.OrderSide == exchange.SellOrderSide {
|
||||
} else if s.OrderSide == order.Sell {
|
||||
var result MarketSell
|
||||
result, err = b.MarketSellOrder(order.Pair.Base.String(), order.Amount)
|
||||
result, err = b.MarketSellOrder(s.Pair.Base.String(), s.Amount)
|
||||
orderID = result.OrderID
|
||||
}
|
||||
|
||||
if orderID != "" {
|
||||
submitOrderResponse.OrderID = fmt.Sprintf("%v", orderID)
|
||||
submitOrderResponse.OrderID = orderID
|
||||
}
|
||||
if err == nil {
|
||||
submitOrderResponse.IsOrderPlaced = true
|
||||
@@ -326,10 +331,10 @@ func (b *Bithumb) SubmitOrder(order *exchange.OrderSubmission) (exchange.SubmitO
|
||||
|
||||
// ModifyOrder will allow of changing orderbook placement and limit to
|
||||
// market conversion
|
||||
func (b *Bithumb) ModifyOrder(action *exchange.ModifyOrder) (string, error) {
|
||||
func (b *Bithumb) ModifyOrder(action *order.Modify) (string, error) {
|
||||
order, err := b.ModifyTrade(action.OrderID,
|
||||
action.CurrencyPair.Base.String(),
|
||||
strings.ToLower(action.OrderSide.ToString()),
|
||||
action.Side.Lower(),
|
||||
action.Amount,
|
||||
int64(action.Price))
|
||||
|
||||
@@ -341,23 +346,23 @@ func (b *Bithumb) ModifyOrder(action *exchange.ModifyOrder) (string, error) {
|
||||
}
|
||||
|
||||
// CancelOrder cancels an order by its corresponding ID number
|
||||
func (b *Bithumb) CancelOrder(order *exchange.OrderCancellation) error {
|
||||
_, err := b.CancelTrade(order.Side.ToString(),
|
||||
func (b *Bithumb) CancelOrder(order *order.Cancel) error {
|
||||
_, err := b.CancelTrade(order.Side.String(),
|
||||
order.OrderID,
|
||||
order.CurrencyPair.Base.String())
|
||||
return err
|
||||
}
|
||||
|
||||
// CancelAllOrders cancels all orders associated with a currency pair
|
||||
func (b *Bithumb) CancelAllOrders(orderCancellation *exchange.OrderCancellation) (exchange.CancelAllOrdersResponse, error) {
|
||||
cancelAllOrdersResponse := exchange.CancelAllOrdersResponse{
|
||||
OrderStatus: make(map[string]string),
|
||||
func (b *Bithumb) CancelAllOrders(orderCancellation *order.Cancel) (order.CancelAllResponse, error) {
|
||||
cancelAllOrdersResponse := order.CancelAllResponse{
|
||||
Status: make(map[string]string),
|
||||
}
|
||||
|
||||
var allOrders []OrderData
|
||||
for _, currency := range b.GetEnabledPairs(asset.Spot) {
|
||||
orders, err := b.GetOrders("",
|
||||
orderCancellation.Side.ToString(),
|
||||
orderCancellation.Side.String(),
|
||||
"100",
|
||||
"",
|
||||
currency.Base.String())
|
||||
@@ -368,11 +373,11 @@ func (b *Bithumb) CancelAllOrders(orderCancellation *exchange.OrderCancellation)
|
||||
}
|
||||
|
||||
for i := range allOrders {
|
||||
_, err := b.CancelTrade(orderCancellation.Side.ToString(),
|
||||
_, err := b.CancelTrade(orderCancellation.Side.String(),
|
||||
allOrders[i].OrderID,
|
||||
orderCancellation.CurrencyPair.Base.String())
|
||||
if err != nil {
|
||||
cancelAllOrdersResponse.OrderStatus[allOrders[i].OrderID] = err.Error()
|
||||
cancelAllOrdersResponse.Status[allOrders[i].OrderID] = err.Error()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -380,8 +385,8 @@ func (b *Bithumb) CancelAllOrders(orderCancellation *exchange.OrderCancellation)
|
||||
}
|
||||
|
||||
// GetOrderInfo returns information on a current open order
|
||||
func (b *Bithumb) GetOrderInfo(orderID string) (exchange.OrderDetail, error) {
|
||||
var orderDetail exchange.OrderDetail
|
||||
func (b *Bithumb) GetOrderInfo(orderID string) (order.Detail, error) {
|
||||
var orderDetail order.Detail
|
||||
return orderDetail, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
@@ -398,7 +403,10 @@ func (b *Bithumb) GetDepositAddress(cryptocurrency currency.Code, _ string) (str
|
||||
// WithdrawCryptocurrencyFunds returns a withdrawal ID when a withdrawal is
|
||||
// submitted
|
||||
func (b *Bithumb) WithdrawCryptocurrencyFunds(withdrawRequest *exchange.CryptoWithdrawRequest) (string, error) {
|
||||
_, err := b.WithdrawCrypto(withdrawRequest.Address, withdrawRequest.AddressTag, withdrawRequest.Currency.String(), withdrawRequest.Amount)
|
||||
_, err := b.WithdrawCrypto(withdrawRequest.Address,
|
||||
withdrawRequest.AddressTag,
|
||||
withdrawRequest.Currency.String(),
|
||||
withdrawRequest.Amount)
|
||||
return "", err
|
||||
}
|
||||
|
||||
@@ -445,8 +453,8 @@ func (b *Bithumb) GetFeeByType(feeBuilder *exchange.FeeBuilder) (float64, error)
|
||||
}
|
||||
|
||||
// GetActiveOrders retrieves any orders that are active/open
|
||||
func (b *Bithumb) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
var orders []exchange.OrderDetail
|
||||
func (b *Bithumb) GetActiveOrders(req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
var orders []order.Detail
|
||||
resp, err := b.GetOrders("", "", "1000", "", "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -458,39 +466,38 @@ func (b *Bithumb) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) (
|
||||
}
|
||||
|
||||
orderDate := time.Unix(resp.Data[i].OrderDate, 0)
|
||||
orderDetail := exchange.OrderDetail{
|
||||
orderDetail := order.Detail{
|
||||
Amount: resp.Data[i].Units,
|
||||
Exchange: b.Name,
|
||||
ID: resp.Data[i].OrderID,
|
||||
OrderDate: orderDate,
|
||||
Price: resp.Data[i].Price,
|
||||
RemainingAmount: resp.Data[i].UnitsRemaining,
|
||||
Status: string(exchange.ActiveOrderStatus),
|
||||
Status: order.Active,
|
||||
CurrencyPair: currency.NewPairWithDelimiter(resp.Data[i].OrderCurrency,
|
||||
resp.Data[i].PaymentCurrency,
|
||||
b.GetPairFormat(asset.Spot, false).Delimiter),
|
||||
}
|
||||
|
||||
if resp.Data[i].Type == "bid" {
|
||||
orderDetail.OrderSide = exchange.BuyOrderSide
|
||||
orderDetail.OrderSide = order.Buy
|
||||
} else if resp.Data[i].Type == "ask" {
|
||||
orderDetail.OrderSide = exchange.SellOrderSide
|
||||
orderDetail.OrderSide = order.Sell
|
||||
}
|
||||
|
||||
orders = append(orders, orderDetail)
|
||||
}
|
||||
|
||||
exchange.FilterOrdersBySide(&orders, getOrdersRequest.OrderSide)
|
||||
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks,
|
||||
getOrdersRequest.EndTicks)
|
||||
exchange.FilterOrdersByCurrencies(&orders, getOrdersRequest.Currencies)
|
||||
order.FilterOrdersBySide(&orders, req.OrderSide)
|
||||
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
|
||||
func (b *Bithumb) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
var orders []exchange.OrderDetail
|
||||
func (b *Bithumb) GetOrderHistory(req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
var orders []order.Detail
|
||||
resp, err := b.GetOrders("", "", "1000", "", "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -502,7 +509,7 @@ func (b *Bithumb) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) (
|
||||
}
|
||||
|
||||
orderDate := time.Unix(resp.Data[i].OrderDate, 0)
|
||||
orderDetail := exchange.OrderDetail{
|
||||
orderDetail := order.Detail{
|
||||
Amount: resp.Data[i].Units,
|
||||
Exchange: b.Name,
|
||||
ID: resp.Data[i].OrderID,
|
||||
@@ -515,18 +522,17 @@ func (b *Bithumb) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) (
|
||||
}
|
||||
|
||||
if resp.Data[i].Type == "bid" {
|
||||
orderDetail.OrderSide = exchange.BuyOrderSide
|
||||
orderDetail.OrderSide = order.Buy
|
||||
} else if resp.Data[i].Type == "ask" {
|
||||
orderDetail.OrderSide = exchange.SellOrderSide
|
||||
orderDetail.OrderSide = order.Sell
|
||||
}
|
||||
|
||||
orders = append(orders, orderDetail)
|
||||
}
|
||||
|
||||
exchange.FilterOrdersBySide(&orders, getOrdersRequest.OrderSide)
|
||||
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks,
|
||||
getOrdersRequest.EndTicks)
|
||||
exchange.FilterOrdersByCurrencies(&orders, getOrdersRequest.Currencies)
|
||||
order.FilterOrdersBySide(&orders, req.OrderSide)
|
||||
order.FilterOrdersByTickRange(&orders, req.StartTicks, req.EndTicks)
|
||||
order.FilterOrdersByCurrencies(&orders, req.Currencies)
|
||||
return orders, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/common/crypto"
|
||||
"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/websocket/wshandler"
|
||||
log "github.com/thrasher-corp/gocryptotrader/logger"
|
||||
)
|
||||
@@ -381,10 +382,10 @@ func (b *Bitstamp) PlaceOrder(currencyPair string, price, amount float64, buy, m
|
||||
req.Add("amount", strconv.FormatFloat(amount, 'f', -1, 64))
|
||||
req.Add("price", strconv.FormatFloat(price, 'f', -1, 64))
|
||||
response := Order{}
|
||||
orderType := exchange.BuyOrderSide.ToLower().ToString()
|
||||
orderType := order.Buy.Lower()
|
||||
|
||||
if !buy {
|
||||
orderType = exchange.SellOrderSide.ToLower().ToString()
|
||||
orderType = order.Sell.Lower()
|
||||
}
|
||||
|
||||
var path string
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
)
|
||||
|
||||
// Please add your private keys and customerID for better tests
|
||||
@@ -328,8 +329,8 @@ func TestFormatWithdrawPermissions(t *testing.T) {
|
||||
func TestGetActiveOrders(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var getOrdersRequest = exchange.GetOrdersRequest{
|
||||
OrderType: exchange.AnyOrderType,
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
OrderType: order.AnyType,
|
||||
}
|
||||
|
||||
_, err := b.GetActiveOrders(&getOrdersRequest)
|
||||
@@ -346,8 +347,8 @@ func TestGetActiveOrders(t *testing.T) {
|
||||
func TestGetOrderHistory(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var getOrdersRequest = exchange.GetOrdersRequest{
|
||||
OrderType: exchange.AnyOrderType,
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
OrderType: order.AnyType,
|
||||
}
|
||||
|
||||
_, err := b.GetOrderHistory(&getOrdersRequest)
|
||||
@@ -371,13 +372,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.BTC,
|
||||
Quote: currency.USD,
|
||||
},
|
||||
OrderSide: exchange.BuyOrderSide,
|
||||
OrderType: exchange.LimitOrderType,
|
||||
OrderSide: order.Buy,
|
||||
OrderType: order.Limit,
|
||||
Price: 1,
|
||||
Amount: 1,
|
||||
ClientID: "meowOrder",
|
||||
@@ -402,7 +403,7 @@ func TestCancelExchangeOrder(t *testing.T) {
|
||||
|
||||
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
|
||||
var orderCancellation = &exchange.OrderCancellation{
|
||||
var orderCancellation = &order.Cancel{
|
||||
OrderID: "1",
|
||||
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
AccountID: "1",
|
||||
@@ -429,7 +430,7 @@ func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
|
||||
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
|
||||
var orderCancellation = &exchange.OrderCancellation{
|
||||
var orderCancellation = &order.Cancel{
|
||||
OrderID: "1",
|
||||
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
AccountID: "1",
|
||||
@@ -446,15 +447,15 @@ 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))
|
||||
}
|
||||
}
|
||||
|
||||
func TestModifyOrder(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
_, err := b.ModifyOrder(&exchange.ModifyOrder{})
|
||||
_, err := b.ModifyOrder(&order.Modify{})
|
||||
if err == nil {
|
||||
t.Error("ModifyOrder() Expected error")
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package bitstamp
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -13,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"
|
||||
@@ -181,7 +181,10 @@ func (b *Bitstamp) Start(wg *sync.WaitGroup) {
|
||||
// Run implements the Bitstamp wrapper
|
||||
func (b *Bitstamp) Run() {
|
||||
if b.Verbose {
|
||||
log.Debugf(log.ExchangeSys, "%s Websocket: %s.", b.GetName(), common.IsEnabled(b.Websocket.IsEnabled()))
|
||||
log.Debugf(log.ExchangeSys,
|
||||
"%s Websocket: %s.",
|
||||
b.GetName(),
|
||||
common.IsEnabled(b.Websocket.IsEnabled()))
|
||||
b.PrintEnabledPairs()
|
||||
}
|
||||
|
||||
@@ -191,7 +194,10 @@ func (b *Bitstamp) Run() {
|
||||
|
||||
err := b.UpdateTradablePairs(false)
|
||||
if err != nil {
|
||||
log.Errorf(log.ExchangeSys, "%s failed to update tradable pairs. Err: %s", b.Name, err)
|
||||
log.Errorf(log.ExchangeSys,
|
||||
"%s failed to update tradable pairs. Err: %s",
|
||||
b.Name,
|
||||
err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -364,23 +370,22 @@ func (b *Bitstamp) GetExchangeHistory(p currency.Pair, assetType asset.Item) ([]
|
||||
}
|
||||
|
||||
// SubmitOrder submits a new order
|
||||
func (b *Bitstamp) 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 *Bitstamp) SubmitOrder(s *order.Submit) (order.SubmitResponse, error) {
|
||||
var submitOrderResponse order.SubmitResponse
|
||||
if err := s.Validate(); err != nil {
|
||||
return submitOrderResponse, err
|
||||
}
|
||||
|
||||
buy := order.OrderSide == exchange.BuyOrderSide
|
||||
market := order.OrderType == exchange.MarketOrderType
|
||||
response, err := b.PlaceOrder(order.Pair.String(), order.Price, order.Amount,
|
||||
buy, market)
|
||||
buy := s.OrderSide == order.Buy
|
||||
market := s.OrderType == order.Market
|
||||
response, err := b.PlaceOrder(s.Pair.String(),
|
||||
s.Price,
|
||||
s.Amount,
|
||||
buy,
|
||||
market)
|
||||
|
||||
if response.ID > 0 {
|
||||
submitOrderResponse.OrderID = fmt.Sprintf("%v", response.ID)
|
||||
submitOrderResponse.OrderID = strconv.FormatInt(response.ID, 10)
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
@@ -392,38 +397,36 @@ func (b *Bitstamp) SubmitOrder(order *exchange.OrderSubmission) (exchange.Submit
|
||||
|
||||
// ModifyOrder will allow of changing orderbook placement and limit to
|
||||
// market conversion
|
||||
func (b *Bitstamp) ModifyOrder(action *exchange.ModifyOrder) (string, error) {
|
||||
func (b *Bitstamp) ModifyOrder(action *order.Modify) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// CancelOrder cancels an order by its corresponding ID number
|
||||
func (b *Bitstamp) CancelOrder(order *exchange.OrderCancellation) error {
|
||||
func (b *Bitstamp) CancelOrder(order *order.Cancel) error {
|
||||
orderIDInt, err := strconv.ParseInt(order.OrderID, 10, 64)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = b.CancelExistingOrder(orderIDInt)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// CancelAllOrders cancels all orders associated with a currency pair
|
||||
func (b *Bitstamp) CancelAllOrders(_ *exchange.OrderCancellation) (exchange.CancelAllOrdersResponse, error) {
|
||||
func (b *Bitstamp) CancelAllOrders(_ *order.Cancel) (order.CancelAllResponse, error) {
|
||||
success, err := b.CancelAllExistingOrders()
|
||||
if err != nil {
|
||||
return exchange.CancelAllOrdersResponse{}, err
|
||||
return order.CancelAllResponse{}, err
|
||||
}
|
||||
if !success {
|
||||
err = errors.New("cancel all orders failed. Bitstamp provides no further information. Check order status to verify")
|
||||
}
|
||||
|
||||
return exchange.CancelAllOrdersResponse{}, err
|
||||
return order.CancelAllResponse{}, err
|
||||
}
|
||||
|
||||
// GetOrderInfo returns information on a current open order
|
||||
func (b *Bitstamp) GetOrderInfo(orderID string) (exchange.OrderDetail, error) {
|
||||
var orderDetail exchange.OrderDetail
|
||||
func (b *Bitstamp) GetOrderInfo(orderID string) (order.Detail, error) {
|
||||
var orderDetail order.Detail
|
||||
return orderDetail, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
@@ -435,7 +438,11 @@ func (b *Bitstamp) GetDepositAddress(cryptocurrency currency.Code, _ string) (st
|
||||
// WithdrawCryptocurrencyFunds returns a withdrawal ID when a withdrawal is
|
||||
// submitted
|
||||
func (b *Bitstamp) WithdrawCryptocurrencyFunds(withdrawRequest *exchange.CryptoWithdrawRequest) (string, error) {
|
||||
resp, err := b.CryptoWithdrawal(withdrawRequest.Amount, withdrawRequest.Address, withdrawRequest.Currency.String(), withdrawRequest.AddressTag, true)
|
||||
resp, err := b.CryptoWithdrawal(withdrawRequest.Amount,
|
||||
withdrawRequest.Address,
|
||||
withdrawRequest.Currency.String(),
|
||||
withdrawRequest.AddressTag,
|
||||
true)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -453,10 +460,17 @@ func (b *Bitstamp) WithdrawCryptocurrencyFunds(withdrawRequest *exchange.CryptoW
|
||||
// WithdrawFiatFunds returns a withdrawal ID when a
|
||||
// withdrawal is submitted
|
||||
func (b *Bitstamp) WithdrawFiatFunds(withdrawRequest *exchange.FiatWithdrawRequest) (string, error) {
|
||||
resp, err := b.OpenBankWithdrawal(withdrawRequest.Amount, withdrawRequest.Currency.String(),
|
||||
withdrawRequest.BankAccountName, withdrawRequest.IBAN, withdrawRequest.SwiftCode, withdrawRequest.BankAddress,
|
||||
withdrawRequest.BankPostalCode, withdrawRequest.BankCity, withdrawRequest.BankCountry,
|
||||
withdrawRequest.Description, sepaWithdrawal)
|
||||
resp, err := b.OpenBankWithdrawal(withdrawRequest.Amount,
|
||||
withdrawRequest.Currency.String(),
|
||||
withdrawRequest.BankAccountName,
|
||||
withdrawRequest.IBAN,
|
||||
withdrawRequest.SwiftCode,
|
||||
withdrawRequest.BankAddress,
|
||||
withdrawRequest.BankPostalCode,
|
||||
withdrawRequest.BankCity,
|
||||
withdrawRequest.BankCountry,
|
||||
withdrawRequest.Description,
|
||||
sepaWithdrawal)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -474,12 +488,23 @@ func (b *Bitstamp) WithdrawFiatFunds(withdrawRequest *exchange.FiatWithdrawReque
|
||||
// WithdrawFiatFundsToInternationalBank returns a withdrawal ID when a
|
||||
// withdrawal is submitted
|
||||
func (b *Bitstamp) WithdrawFiatFundsToInternationalBank(withdrawRequest *exchange.FiatWithdrawRequest) (string, error) {
|
||||
resp, err := b.OpenInternationalBankWithdrawal(withdrawRequest.Amount, withdrawRequest.Currency.String(),
|
||||
withdrawRequest.BankAccountName, withdrawRequest.IBAN, withdrawRequest.SwiftCode, withdrawRequest.BankAddress,
|
||||
withdrawRequest.BankPostalCode, withdrawRequest.BankCity, withdrawRequest.BankCountry,
|
||||
withdrawRequest.IntermediaryBankName, withdrawRequest.IntermediaryBankAddress, withdrawRequest.IntermediaryBankPostalCode,
|
||||
withdrawRequest.IntermediaryBankCity, withdrawRequest.IntermediaryBankCountry, withdrawRequest.WireCurrency,
|
||||
withdrawRequest.Description, internationalWithdrawal)
|
||||
resp, err := b.OpenInternationalBankWithdrawal(withdrawRequest.Amount,
|
||||
withdrawRequest.Currency.String(),
|
||||
withdrawRequest.BankAccountName,
|
||||
withdrawRequest.IBAN,
|
||||
withdrawRequest.SwiftCode,
|
||||
withdrawRequest.BankAddress,
|
||||
withdrawRequest.BankPostalCode,
|
||||
withdrawRequest.BankCity,
|
||||
withdrawRequest.BankCountry,
|
||||
withdrawRequest.IntermediaryBankName,
|
||||
withdrawRequest.IntermediaryBankAddress,
|
||||
withdrawRequest.IntermediaryBankPostalCode,
|
||||
withdrawRequest.IntermediaryBankCity,
|
||||
withdrawRequest.IntermediaryBankCountry,
|
||||
withdrawRequest.WireCurrency,
|
||||
withdrawRequest.Description,
|
||||
internationalWithdrawal)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -500,13 +525,13 @@ func (b *Bitstamp) GetWebsocket() (*wshandler.Websocket, error) {
|
||||
}
|
||||
|
||||
// GetActiveOrders retrieves any orders that are active/open
|
||||
func (b *Bitstamp) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
var orders []exchange.OrderDetail
|
||||
func (b *Bitstamp) GetActiveOrders(req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
var orders []order.Detail
|
||||
var currPair string
|
||||
if len(getOrdersRequest.Currencies) != 1 {
|
||||
if len(req.Currencies) != 1 {
|
||||
currPair = "all"
|
||||
} else {
|
||||
currPair = getOrdersRequest.Currencies[0].String()
|
||||
currPair = req.Currencies[0].String()
|
||||
}
|
||||
|
||||
resp, err := b.GetOpenOrders(currPair)
|
||||
@@ -514,59 +539,63 @@ func (b *Bitstamp) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, order := range resp {
|
||||
orderDate := time.Unix(order.Date, 0)
|
||||
orders = append(orders, exchange.OrderDetail{
|
||||
Amount: order.Amount,
|
||||
ID: fmt.Sprintf("%v", order.ID),
|
||||
Price: order.Price,
|
||||
for i := range resp {
|
||||
orderDate := time.Unix(resp[i].Date, 0)
|
||||
orders = append(orders, order.Detail{
|
||||
Amount: resp[i].Amount,
|
||||
ID: strconv.FormatInt(resp[i].ID, 10),
|
||||
Price: resp[i].Price,
|
||||
OrderDate: orderDate,
|
||||
CurrencyPair: currency.NewPairFromStrings(order.Currency[0:3],
|
||||
order.Currency[len(order.Currency)-3:]),
|
||||
CurrencyPair: currency.NewPairFromStrings(resp[i].Currency[0:3],
|
||||
resp[i].Currency[len(resp[i].Currency)-3:]),
|
||||
Exchange: b.Name,
|
||||
})
|
||||
}
|
||||
|
||||
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks, getOrdersRequest.EndTicks)
|
||||
exchange.FilterOrdersByCurrencies(&orders, getOrdersRequest.Currencies)
|
||||
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
|
||||
func (b *Bitstamp) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
func (b *Bitstamp) GetOrderHistory(req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
var currPair string
|
||||
if len(getOrdersRequest.Currencies) == 1 {
|
||||
currPair = getOrdersRequest.Currencies[0].String()
|
||||
if len(req.Currencies) == 1 {
|
||||
currPair = req.Currencies[0].String()
|
||||
}
|
||||
resp, err := b.GetUserTransactions(currPair)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var orders []exchange.OrderDetail
|
||||
for _, order := range resp {
|
||||
if order.Type != 2 {
|
||||
var orders []order.Detail
|
||||
for i := range resp {
|
||||
if resp[i].Type != 2 {
|
||||
continue
|
||||
}
|
||||
var quoteCurrency, baseCurrency currency.Code
|
||||
|
||||
switch {
|
||||
case order.BTC > 0:
|
||||
case resp[i].BTC > 0:
|
||||
baseCurrency = currency.BTC
|
||||
case order.XRP > 0:
|
||||
case resp[i].XRP > 0:
|
||||
baseCurrency = currency.XRP
|
||||
default:
|
||||
log.Warnf(log.ExchangeSys, "no base currency found for OrderID '%v'", order.OrderID)
|
||||
log.Warnf(log.ExchangeSys,
|
||||
"no base currency found for OrderID '%d'",
|
||||
resp[i].OrderID)
|
||||
}
|
||||
|
||||
switch {
|
||||
case order.USD > 0:
|
||||
case resp[i].USD > 0:
|
||||
quoteCurrency = currency.USD
|
||||
case order.EUR > 0:
|
||||
case resp[i].EUR > 0:
|
||||
quoteCurrency = currency.EUR
|
||||
default:
|
||||
log.Warnf(log.ExchangeSys, "no quote currency found for orderID '%v'", order.OrderID)
|
||||
log.Warnf(log.ExchangeSys,
|
||||
"no quote currency found for orderID '%d'",
|
||||
resp[i].OrderID)
|
||||
}
|
||||
|
||||
var currPair currency.Pair
|
||||
@@ -576,22 +605,21 @@ func (b *Bitstamp) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest)
|
||||
b.GetPairFormat(asset.Spot, false).Delimiter)
|
||||
}
|
||||
|
||||
orderDate, err := time.Parse("2006-01-02 15:04:05", order.Date)
|
||||
orderDate, err := time.Parse("2006-01-02 15:04:05", resp[i].Date)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
orders = append(orders, exchange.OrderDetail{
|
||||
ID: fmt.Sprintf("%v", order.OrderID),
|
||||
orders = append(orders, order.Detail{
|
||||
ID: strconv.FormatInt(resp[i].OrderID, 10),
|
||||
OrderDate: orderDate,
|
||||
Exchange: b.Name,
|
||||
CurrencyPair: currPair,
|
||||
})
|
||||
}
|
||||
|
||||
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks,
|
||||
getOrdersRequest.EndTicks)
|
||||
exchange.FilterOrdersByCurrencies(&orders, getOrdersRequest.Currencies)
|
||||
order.FilterOrdersByTickRange(&orders, req.StartTicks, req.EndTicks)
|
||||
order.FilterOrdersByCurrencies(&orders, req.Currencies)
|
||||
return orders, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,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 you own test keys here to run better tests.
|
||||
@@ -333,8 +334,8 @@ func TestGetActiveOrders(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)},
|
||||
}
|
||||
@@ -353,8 +354,8 @@ func TestGetOrderHistory(t *testing.T) {
|
||||
b.SetDefaults()
|
||||
TestSetup(t)
|
||||
|
||||
var getOrdersRequest = exchange.GetOrdersRequest{
|
||||
OrderType: exchange.AnyOrderType,
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
OrderType: order.AnyType,
|
||||
}
|
||||
|
||||
_, err := b.GetOrderHistory(&getOrdersRequest)
|
||||
@@ -379,14 +380,14 @@ 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{
|
||||
Delimiter: "-",
|
||||
Base: currency.BTC,
|
||||
Quote: currency.LTC,
|
||||
},
|
||||
OrderSide: exchange.BuyOrderSide,
|
||||
OrderType: exchange.LimitOrderType,
|
||||
OrderSide: order.Buy,
|
||||
OrderType: order.Limit,
|
||||
Price: 1,
|
||||
Amount: 1,
|
||||
ClientID: "meowOrder",
|
||||
@@ -409,7 +410,7 @@ func TestCancelExchangeOrder(t *testing.T) {
|
||||
|
||||
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
|
||||
var orderCancellation = &exchange.OrderCancellation{
|
||||
var orderCancellation = &order.Cancel{
|
||||
OrderID: "1",
|
||||
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
AccountID: "1",
|
||||
@@ -435,7 +436,7 @@ func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
|
||||
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
|
||||
var orderCancellation = &exchange.OrderCancellation{
|
||||
var orderCancellation = &order.Cancel{
|
||||
OrderID: "1",
|
||||
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
AccountID: "1",
|
||||
@@ -451,13 +452,13 @@ 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))
|
||||
}
|
||||
}
|
||||
|
||||
func TestModifyOrder(t *testing.T) {
|
||||
_, err := b.ModifyOrder(&exchange.ModifyOrder{})
|
||||
_, err := b.ModifyOrder(&order.Modify{})
|
||||
if err == nil {
|
||||
t.Error("ModifyOrder() Expected error")
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package bittrex
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -12,6 +11,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"
|
||||
@@ -139,7 +139,10 @@ func (b *Bittrex) Run() {
|
||||
|
||||
err := b.UpdatePairs(currency.NewPairsFromStrings(enabledPairs), asset.Spot, true, true)
|
||||
if err != nil {
|
||||
log.Errorf(log.ExchangeSys, "%s failed to update currencies. Err: %s\n", b.Name, err)
|
||||
log.Errorf(log.ExchangeSys,
|
||||
"%s failed to update currencies. Err: %s\n",
|
||||
b.Name,
|
||||
err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,7 +152,10 @@ func (b *Bittrex) Run() {
|
||||
|
||||
err := b.UpdateTradablePairs(forceUpdate)
|
||||
if err != nil {
|
||||
log.Errorf(log.ExchangeSys, "%s failed to update tradable pairs. Err: %s", b.Name, err)
|
||||
log.Errorf(log.ExchangeSys,
|
||||
"%s failed to update tradable pairs. Err: %s",
|
||||
b.Name,
|
||||
err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -313,30 +319,29 @@ func (b *Bittrex) GetExchangeHistory(p currency.Pair, assetType asset.Item) ([]e
|
||||
}
|
||||
|
||||
// SubmitOrder submits a new order
|
||||
func (b *Bittrex) 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 *Bittrex) SubmitOrder(s *order.Submit) (order.SubmitResponse, error) {
|
||||
var submitOrderResponse order.SubmitResponse
|
||||
if err := s.Validate(); err != nil {
|
||||
return submitOrderResponse, err
|
||||
}
|
||||
|
||||
buy := order.OrderSide == exchange.BuyOrderSide
|
||||
var response UUID
|
||||
var err error
|
||||
buy := s.OrderSide == order.Buy
|
||||
|
||||
if order.OrderType != exchange.LimitOrderType {
|
||||
return submitOrderResponse, errors.New("limit order not supported on exchange")
|
||||
if s.OrderType != order.Limit {
|
||||
return submitOrderResponse,
|
||||
errors.New("limit order not supported on exchange")
|
||||
}
|
||||
|
||||
var response UUID
|
||||
var err error
|
||||
if buy {
|
||||
response, err = b.PlaceBuyLimit(order.Pair.String(), order.Amount,
|
||||
order.Price)
|
||||
response, err = b.PlaceBuyLimit(s.Pair.String(),
|
||||
s.Amount,
|
||||
s.Price)
|
||||
} else {
|
||||
response, err = b.PlaceSellLimit(order.Pair.String(), order.Amount,
|
||||
order.Price)
|
||||
response, err = b.PlaceSellLimit(s.Pair.String(),
|
||||
s.Amount,
|
||||
s.Price)
|
||||
}
|
||||
|
||||
if response.Result.ID != "" {
|
||||
@@ -352,21 +357,21 @@ func (b *Bittrex) SubmitOrder(order *exchange.OrderSubmission) (exchange.SubmitO
|
||||
|
||||
// ModifyOrder will allow of changing orderbook placement and limit to
|
||||
// market conversion
|
||||
func (b *Bittrex) ModifyOrder(action *exchange.ModifyOrder) (string, error) {
|
||||
func (b *Bittrex) ModifyOrder(action *order.Modify) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// CancelOrder cancels an order by its corresponding ID number
|
||||
func (b *Bittrex) CancelOrder(order *exchange.OrderCancellation) error {
|
||||
func (b *Bittrex) CancelOrder(order *order.Cancel) error {
|
||||
_, err := b.CancelExistingOrder(order.OrderID)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// CancelAllOrders cancels all orders associated with a currency pair
|
||||
func (b *Bittrex) CancelAllOrders(_ *exchange.OrderCancellation) (exchange.CancelAllOrdersResponse, error) {
|
||||
cancelAllOrdersResponse := exchange.CancelAllOrdersResponse{
|
||||
OrderStatus: make(map[string]string),
|
||||
func (b *Bittrex) CancelAllOrders(_ *order.Cancel) (order.CancelAllResponse, error) {
|
||||
cancelAllOrdersResponse := order.CancelAllResponse{
|
||||
Status: make(map[string]string),
|
||||
}
|
||||
openOrders, err := b.GetOpenOrders("")
|
||||
if err != nil {
|
||||
@@ -376,7 +381,7 @@ func (b *Bittrex) CancelAllOrders(_ *exchange.OrderCancellation) (exchange.Cance
|
||||
for i := range openOrders.Result {
|
||||
_, err := b.CancelExistingOrder(openOrders.Result[i].OrderUUID)
|
||||
if err != nil {
|
||||
cancelAllOrdersResponse.OrderStatus[openOrders.Result[i].OrderUUID] = err.Error()
|
||||
cancelAllOrdersResponse.Status[openOrders.Result[i].OrderUUID] = err.Error()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -384,8 +389,8 @@ func (b *Bittrex) CancelAllOrders(_ *exchange.OrderCancellation) (exchange.Cance
|
||||
}
|
||||
|
||||
// GetOrderInfo returns information on a current open order
|
||||
func (b *Bittrex) GetOrderInfo(orderID string) (exchange.OrderDetail, error) {
|
||||
var orderDetail exchange.OrderDetail
|
||||
func (b *Bittrex) GetOrderInfo(orderID string) (order.Detail, error) {
|
||||
var orderDetail order.Detail
|
||||
return orderDetail, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
@@ -403,7 +408,7 @@ func (b *Bittrex) GetDepositAddress(cryptocurrency currency.Code, _ string) (str
|
||||
// submitted
|
||||
func (b *Bittrex) WithdrawCryptocurrencyFunds(withdrawRequest *exchange.CryptoWithdrawRequest) (string, error) {
|
||||
uuid, err := b.Withdraw(withdrawRequest.Currency.String(), withdrawRequest.AddressTag, withdrawRequest.Address, withdrawRequest.Amount)
|
||||
return fmt.Sprintf("%v", uuid), err
|
||||
return uuid.Result.ID, err
|
||||
}
|
||||
|
||||
// WithdrawFiatFunds returns a withdrawal ID when a
|
||||
@@ -434,10 +439,10 @@ func (b *Bittrex) GetFeeByType(feeBuilder *exchange.FeeBuilder) (float64, error)
|
||||
}
|
||||
|
||||
// GetActiveOrders retrieves any orders that are active/open
|
||||
func (b *Bittrex) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
func (b *Bittrex) GetActiveOrders(req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
var currPair string
|
||||
if len(getOrdersRequest.Currencies) == 1 {
|
||||
currPair = getOrdersRequest.Currencies[0].String()
|
||||
if len(req.Currencies) == 1 {
|
||||
currPair = req.Currencies[0].String()
|
||||
}
|
||||
|
||||
resp, err := b.GetOpenOrders(currPair)
|
||||
@@ -445,19 +450,23 @@ func (b *Bittrex) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) (
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var orders []exchange.OrderDetail
|
||||
var orders []order.Detail
|
||||
for i := range resp.Result {
|
||||
orderDate, err := time.Parse(time.RFC3339, resp.Result[i].Opened)
|
||||
if err != nil {
|
||||
log.Warnf(log.ExchangeSys, "Exchange %v Func %v Order %v Could not parse date to unix with value of %v",
|
||||
b.Name, "GetActiveOrders", resp.Result[i].OrderUUID, resp.Result[i].Opened)
|
||||
log.Warnf(log.ExchangeSys,
|
||||
"Exchange %v Func %v Order %v Could not parse date to unix with value of %v",
|
||||
b.Name,
|
||||
"GetActiveOrders",
|
||||
resp.Result[i].OrderUUID,
|
||||
resp.Result[i].Opened)
|
||||
}
|
||||
|
||||
pair := currency.NewPairDelimiter(resp.Result[i].Exchange,
|
||||
b.GetPairFormat(asset.Spot, false).Delimiter)
|
||||
orderType := exchange.OrderType(strings.ToUpper(resp.Result[i].Type))
|
||||
orderType := order.Type(strings.ToUpper(resp.Result[i].Type))
|
||||
|
||||
orders = append(orders, exchange.OrderDetail{
|
||||
orders = append(orders, order.Detail{
|
||||
Amount: resp.Result[i].Quantity,
|
||||
RemainingAmount: resp.Result[i].QuantityRemaining,
|
||||
Price: resp.Result[i].Price,
|
||||
@@ -469,19 +478,18 @@ func (b *Bittrex) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) (
|
||||
})
|
||||
}
|
||||
|
||||
exchange.FilterOrdersByType(&orders, getOrdersRequest.OrderType)
|
||||
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks,
|
||||
getOrdersRequest.EndTicks)
|
||||
exchange.FilterOrdersByCurrencies(&orders, getOrdersRequest.Currencies)
|
||||
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
|
||||
func (b *Bittrex) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
func (b *Bittrex) GetOrderHistory(req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
var currPair string
|
||||
if len(getOrdersRequest.Currencies) == 1 {
|
||||
currPair = getOrdersRequest.Currencies[0].String()
|
||||
if len(req.Currencies) == 1 {
|
||||
currPair = req.Currencies[0].String()
|
||||
}
|
||||
|
||||
resp, err := b.GetOrderHistoryForCurrency(currPair)
|
||||
@@ -489,19 +497,23 @@ func (b *Bittrex) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) (
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var orders []exchange.OrderDetail
|
||||
var orders []order.Detail
|
||||
for i := range resp.Result {
|
||||
orderDate, err := time.Parse(time.RFC3339, resp.Result[i].TimeStamp)
|
||||
if err != nil {
|
||||
log.Warnf(log.ExchangeSys, "Exchange %v Func %v Order %v Could not parse date to unix with value of %v",
|
||||
b.Name, "GetActiveOrders", resp.Result[i].OrderUUID, resp.Result[i].Opened)
|
||||
log.Warnf(log.ExchangeSys,
|
||||
"Exchange %v Func %v Order %v Could not parse date to unix with value of %v",
|
||||
b.Name,
|
||||
"GetActiveOrders",
|
||||
resp.Result[i].OrderUUID,
|
||||
resp.Result[i].Opened)
|
||||
}
|
||||
|
||||
pair := currency.NewPairDelimiter(resp.Result[i].Exchange,
|
||||
b.GetPairFormat(asset.Spot, false).Delimiter)
|
||||
orderType := exchange.OrderType(strings.ToUpper(resp.Result[i].Type))
|
||||
orderType := order.Type(strings.ToUpper(resp.Result[i].Type))
|
||||
|
||||
orders = append(orders, exchange.OrderDetail{
|
||||
orders = append(orders, order.Detail{
|
||||
Amount: resp.Result[i].Quantity,
|
||||
RemainingAmount: resp.Result[i].QuantityRemaining,
|
||||
Price: resp.Result[i].Price,
|
||||
@@ -514,10 +526,9 @@ func (b *Bittrex) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) (
|
||||
})
|
||||
}
|
||||
|
||||
exchange.FilterOrdersByType(&orders, getOrdersRequest.OrderType)
|
||||
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks,
|
||||
getOrdersRequest.EndTicks)
|
||||
exchange.FilterOrdersByCurrencies(&orders, getOrdersRequest.Currencies)
|
||||
order.FilterOrdersByType(&orders, req.OrderType)
|
||||
order.FilterOrdersByTickRange(&orders, req.StartTicks, req.EndTicks)
|
||||
order.FilterOrdersByCurrencies(&orders, req.Currencies)
|
||||
return orders, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,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"
|
||||
)
|
||||
|
||||
var b BTCMarkets
|
||||
@@ -85,7 +86,7 @@ func TestGetTrades(t *testing.T) {
|
||||
func TestNewOrder(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.NewOrder("AUD", "BTC", 0, 0, "Bid",
|
||||
exchange.LimitOrderType.ToLower().ToString(), "testTest")
|
||||
order.Limit.Lower(), "testTest")
|
||||
if err == nil {
|
||||
t.Error("NewOrder() Expected error")
|
||||
}
|
||||
@@ -294,8 +295,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)
|
||||
@@ -310,8 +311,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)},
|
||||
}
|
||||
@@ -338,14 +339,14 @@ 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{
|
||||
Delimiter: "-",
|
||||
Base: currency.BTC,
|
||||
Quote: currency.LTC,
|
||||
},
|
||||
OrderSide: exchange.BuyOrderSide,
|
||||
OrderType: exchange.LimitOrderType,
|
||||
OrderSide: order.Buy,
|
||||
OrderType: order.Limit,
|
||||
Price: 1,
|
||||
Amount: 1,
|
||||
ClientID: "meowOrder",
|
||||
@@ -368,7 +369,7 @@ func TestCancelExchangeOrder(t *testing.T) {
|
||||
|
||||
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
|
||||
var orderCancellation = &exchange.OrderCancellation{
|
||||
var orderCancellation = &order.Cancel{
|
||||
OrderID: "1",
|
||||
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
AccountID: "1",
|
||||
@@ -394,7 +395,7 @@ func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
|
||||
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
|
||||
var orderCancellation = &exchange.OrderCancellation{
|
||||
var orderCancellation = &order.Cancel{
|
||||
OrderID: "1",
|
||||
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
AccountID: "1",
|
||||
@@ -410,13 +411,13 @@ 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))
|
||||
}
|
||||
}
|
||||
|
||||
func TestModifyOrder(t *testing.T) {
|
||||
_, err := b.ModifyOrder(&exchange.ModifyOrder{})
|
||||
_, err := b.ModifyOrder(&order.Modify{})
|
||||
if err == nil {
|
||||
t.Error("ModifyOrder() Expected error")
|
||||
}
|
||||
|
||||
@@ -13,6 +13,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"
|
||||
@@ -340,33 +341,29 @@ func (b *BTCMarkets) GetExchangeHistory(p currency.Pair, assetType asset.Item) (
|
||||
}
|
||||
|
||||
// SubmitOrder submits a new order
|
||||
func (b *BTCMarkets) 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 *BTCMarkets) SubmitOrder(s *order.Submit) (order.SubmitResponse, error) {
|
||||
var submitOrderResponse order.SubmitResponse
|
||||
if err := s.Validate(); err != nil {
|
||||
return submitOrderResponse, err
|
||||
}
|
||||
|
||||
if strings.EqualFold(order.OrderSide.ToString(), exchange.SellOrderSide.ToString()) {
|
||||
order.OrderSide = exchange.AskOrderSide
|
||||
if strings.EqualFold(s.OrderSide.String(), order.Sell.String()) {
|
||||
s.OrderSide = order.Ask
|
||||
}
|
||||
if strings.EqualFold(order.OrderSide.ToString(), exchange.BuyOrderSide.ToString()) {
|
||||
order.OrderSide = exchange.BuyOrderSide
|
||||
if strings.EqualFold(s.OrderSide.String(), order.Buy.String()) {
|
||||
s.OrderSide = order.Bid
|
||||
}
|
||||
|
||||
response, err := b.NewOrder(order.Pair.Base.Upper().String(),
|
||||
order.Pair.Quote.Upper().String(),
|
||||
order.Price,
|
||||
order.Amount,
|
||||
order.OrderSide.ToString(),
|
||||
order.OrderType.ToString(),
|
||||
order.ClientID)
|
||||
response, err := b.NewOrder(s.Pair.Base.Upper().String(),
|
||||
s.Pair.Quote.Upper().String(),
|
||||
s.Price,
|
||||
s.Amount,
|
||||
s.OrderSide.String(),
|
||||
s.OrderType.String(),
|
||||
s.ClientID)
|
||||
|
||||
if response > 0 {
|
||||
submitOrderResponse.OrderID = fmt.Sprintf("%v", response)
|
||||
submitOrderResponse.OrderID = strconv.FormatInt(response, 10)
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
@@ -378,12 +375,12 @@ func (b *BTCMarkets) SubmitOrder(order *exchange.OrderSubmission) (exchange.Subm
|
||||
|
||||
// ModifyOrder will allow of changing orderbook placement and limit to
|
||||
// market conversion
|
||||
func (b *BTCMarkets) ModifyOrder(action *exchange.ModifyOrder) (string, error) {
|
||||
func (b *BTCMarkets) ModifyOrder(action *order.Modify) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// CancelOrder cancels an order by its corresponding ID number
|
||||
func (b *BTCMarkets) CancelOrder(order *exchange.OrderCancellation) error {
|
||||
func (b *BTCMarkets) CancelOrder(order *order.Cancel) error {
|
||||
orderIDInt, err := strconv.ParseInt(order.OrderID, 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -394,9 +391,9 @@ func (b *BTCMarkets) CancelOrder(order *exchange.OrderCancellation) error {
|
||||
}
|
||||
|
||||
// CancelAllOrders cancels all orders associated with a currency pair
|
||||
func (b *BTCMarkets) CancelAllOrders(_ *exchange.OrderCancellation) (exchange.CancelAllOrdersResponse, error) {
|
||||
cancelAllOrdersResponse := exchange.CancelAllOrdersResponse{
|
||||
OrderStatus: make(map[string]string),
|
||||
func (b *BTCMarkets) CancelAllOrders(_ *order.Cancel) (order.CancelAllResponse, error) {
|
||||
cancelAllOrdersResponse := order.CancelAllResponse{
|
||||
Status: make(map[string]string),
|
||||
}
|
||||
openOrders, err := b.GetOpenOrders()
|
||||
if err != nil {
|
||||
@@ -416,7 +413,7 @@ func (b *BTCMarkets) CancelAllOrders(_ *exchange.OrderCancellation) (exchange.Ca
|
||||
|
||||
for i := range orders {
|
||||
if !orders[i].Success {
|
||||
cancelAllOrdersResponse.OrderStatus[strconv.FormatInt(orders[i].ID, 10)] = orders[i].ErrorMessage
|
||||
cancelAllOrdersResponse.Status[strconv.FormatInt(orders[i].ID, 10)] = orders[i].ErrorMessage
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -424,8 +421,8 @@ func (b *BTCMarkets) CancelAllOrders(_ *exchange.OrderCancellation) (exchange.Ca
|
||||
}
|
||||
|
||||
// GetOrderInfo returns information on a current open order
|
||||
func (b *BTCMarkets) GetOrderInfo(orderID string) (exchange.OrderDetail, error) {
|
||||
var OrderDetail exchange.OrderDetail
|
||||
func (b *BTCMarkets) GetOrderInfo(orderID string) (order.Detail, error) {
|
||||
var OrderDetail order.Detail
|
||||
|
||||
o, err := strconv.ParseInt(orderID, 10, 64)
|
||||
if err != nil {
|
||||
@@ -446,14 +443,14 @@ func (b *BTCMarkets) GetOrderInfo(orderID string) (exchange.OrderDetail, error)
|
||||
}
|
||||
|
||||
for i := range orders {
|
||||
var side exchange.OrderSide
|
||||
if strings.EqualFold(orders[i].OrderSide, exchange.AskOrderSide.ToString()) {
|
||||
side = exchange.SellOrderSide
|
||||
} else if strings.EqualFold(orders[i].OrderSide, exchange.BidOrderSide.ToString()) {
|
||||
side = exchange.BuyOrderSide
|
||||
var side order.Side
|
||||
if strings.EqualFold(orders[i].OrderSide, order.Ask.String()) {
|
||||
side = order.Sell
|
||||
} else if strings.EqualFold(orders[i].OrderSide, order.Bid.String()) {
|
||||
side = order.Buy
|
||||
}
|
||||
orderDate := time.Unix(int64(orders[i].CreationTime), 0)
|
||||
orderType := exchange.OrderType(strings.ToUpper(orders[i].OrderType))
|
||||
orderType := order.Type(strings.ToUpper(orders[i].OrderType))
|
||||
|
||||
OrderDetail.Amount = orders[i].Volume
|
||||
OrderDetail.OrderDate = orderDate
|
||||
@@ -463,7 +460,7 @@ func (b *BTCMarkets) GetOrderInfo(orderID string) (exchange.OrderDetail, error)
|
||||
OrderDetail.OrderSide = side
|
||||
OrderDetail.OrderType = orderType
|
||||
OrderDetail.Price = orders[i].Price
|
||||
OrderDetail.Status = orders[i].Status
|
||||
OrderDetail.Status = order.Status(orders[i].Status)
|
||||
OrderDetail.CurrencyPair = currency.NewPairWithDelimiter(orders[i].Instrument,
|
||||
orders[i].Currency,
|
||||
b.GetPairFormat(asset.Spot, false).Delimiter)
|
||||
@@ -488,7 +485,11 @@ func (b *BTCMarkets) WithdrawFiatFunds(withdrawRequest *exchange.FiatWithdrawReq
|
||||
if withdrawRequest.Currency != currency.AUD {
|
||||
return "", errors.New("only AUD is supported for withdrawals")
|
||||
}
|
||||
return b.WithdrawAUD(withdrawRequest.BankAccountName, fmt.Sprintf("%v", withdrawRequest.BankAccountNumber), withdrawRequest.BankName, fmt.Sprintf("%v", withdrawRequest.BankCode), withdrawRequest.Amount)
|
||||
return b.WithdrawAUD(withdrawRequest.BankAccountName,
|
||||
strconv.FormatFloat(withdrawRequest.BankAccountNumber, 'f', -1, 64),
|
||||
withdrawRequest.BankName,
|
||||
strconv.FormatFloat(withdrawRequest.BankCode, 'f', -1, 64),
|
||||
withdrawRequest.Amount)
|
||||
}
|
||||
|
||||
// WithdrawFiatFundsToInternationalBank returns a withdrawal ID when a
|
||||
@@ -512,24 +513,24 @@ func (b *BTCMarkets) GetFeeByType(feeBuilder *exchange.FeeBuilder) (float64, err
|
||||
}
|
||||
|
||||
// GetActiveOrders retrieves any orders that are active/open
|
||||
func (b *BTCMarkets) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
func (b *BTCMarkets) GetActiveOrders(req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
resp, err := b.GetOpenOrders()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var orders []exchange.OrderDetail
|
||||
var orders []order.Detail
|
||||
for i := range resp {
|
||||
var side exchange.OrderSide
|
||||
if strings.EqualFold(resp[i].OrderSide, exchange.AskOrderSide.ToString()) {
|
||||
side = exchange.SellOrderSide
|
||||
} else if strings.EqualFold(resp[i].OrderSide, exchange.BidOrderSide.ToString()) {
|
||||
side = exchange.BuyOrderSide
|
||||
var side order.Side
|
||||
if strings.EqualFold(resp[i].OrderSide, order.Ask.String()) {
|
||||
side = order.Sell
|
||||
} else if strings.EqualFold(resp[i].OrderSide, order.Bid.String()) {
|
||||
side = order.Buy
|
||||
}
|
||||
orderDate := time.Unix(int64(resp[i].CreationTime), 0)
|
||||
orderType := exchange.OrderType(strings.ToUpper(resp[i].OrderType))
|
||||
orderType := order.Type(strings.ToUpper(resp[i].OrderType))
|
||||
|
||||
openOrder := exchange.OrderDetail{
|
||||
openOrder := order.Detail{
|
||||
ID: strconv.FormatInt(resp[i].ID, 10),
|
||||
Amount: resp[i].Volume,
|
||||
Exchange: b.Name,
|
||||
@@ -538,7 +539,7 @@ func (b *BTCMarkets) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest
|
||||
OrderSide: side,
|
||||
OrderType: orderType,
|
||||
Price: resp[i].Price,
|
||||
Status: resp[i].Status,
|
||||
Status: order.Status(resp[i].Status),
|
||||
CurrencyPair: currency.NewPairWithDelimiter(resp[i].Instrument,
|
||||
resp[i].Currency,
|
||||
b.GetPairFormat(asset.Spot, false).Delimiter),
|
||||
@@ -546,7 +547,7 @@ func (b *BTCMarkets) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest
|
||||
|
||||
for j := range resp[i].Trades {
|
||||
tradeDate := time.Unix(int64(resp[i].Trades[j].CreationTime), 0)
|
||||
openOrder.Trades = append(openOrder.Trades, exchange.TradeHistory{
|
||||
openOrder.Trades = append(openOrder.Trades, order.TradeHistory{
|
||||
Amount: resp[i].Trades[j].Volume,
|
||||
Exchange: b.Name,
|
||||
Price: resp[i].Trades[j].Price,
|
||||
@@ -560,24 +561,23 @@ func (b *BTCMarkets) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest
|
||||
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 *BTCMarkets) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
if len(getOrdersRequest.Currencies) == 0 {
|
||||
func (b *BTCMarkets) GetOrderHistory(req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
if len(req.Currencies) == 0 {
|
||||
return nil, errors.New("requires at least one currency pair to retrieve history")
|
||||
}
|
||||
|
||||
var respOrders []Order
|
||||
for _, currency := range getOrdersRequest.Currencies {
|
||||
resp, err := b.GetOrders(currency.Base.String(),
|
||||
currency.Quote.String(),
|
||||
for i := range req.Currencies {
|
||||
resp, err := b.GetOrders(req.Currencies[i].Base.String(),
|
||||
req.Currencies[i].Quote.String(),
|
||||
200,
|
||||
0,
|
||||
true)
|
||||
@@ -587,18 +587,18 @@ func (b *BTCMarkets) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest
|
||||
respOrders = append(respOrders, resp...)
|
||||
}
|
||||
|
||||
var orders []exchange.OrderDetail
|
||||
var orders []order.Detail
|
||||
for i := range respOrders {
|
||||
var side exchange.OrderSide
|
||||
if strings.EqualFold(respOrders[i].OrderSide, exchange.AskOrderSide.ToString()) {
|
||||
side = exchange.SellOrderSide
|
||||
} else if strings.EqualFold(respOrders[i].OrderSide, exchange.BidOrderSide.ToString()) {
|
||||
side = exchange.BuyOrderSide
|
||||
var side order.Side
|
||||
if strings.EqualFold(respOrders[i].OrderSide, order.Ask.String()) {
|
||||
side = order.Sell
|
||||
} else if strings.EqualFold(respOrders[i].OrderSide, order.Bid.String()) {
|
||||
side = order.Buy
|
||||
}
|
||||
orderDate := time.Unix(int64(respOrders[i].CreationTime), 0)
|
||||
orderType := exchange.OrderType(strings.ToUpper(respOrders[i].OrderType))
|
||||
orderType := order.Type(strings.ToUpper(respOrders[i].OrderType))
|
||||
|
||||
openOrder := exchange.OrderDetail{
|
||||
openOrder := order.Detail{
|
||||
ID: strconv.FormatInt(respOrders[i].ID, 10),
|
||||
Amount: respOrders[i].Volume,
|
||||
Exchange: b.Name,
|
||||
@@ -607,7 +607,7 @@ func (b *BTCMarkets) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest
|
||||
OrderSide: side,
|
||||
OrderType: orderType,
|
||||
Price: respOrders[i].Price,
|
||||
Status: respOrders[i].Status,
|
||||
Status: order.Status(respOrders[i].Status),
|
||||
CurrencyPair: currency.NewPairWithDelimiter(respOrders[i].Instrument,
|
||||
respOrders[i].Currency,
|
||||
b.GetPairFormat(asset.Spot, false).Delimiter),
|
||||
@@ -615,7 +615,7 @@ func (b *BTCMarkets) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest
|
||||
|
||||
for j := range respOrders[i].Trades {
|
||||
tradeDate := time.Unix(int64(respOrders[i].Trades[j].CreationTime), 0)
|
||||
openOrder.Trades = append(openOrder.Trades, exchange.TradeHistory{
|
||||
openOrder.Trades = append(openOrder.Trades, order.TradeHistory{
|
||||
Amount: respOrders[i].Trades[j].Volume,
|
||||
Exchange: b.Name,
|
||||
Price: respOrders[i].Trades[j].Price,
|
||||
@@ -628,9 +628,9 @@ func (b *BTCMarkets) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/common/crypto"
|
||||
"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/websocket/wshandler"
|
||||
log "github.com/thrasher-corp/gocryptotrader/logger"
|
||||
)
|
||||
@@ -288,7 +289,7 @@ func (c *CoinbasePro) GetHolds(accountID string) ([]AccountHolds, error) {
|
||||
func (c *CoinbasePro) PlaceLimitOrder(clientRef string, price, amount float64, side, timeInforce, cancelAfter, productID, stp string, postOnly bool) (string, error) {
|
||||
resp := GeneralizedOrderResponse{}
|
||||
req := make(map[string]interface{})
|
||||
req["type"] = exchange.LimitOrderType.ToLower().ToString()
|
||||
req["type"] = order.Limit.Lower()
|
||||
req["price"] = strconv.FormatFloat(price, 'f', -1, 64)
|
||||
req["size"] = strconv.FormatFloat(amount, 'f', -1, 64)
|
||||
req["side"] = side
|
||||
@@ -339,7 +340,7 @@ func (c *CoinbasePro) PlaceMarketOrder(clientRef string, size, funds float64, si
|
||||
req := make(map[string]interface{})
|
||||
req["side"] = side
|
||||
req["product_id"] = productID
|
||||
req["type"] = exchange.MarketOrderType.ToLower().ToString()
|
||||
req["type"] = order.Market.Lower()
|
||||
|
||||
if size != 0 {
|
||||
req["size"] = strconv.FormatFloat(size, 'f', -1, 64)
|
||||
|
||||
@@ -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"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/sharedtestvalues"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
)
|
||||
@@ -382,8 +383,8 @@ func TestGetActiveOrders(t *testing.T) {
|
||||
c.SetDefaults()
|
||||
TestSetup(t)
|
||||
|
||||
var getOrdersRequest = exchange.GetOrdersRequest{
|
||||
OrderType: exchange.AnyOrderType,
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
OrderType: order.AnyType,
|
||||
Currencies: []currency.Pair{currency.NewPair(currency.BTC,
|
||||
currency.LTC)},
|
||||
}
|
||||
@@ -400,8 +401,8 @@ func TestGetOrderHistory(t *testing.T) {
|
||||
c.SetDefaults()
|
||||
TestSetup(t)
|
||||
|
||||
var getOrdersRequest = exchange.GetOrdersRequest{
|
||||
OrderType: exchange.AnyOrderType,
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
OrderType: order.AnyType,
|
||||
Currencies: []currency.Pair{currency.NewPair(currency.BTC,
|
||||
currency.LTC)},
|
||||
}
|
||||
@@ -428,14 +429,14 @@ 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{
|
||||
Delimiter: "-",
|
||||
Base: currency.BTC,
|
||||
Quote: currency.USD,
|
||||
},
|
||||
OrderSide: exchange.BuyOrderSide,
|
||||
OrderType: exchange.LimitOrderType,
|
||||
OrderSide: order.Buy,
|
||||
OrderType: order.Limit,
|
||||
Price: 1,
|
||||
Amount: 1,
|
||||
ClientID: "meowOrder",
|
||||
@@ -459,7 +460,7 @@ func TestCancelExchangeOrder(t *testing.T) {
|
||||
|
||||
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
|
||||
var orderCancellation = &exchange.OrderCancellation{
|
||||
var orderCancellation = &order.Cancel{
|
||||
OrderID: "1",
|
||||
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
AccountID: "1",
|
||||
@@ -486,7 +487,7 @@ func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
|
||||
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
|
||||
var orderCancellation = &exchange.OrderCancellation{
|
||||
var orderCancellation = &order.Cancel{
|
||||
OrderID: "1",
|
||||
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
AccountID: "1",
|
||||
@@ -502,13 +503,13 @@ 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))
|
||||
}
|
||||
}
|
||||
|
||||
func TestModifyOrder(t *testing.T) {
|
||||
_, err := c.ModifyOrder(&exchange.ModifyOrder{})
|
||||
_, err := c.ModifyOrder(&order.Modify{})
|
||||
if err == nil {
|
||||
t.Error("ModifyOrder() Expected error")
|
||||
}
|
||||
|
||||
@@ -13,6 +13,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"
|
||||
@@ -240,7 +241,7 @@ func (c *CoinbasePro) ProcessUpdate(update WebsocketL2Update) error {
|
||||
price, _ := strconv.ParseFloat(update.Changes[i][1].(string), 64)
|
||||
volume, _ := strconv.ParseFloat(update.Changes[i][2].(string), 64)
|
||||
|
||||
if update.Changes[i][0].(string) == exchange.BuyOrderSide.ToLower().ToString() {
|
||||
if update.Changes[i][0].(string) == order.Buy.Lower() {
|
||||
bids = append(bids, orderbook.Item{Price: price, Amount: volume})
|
||||
} else {
|
||||
asks = append(asks, orderbook.Item{Price: price, Amount: volume})
|
||||
|
||||
@@ -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"
|
||||
@@ -186,7 +187,8 @@ func (c *CoinbasePro) Start(wg *sync.WaitGroup) {
|
||||
// Run implements the coinbasepro wrapper
|
||||
func (c *CoinbasePro) Run() {
|
||||
if c.Verbose {
|
||||
log.Debugf(log.ExchangeSys, "%s Websocket: %s. (url: %s).\n",
|
||||
log.Debugf(log.ExchangeSys,
|
||||
"%s Websocket: %s. (url: %s).\n",
|
||||
c.GetName(),
|
||||
common.IsEnabled(c.Websocket.IsEnabled()),
|
||||
coinbaseproWebsocketURL)
|
||||
@@ -369,34 +371,30 @@ func (c *CoinbasePro) GetExchangeHistory(p currency.Pair, assetType asset.Item)
|
||||
}
|
||||
|
||||
// SubmitOrder submits a new order
|
||||
func (c *CoinbasePro) 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 (c *CoinbasePro) SubmitOrder(s *order.Submit) (order.SubmitResponse, error) {
|
||||
var submitOrderResponse order.SubmitResponse
|
||||
if err := s.Validate(); err != nil {
|
||||
return submitOrderResponse, err
|
||||
}
|
||||
|
||||
var response string
|
||||
var err error
|
||||
switch order.OrderType {
|
||||
case exchange.MarketOrderType:
|
||||
switch s.OrderType {
|
||||
case order.Market:
|
||||
response, err = c.PlaceMarketOrder("",
|
||||
order.Amount,
|
||||
order.Amount,
|
||||
order.OrderSide.ToString(),
|
||||
c.FormatExchangeCurrency(order.Pair, asset.Spot).String(),
|
||||
s.Amount,
|
||||
s.Amount,
|
||||
s.OrderSide.String(),
|
||||
c.FormatExchangeCurrency(s.Pair, asset.Spot).String(),
|
||||
"")
|
||||
case exchange.LimitOrderType:
|
||||
case order.Limit:
|
||||
response, err = c.PlaceLimitOrder("",
|
||||
order.Price,
|
||||
order.Amount,
|
||||
order.OrderSide.ToString(),
|
||||
s.Price,
|
||||
s.Amount,
|
||||
s.OrderSide.String(),
|
||||
"",
|
||||
"",
|
||||
c.FormatExchangeCurrency(order.Pair, asset.Spot).String(),
|
||||
c.FormatExchangeCurrency(s.Pair, asset.Spot).String(),
|
||||
"",
|
||||
false)
|
||||
default:
|
||||
@@ -416,25 +414,25 @@ func (c *CoinbasePro) SubmitOrder(order *exchange.OrderSubmission) (exchange.Sub
|
||||
|
||||
// ModifyOrder will allow of changing orderbook placement and limit to
|
||||
// market conversion
|
||||
func (c *CoinbasePro) ModifyOrder(action *exchange.ModifyOrder) (string, error) {
|
||||
func (c *CoinbasePro) ModifyOrder(action *order.Modify) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// CancelOrder cancels an order by its corresponding ID number
|
||||
func (c *CoinbasePro) CancelOrder(order *exchange.OrderCancellation) error {
|
||||
func (c *CoinbasePro) CancelOrder(order *order.Cancel) error {
|
||||
return c.CancelExistingOrder(order.OrderID)
|
||||
}
|
||||
|
||||
// CancelAllOrders cancels all orders associated with a currency pair
|
||||
func (c *CoinbasePro) CancelAllOrders(_ *exchange.OrderCancellation) (exchange.CancelAllOrdersResponse, error) {
|
||||
func (c *CoinbasePro) CancelAllOrders(_ *order.Cancel) (order.CancelAllResponse, error) {
|
||||
// CancellAllExisting orders returns a list of successful cancellations, we're only interested in failures
|
||||
_, err := c.CancelAllExistingOrders("")
|
||||
return exchange.CancelAllOrdersResponse{}, err
|
||||
return order.CancelAllResponse{}, err
|
||||
}
|
||||
|
||||
// GetOrderInfo returns information on a current open order
|
||||
func (c *CoinbasePro) GetOrderInfo(orderID string) (exchange.OrderDetail, error) {
|
||||
var orderDetail exchange.OrderDetail
|
||||
func (c *CoinbasePro) GetOrderInfo(orderID string) (order.Detail, error) {
|
||||
var orderDetail order.Detail
|
||||
return orderDetail, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
@@ -498,30 +496,34 @@ func (c *CoinbasePro) GetFeeByType(feeBuilder *exchange.FeeBuilder) (float64, er
|
||||
}
|
||||
|
||||
// GetActiveOrders retrieves any orders that are active/open
|
||||
func (c *CoinbasePro) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
func (c *CoinbasePro) GetActiveOrders(req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
var respOrders []GeneralizedOrderResponse
|
||||
for i := range getOrdersRequest.Currencies {
|
||||
for i := range req.Currencies {
|
||||
resp, err := c.GetOrders([]string{"open", "pending", "active"},
|
||||
c.FormatExchangeCurrency(getOrdersRequest.Currencies[i], asset.Spot).String())
|
||||
c.FormatExchangeCurrency(req.Currencies[i], asset.Spot).String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
respOrders = append(respOrders, resp...)
|
||||
}
|
||||
|
||||
var orders []exchange.OrderDetail
|
||||
var orders []order.Detail
|
||||
for i := range respOrders {
|
||||
currency := currency.NewPairDelimiter(respOrders[i].ProductID,
|
||||
c.GetPairFormat(asset.Spot, false).Delimiter)
|
||||
orderSide := exchange.OrderSide(strings.ToUpper(respOrders[i].Side))
|
||||
orderType := exchange.OrderType(strings.ToUpper(respOrders[i].Type))
|
||||
orderSide := order.Side(strings.ToUpper(respOrders[i].Side))
|
||||
orderType := order.Type(strings.ToUpper(respOrders[i].Type))
|
||||
orderDate, err := time.Parse(time.RFC3339, respOrders[i].CreatedAt)
|
||||
if err != nil {
|
||||
log.Warnf(log.ExchangeSys, "Exchange %v Func %v Order %v Could not parse date to unix with value of %v",
|
||||
c.Name, "GetActiveOrders", respOrders[i].ID, respOrders[i].CreatedAt)
|
||||
log.Warnf(log.ExchangeSys,
|
||||
"Exchange %v Func %v Order %v Could not parse date to unix with value of %v",
|
||||
c.Name,
|
||||
"GetActiveOrders",
|
||||
respOrders[i].ID,
|
||||
respOrders[i].CreatedAt)
|
||||
}
|
||||
|
||||
orders = append(orders, exchange.OrderDetail{
|
||||
orders = append(orders, order.Detail{
|
||||
ID: respOrders[i].ID,
|
||||
Amount: respOrders[i].Size,
|
||||
ExecutedAmount: respOrders[i].FilledSize,
|
||||
@@ -533,17 +535,17 @@ func (c *CoinbasePro) GetActiveOrders(getOrdersRequest *exchange.GetOrdersReques
|
||||
})
|
||||
}
|
||||
|
||||
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 (c *CoinbasePro) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
func (c *CoinbasePro) GetOrderHistory(req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
var respOrders []GeneralizedOrderResponse
|
||||
for _, currency := range getOrdersRequest.Currencies {
|
||||
for _, currency := range req.Currencies {
|
||||
resp, err := c.GetOrders([]string{"done", "settled"},
|
||||
c.FormatExchangeCurrency(currency, asset.Spot).String())
|
||||
if err != nil {
|
||||
@@ -552,19 +554,23 @@ func (c *CoinbasePro) GetOrderHistory(getOrdersRequest *exchange.GetOrdersReques
|
||||
respOrders = append(respOrders, resp...)
|
||||
}
|
||||
|
||||
var orders []exchange.OrderDetail
|
||||
var orders []order.Detail
|
||||
for i := range respOrders {
|
||||
currency := currency.NewPairDelimiter(respOrders[i].ProductID,
|
||||
c.GetPairFormat(asset.Spot, false).Delimiter)
|
||||
orderSide := exchange.OrderSide(strings.ToUpper(respOrders[i].Side))
|
||||
orderType := exchange.OrderType(strings.ToUpper(respOrders[i].Type))
|
||||
orderSide := order.Side(strings.ToUpper(respOrders[i].Side))
|
||||
orderType := order.Type(strings.ToUpper(respOrders[i].Type))
|
||||
orderDate, err := time.Parse(time.RFC3339, respOrders[i].CreatedAt)
|
||||
if err != nil {
|
||||
log.Warnf(log.ExchangeSys, "Exchange %v Func %v Order %v Could not parse date to unix with value of %v",
|
||||
c.Name, "GetActiveOrders", respOrders[i].ID, respOrders[i].CreatedAt)
|
||||
log.Warnf(log.ExchangeSys,
|
||||
"Exchange %v Func %v Order %v Could not parse date to unix with value of %v",
|
||||
c.Name,
|
||||
"GetActiveOrders",
|
||||
respOrders[i].ID,
|
||||
respOrders[i].CreatedAt)
|
||||
}
|
||||
|
||||
orders = append(orders, exchange.OrderDetail{
|
||||
orders = append(orders, order.Detail{
|
||||
ID: respOrders[i].ID,
|
||||
Amount: respOrders[i].Size,
|
||||
ExecutedAmount: respOrders[i].FilledSize,
|
||||
@@ -576,10 +582,9 @@ func (c *CoinbasePro) GetOrderHistory(getOrdersRequest *exchange.GetOrdersReques
|
||||
})
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,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/websocket/wshandler"
|
||||
log "github.com/thrasher-corp/gocryptotrader/logger"
|
||||
)
|
||||
@@ -120,9 +121,9 @@ func (c *COINUT) NewOrder(instrumentID int64, quantity, price float64, buy bool,
|
||||
params["price"] = fmt.Sprintf("%v", price)
|
||||
}
|
||||
params["qty"] = fmt.Sprintf("%v", quantity)
|
||||
params["side"] = exchange.BuyOrderSide.ToString()
|
||||
params["side"] = order.Buy.String()
|
||||
if !buy {
|
||||
params["side"] = exchange.SellOrderSide.ToString()
|
||||
params["side"] = order.Sell.String()
|
||||
}
|
||||
params["client_ord_id"] = orderID
|
||||
|
||||
|
||||
@@ -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"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/sharedtestvalues"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
)
|
||||
@@ -262,8 +263,8 @@ func TestGetActiveOrders(t *testing.T) {
|
||||
c.SetDefaults()
|
||||
TestSetup(t)
|
||||
|
||||
var getOrdersRequest = exchange.GetOrdersRequest{
|
||||
OrderType: exchange.AnyOrderType,
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
OrderType: order.AnyType,
|
||||
}
|
||||
|
||||
_, err := c.GetActiveOrders(&getOrdersRequest)
|
||||
@@ -276,8 +277,8 @@ func TestGetOrderHistory(t *testing.T) {
|
||||
c.SetDefaults()
|
||||
TestSetup(t)
|
||||
|
||||
var getOrdersRequest = exchange.GetOrdersRequest{
|
||||
OrderType: exchange.AnyOrderType,
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
OrderType: order.AnyType,
|
||||
Currencies: []currency.Pair{currency.NewPair(currency.BTC,
|
||||
currency.LTC)},
|
||||
}
|
||||
@@ -302,13 +303,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.BTC,
|
||||
Quote: currency.USD,
|
||||
},
|
||||
OrderSide: exchange.BuyOrderSide,
|
||||
OrderType: exchange.LimitOrderType,
|
||||
OrderSide: order.Buy,
|
||||
OrderType: order.Limit,
|
||||
Price: 1,
|
||||
Amount: 1,
|
||||
ClientID: "meowOrder",
|
||||
@@ -332,7 +333,7 @@ func TestCancelExchangeOrder(t *testing.T) {
|
||||
|
||||
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
|
||||
var orderCancellation = &exchange.OrderCancellation{
|
||||
var orderCancellation = &order.Cancel{
|
||||
OrderID: "1",
|
||||
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
AccountID: "1",
|
||||
@@ -359,7 +360,7 @@ func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
|
||||
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
|
||||
var orderCancellation = &exchange.OrderCancellation{
|
||||
var orderCancellation = &order.Cancel{
|
||||
OrderID: "1",
|
||||
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
AccountID: "1",
|
||||
@@ -375,8 +376,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))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -395,7 +396,7 @@ func TestGetAccountInfo(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestModifyOrder(t *testing.T) {
|
||||
_, err := c.ModifyOrder(&exchange.ModifyOrder{})
|
||||
_, err := c.ModifyOrder(&order.Modify{})
|
||||
if err == nil {
|
||||
t.Error("ModifyOrder() Expected error")
|
||||
}
|
||||
@@ -480,7 +481,7 @@ func TestWsAuthSubmitOrder(t *testing.T) {
|
||||
Currency: currency.NewPair(currency.LTC, currency.BTC),
|
||||
OrderID: 1,
|
||||
Price: 1,
|
||||
Side: exchange.BuyOrderSide,
|
||||
Side: order.Buy,
|
||||
}
|
||||
_, err := c.wsSubmitOrder(&order)
|
||||
if err != nil {
|
||||
@@ -499,14 +500,14 @@ func TestWsAuthSubmitOrders(t *testing.T) {
|
||||
Currency: currency.NewPair(currency.LTC, currency.BTC),
|
||||
OrderID: 1,
|
||||
Price: 1,
|
||||
Side: exchange.BuyOrderSide,
|
||||
Side: order.Buy,
|
||||
}
|
||||
order2 := WsSubmitOrderParameters{
|
||||
Amount: 3,
|
||||
Currency: currency.NewPair(currency.LTC, currency.BTC),
|
||||
OrderID: 2,
|
||||
Price: 2,
|
||||
Side: exchange.BuyOrderSide,
|
||||
Side: order.Buy,
|
||||
}
|
||||
_, err := c.wsSubmitOrders([]WsSubmitOrderParameters{order1, order2})
|
||||
if err != nil {
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
)
|
||||
|
||||
// GenericResponse is the generic response you will get from coinut
|
||||
@@ -477,7 +477,7 @@ type WsSubmitOrderRequest struct {
|
||||
// WsSubmitOrderParameters ws request parameters
|
||||
type WsSubmitOrderParameters struct {
|
||||
Currency currency.Pair
|
||||
Side exchange.OrderSide
|
||||
Side order.Side
|
||||
Amount, Price float64
|
||||
OrderID int64
|
||||
}
|
||||
|
||||
@@ -13,6 +13,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"
|
||||
@@ -305,7 +306,7 @@ func (c *COINUT) WsProcessOrderbookUpdate(update *WsOrderbookUpdate) error {
|
||||
UpdateID: update.TransID,
|
||||
AssetType: asset.Spot,
|
||||
}
|
||||
if strings.EqualFold(update.Side, exchange.BuyOrderSide.ToLower().ToString()) {
|
||||
if strings.EqualFold(update.Side, order.Buy.Lower()) {
|
||||
bufferUpdate.Bids = []orderbook.Item{{Price: update.Price, Amount: update.Volume}}
|
||||
} else {
|
||||
bufferUpdate.Asks = []orderbook.Item{{Price: update.Price, Amount: update.Volume}}
|
||||
|
||||
@@ -13,6 +13,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"
|
||||
@@ -430,19 +431,15 @@ func (c *COINUT) GetExchangeHistory(p currency.Pair, assetType asset.Item) ([]ex
|
||||
}
|
||||
|
||||
// SubmitOrder submits a new order
|
||||
func (c *COINUT) 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 (c *COINUT) SubmitOrder(s *order.Submit) (order.SubmitResponse, error) {
|
||||
var submitOrderResponse order.SubmitResponse
|
||||
if err := s.Validate(); err != nil {
|
||||
return submitOrderResponse, err
|
||||
}
|
||||
|
||||
var APIresponse interface{}
|
||||
isBuyOrder := order.OrderSide == exchange.BuyOrderSide
|
||||
clientIDInt, err := strconv.ParseUint(order.ClientID, 0, 32)
|
||||
isBuyOrder := s.OrderSide == order.Buy
|
||||
clientIDInt, err := strconv.ParseUint(s.ClientID, 0, 32)
|
||||
if err != nil {
|
||||
return submitOrderResponse, err
|
||||
}
|
||||
@@ -456,32 +453,40 @@ func (c *COINUT) SubmitOrder(order *exchange.OrderSubmission) (exchange.SubmitOr
|
||||
}
|
||||
}
|
||||
|
||||
currencyID := c.instrumentMap.LookupID(c.FormatExchangeCurrency(order.Pair,
|
||||
currencyID := c.instrumentMap.LookupID(c.FormatExchangeCurrency(s.Pair,
|
||||
asset.Spot).String())
|
||||
if currencyID == 0 {
|
||||
return submitOrderResponse, errLookupInstrumentID
|
||||
}
|
||||
|
||||
switch order.OrderType {
|
||||
case exchange.LimitOrderType:
|
||||
APIresponse, err = c.NewOrder(currencyID, order.Amount, order.Price,
|
||||
isBuyOrder, clientIDUint)
|
||||
case exchange.MarketOrderType:
|
||||
APIresponse, err = c.NewOrder(currencyID, order.Amount, 0, isBuyOrder,
|
||||
switch s.OrderType {
|
||||
case order.Limit:
|
||||
APIresponse, err = c.NewOrder(currencyID,
|
||||
s.Amount,
|
||||
s.Price,
|
||||
isBuyOrder,
|
||||
clientIDUint)
|
||||
case order.Market:
|
||||
APIresponse, err = c.NewOrder(currencyID,
|
||||
s.Amount,
|
||||
0,
|
||||
isBuyOrder,
|
||||
clientIDUint)
|
||||
}
|
||||
|
||||
switch apiResp := APIresponse.(type) {
|
||||
case OrdersBase:
|
||||
orderResult := apiResp
|
||||
submitOrderResponse.OrderID = fmt.Sprintf("%v", orderResult.OrderID)
|
||||
submitOrderResponse.OrderID = strconv.FormatInt(orderResult.OrderID, 10)
|
||||
case OrderFilledResponse:
|
||||
orderResult := apiResp
|
||||
submitOrderResponse.OrderID = fmt.Sprintf("%v", orderResult.Order.OrderID)
|
||||
submitOrderResponse.OrderID = strconv.FormatInt(orderResult.Order.OrderID, 10)
|
||||
case OrderRejectResponse:
|
||||
orderResult := apiResp
|
||||
submitOrderResponse.OrderID = fmt.Sprintf("%v", orderResult.OrderID)
|
||||
err = fmt.Errorf("orderID: %v was rejected: %v", orderResult.OrderID, orderResult.Reasons)
|
||||
submitOrderResponse.OrderID = strconv.FormatInt(orderResult.OrderID, 10)
|
||||
err = fmt.Errorf("orderID: %d was rejected: %v",
|
||||
orderResult.OrderID,
|
||||
orderResult.Reasons)
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
@@ -493,12 +498,12 @@ func (c *COINUT) SubmitOrder(order *exchange.OrderSubmission) (exchange.SubmitOr
|
||||
|
||||
// ModifyOrder will allow of changing orderbook placement and limit to
|
||||
// market conversion
|
||||
func (c *COINUT) ModifyOrder(action *exchange.ModifyOrder) (string, error) {
|
||||
func (c *COINUT) ModifyOrder(action *order.Modify) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// CancelOrder cancels an order by its corresponding ID number
|
||||
func (c *COINUT) CancelOrder(order *exchange.OrderCancellation) error {
|
||||
func (c *COINUT) CancelOrder(order *order.Cancel) error {
|
||||
orderIDInt, err := strconv.ParseInt(order.OrderID, 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -523,13 +528,14 @@ func (c *COINUT) CancelOrder(order *exchange.OrderCancellation) error {
|
||||
}
|
||||
|
||||
// CancelAllOrders cancels all orders associated with a currency pair
|
||||
func (c *COINUT) CancelAllOrders(_ *exchange.OrderCancellation) (exchange.CancelAllOrdersResponse, error) {
|
||||
func (c *COINUT) CancelAllOrders(_ *order.Cancel) (order.CancelAllResponse, error) {
|
||||
// TODO, this is a terrible implementation. Requires DB to improve
|
||||
// Coinut provides no way of retrieving orders without a currency
|
||||
// So we need to retrieve all currencies, then retrieve orders for each currency
|
||||
// Then cancel. Advisable to never use this until DB due to performance
|
||||
cancelAllOrdersResponse := exchange.CancelAllOrdersResponse{
|
||||
OrderStatus: make(map[string]string),
|
||||
// So we need to retrieve all currencies, then retrieve orders for each
|
||||
// currency then cancel. Advisable to never use this until DB due to
|
||||
// performance.
|
||||
cancelAllOrdersResponse := order.CancelAllResponse{
|
||||
Status: make(map[string]string),
|
||||
}
|
||||
|
||||
if !c.instrumentMap.IsLoaded() {
|
||||
@@ -566,7 +572,7 @@ func (c *COINUT) CancelAllOrders(_ *exchange.OrderCancellation) (exchange.Cancel
|
||||
|
||||
for _, order := range resp.Results {
|
||||
if order.Status != "OK" {
|
||||
cancelAllOrdersResponse.OrderStatus[strconv.FormatInt(order.OrderID, 10)] = order.Status
|
||||
cancelAllOrdersResponse.Status[strconv.FormatInt(order.OrderID, 10)] = order.Status
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -575,8 +581,8 @@ func (c *COINUT) CancelAllOrders(_ *exchange.OrderCancellation) (exchange.Cancel
|
||||
}
|
||||
|
||||
// GetOrderInfo returns information on a current open order
|
||||
func (c *COINUT) GetOrderInfo(orderID string) (exchange.OrderDetail, error) {
|
||||
return exchange.OrderDetail{}, common.ErrNotYetImplemented
|
||||
func (c *COINUT) GetOrderInfo(orderID string) (order.Detail, error) {
|
||||
return order.Detail{}, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
// GetDepositAddress returns a deposit address for a specified currency
|
||||
@@ -617,7 +623,7 @@ func (c *COINUT) GetFeeByType(feeBuilder *exchange.FeeBuilder) (float64, error)
|
||||
}
|
||||
|
||||
// GetActiveOrders retrieves any orders that are active/open
|
||||
func (c *COINUT) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
func (c *COINUT) GetActiveOrders(req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
if !c.instrumentMap.IsLoaded() {
|
||||
err := c.SeedInstruments()
|
||||
if err != nil {
|
||||
@@ -626,9 +632,9 @@ func (c *COINUT) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([
|
||||
}
|
||||
|
||||
var instrumentsToUse []int64
|
||||
if len(getOrdersRequest.Currencies) > 0 {
|
||||
for x := range getOrdersRequest.Currencies {
|
||||
currency := c.FormatExchangeCurrency(getOrdersRequest.Currencies[x],
|
||||
if len(req.Currencies) > 0 {
|
||||
for x := range req.Currencies {
|
||||
currency := c.FormatExchangeCurrency(req.Currencies[x],
|
||||
asset.Spot).String()
|
||||
instrumentsToUse = append(instrumentsToUse,
|
||||
c.instrumentMap.LookupID(currency))
|
||||
@@ -641,7 +647,7 @@ func (c *COINUT) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([
|
||||
return nil, errors.New("no instrument IDs to use")
|
||||
}
|
||||
|
||||
var orders []exchange.OrderDetail
|
||||
var orders []order.Detail
|
||||
for x := range instrumentsToUse {
|
||||
openOrders, err := c.GetOpenOrders(instrumentsToUse[x])
|
||||
if err != nil {
|
||||
@@ -652,9 +658,9 @@ func (c *COINUT) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([
|
||||
p := currency.NewPairFromFormattedPairs(curr,
|
||||
c.GetEnabledPairs(asset.Spot),
|
||||
c.GetPairFormat(asset.Spot, true))
|
||||
orderSide := exchange.OrderSide(strings.ToUpper(openOrders.Orders[y].Side))
|
||||
orderSide := order.Side(strings.ToUpper(openOrders.Orders[y].Side))
|
||||
orderDate := time.Unix(openOrders.Orders[y].Timestamp, 0)
|
||||
orders = append(orders, exchange.OrderDetail{
|
||||
orders = append(orders, order.Detail{
|
||||
ID: strconv.FormatInt(openOrders.Orders[y].OrderID, 10),
|
||||
Amount: openOrders.Orders[y].Quantity,
|
||||
Price: openOrders.Orders[y].Price,
|
||||
@@ -666,14 +672,14 @@ func (c *COINUT) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([
|
||||
}
|
||||
}
|
||||
|
||||
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks, getOrdersRequest.EndTicks)
|
||||
exchange.FilterOrdersBySide(&orders, getOrdersRequest.OrderSide)
|
||||
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 (c *COINUT) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
func (c *COINUT) GetOrderHistory(req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
if !c.instrumentMap.IsLoaded() {
|
||||
err := c.SeedInstruments()
|
||||
if err != nil {
|
||||
@@ -682,9 +688,9 @@ func (c *COINUT) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([
|
||||
}
|
||||
|
||||
var instrumentsToUse []int64
|
||||
if len(getOrdersRequest.Currencies) > 0 {
|
||||
for x := range getOrdersRequest.Currencies {
|
||||
currency := c.FormatExchangeCurrency(getOrdersRequest.Currencies[x],
|
||||
if len(req.Currencies) > 0 {
|
||||
for x := range req.Currencies {
|
||||
currency := c.FormatExchangeCurrency(req.Currencies[x],
|
||||
asset.Spot).String()
|
||||
instrumentsToUse = append(instrumentsToUse,
|
||||
c.instrumentMap.LookupID(currency))
|
||||
@@ -697,7 +703,7 @@ func (c *COINUT) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([
|
||||
return nil, errors.New("no instrument IDs to use")
|
||||
}
|
||||
|
||||
var allOrders []exchange.OrderDetail
|
||||
var allOrders []order.Detail
|
||||
for x := range instrumentsToUse {
|
||||
orders, err := c.GetTradeHistory(instrumentsToUse[x], -1, -1)
|
||||
if err != nil {
|
||||
@@ -708,10 +714,9 @@ func (c *COINUT) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([
|
||||
p := currency.NewPairFromFormattedPairs(curr,
|
||||
c.GetEnabledPairs(asset.Spot),
|
||||
c.GetPairFormat(asset.Spot, true))
|
||||
orderSide := exchange.OrderSide(
|
||||
strings.ToUpper(orders.Trades[y].Order.Side))
|
||||
orderSide := order.Side(strings.ToUpper(orders.Trades[y].Order.Side))
|
||||
orderDate := time.Unix(orders.Trades[y].Order.Timestamp, 0)
|
||||
allOrders = append(allOrders, exchange.OrderDetail{
|
||||
allOrders = append(allOrders, order.Detail{
|
||||
ID: strconv.FormatInt(orders.Trades[y].Order.OrderID, 10),
|
||||
Amount: orders.Trades[y].Order.Quantity,
|
||||
Price: orders.Trades[y].Order.Price,
|
||||
@@ -724,9 +729,8 @@ func (c *COINUT) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([
|
||||
|
||||
}
|
||||
|
||||
exchange.FilterOrdersByTickRange(&allOrders, getOrdersRequest.StartTicks,
|
||||
getOrdersRequest.EndTicks)
|
||||
exchange.FilterOrdersBySide(&allOrders, getOrdersRequest.OrderSide)
|
||||
order.FilterOrdersByTickRange(&allOrders, req.StartTicks, req.EndTicks)
|
||||
order.FilterOrdersBySide(&allOrders, req.OrderSide)
|
||||
return allOrders, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -1314,319 +1314,6 @@ func TestFormatWithdrawPermissions(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestOrderSides(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var os = BuyOrderSide
|
||||
if os.ToString() != "BUY" {
|
||||
t.Errorf("unexpected string %s", os.ToString())
|
||||
}
|
||||
|
||||
if os.ToLower() != "buy" {
|
||||
t.Errorf("unexpected string %s", os.ToString())
|
||||
}
|
||||
}
|
||||
|
||||
func TestOrderTypes(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var ot OrderType = "Mo'Money"
|
||||
|
||||
if ot.ToString() != "Mo'Money" {
|
||||
t.Errorf("unexpected string %s", ot.ToString())
|
||||
}
|
||||
|
||||
if ot.ToLower() != "mo'money" {
|
||||
t.Errorf("unexpected string %s", ot.ToString())
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterOrdersByType(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var orders = []OrderDetail{
|
||||
{
|
||||
OrderType: ImmediateOrCancelOrderType,
|
||||
},
|
||||
{
|
||||
OrderType: LimitOrderType,
|
||||
},
|
||||
}
|
||||
|
||||
FilterOrdersByType(&orders, AnyOrderType)
|
||||
if len(orders) != 2 {
|
||||
t.Errorf("Orders failed to be filtered. Expected %v, received %v", 2, len(orders))
|
||||
}
|
||||
|
||||
FilterOrdersByType(&orders, LimitOrderType)
|
||||
if len(orders) != 1 {
|
||||
t.Errorf("Orders failed to be filtered. Expected %v, received %v", 1, len(orders))
|
||||
}
|
||||
|
||||
FilterOrdersByType(&orders, StopOrderType)
|
||||
if len(orders) != 0 {
|
||||
t.Errorf("Orders failed to be filtered. Expected %v, received %v", 0, len(orders))
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterOrdersBySide(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var orders = []OrderDetail{
|
||||
{
|
||||
OrderSide: BuyOrderSide,
|
||||
},
|
||||
{
|
||||
OrderSide: SellOrderSide,
|
||||
},
|
||||
{},
|
||||
}
|
||||
|
||||
FilterOrdersBySide(&orders, AnyOrderSide)
|
||||
if len(orders) != 3 {
|
||||
t.Errorf("Orders failed to be filtered. Expected %v, received %v", 3, len(orders))
|
||||
}
|
||||
|
||||
FilterOrdersBySide(&orders, BuyOrderSide)
|
||||
if len(orders) != 1 {
|
||||
t.Errorf("Orders failed to be filtered. Expected %v, received %v", 1, len(orders))
|
||||
}
|
||||
|
||||
FilterOrdersBySide(&orders, SellOrderSide)
|
||||
if len(orders) != 0 {
|
||||
t.Errorf("Orders failed to be filtered. Expected %v, received %v", 0, len(orders))
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterOrdersByTickRange(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var orders = []OrderDetail{
|
||||
{
|
||||
OrderDate: time.Unix(100, 0),
|
||||
},
|
||||
{
|
||||
OrderDate: time.Unix(110, 0),
|
||||
},
|
||||
{
|
||||
OrderDate: time.Unix(111, 0),
|
||||
},
|
||||
}
|
||||
|
||||
FilterOrdersByTickRange(&orders, time.Unix(0, 0), time.Unix(0, 0))
|
||||
if len(orders) != 3 {
|
||||
t.Errorf("Orders failed to be filtered. Expected %v, received %v", 3, len(orders))
|
||||
}
|
||||
|
||||
FilterOrdersByTickRange(&orders, time.Unix(100, 0), time.Unix(111, 0))
|
||||
if len(orders) != 3 {
|
||||
t.Errorf("Orders failed to be filtered. Expected %v, received %v", 3, len(orders))
|
||||
}
|
||||
|
||||
FilterOrdersByTickRange(&orders, time.Unix(101, 0), time.Unix(111, 0))
|
||||
if len(orders) != 2 {
|
||||
t.Errorf("Orders failed to be filtered. Expected %v, received %v", 2, len(orders))
|
||||
}
|
||||
|
||||
FilterOrdersByTickRange(&orders, time.Unix(200, 0), time.Unix(300, 0))
|
||||
if len(orders) != 0 {
|
||||
t.Errorf("Orders failed to be filtered. Expected %v, received %v", 0, len(orders))
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterOrdersByCurrencies(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var orders = []OrderDetail{
|
||||
{
|
||||
CurrencyPair: currency.NewPair(currency.BTC, currency.USD),
|
||||
},
|
||||
{
|
||||
CurrencyPair: currency.NewPair(currency.LTC, currency.EUR),
|
||||
},
|
||||
{
|
||||
CurrencyPair: currency.NewPair(currency.DOGE, currency.RUB),
|
||||
},
|
||||
}
|
||||
|
||||
currencies := []currency.Pair{currency.NewPair(currency.BTC, currency.USD),
|
||||
currency.NewPair(currency.LTC, currency.EUR),
|
||||
currency.NewPair(currency.DOGE, currency.RUB)}
|
||||
FilterOrdersByCurrencies(&orders, currencies)
|
||||
if len(orders) != 3 {
|
||||
t.Errorf("Orders failed to be filtered. Expected %v, received %v", 3, len(orders))
|
||||
}
|
||||
|
||||
currencies = []currency.Pair{currency.NewPair(currency.BTC, currency.USD),
|
||||
currency.NewPair(currency.LTC, currency.EUR)}
|
||||
FilterOrdersByCurrencies(&orders, currencies)
|
||||
if len(orders) != 2 {
|
||||
t.Errorf("Orders failed to be filtered. Expected %v, received %v", 2, len(orders))
|
||||
}
|
||||
|
||||
currencies = []currency.Pair{currency.NewPair(currency.BTC, currency.USD)}
|
||||
FilterOrdersByCurrencies(&orders, currencies)
|
||||
if len(orders) != 1 {
|
||||
t.Errorf("Orders failed to be filtered. Expected %v, received %v", 1, len(orders))
|
||||
}
|
||||
|
||||
currencies = []currency.Pair{}
|
||||
FilterOrdersByCurrencies(&orders, currencies)
|
||||
if len(orders) != 1 {
|
||||
t.Errorf("Orders failed to be filtered. Expected %v, received %v", 1, len(orders))
|
||||
}
|
||||
}
|
||||
|
||||
func TestSortOrdersByPrice(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
orders := []OrderDetail{
|
||||
{
|
||||
Price: 100,
|
||||
}, {
|
||||
Price: 0,
|
||||
}, {
|
||||
Price: 50,
|
||||
},
|
||||
}
|
||||
|
||||
SortOrdersByPrice(&orders, false)
|
||||
if orders[0].Price != 0 {
|
||||
t.Errorf("Expected: '%v', received: '%v'", 0, orders[0].Price)
|
||||
}
|
||||
|
||||
SortOrdersByPrice(&orders, true)
|
||||
if orders[0].Price != 100 {
|
||||
t.Errorf("Expected: '%v', received: '%v'", 100, orders[0].Price)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSortOrdersByDate(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
orders := []OrderDetail{
|
||||
{
|
||||
OrderDate: time.Unix(0, 0),
|
||||
}, {
|
||||
OrderDate: time.Unix(1, 0),
|
||||
}, {
|
||||
OrderDate: time.Unix(2, 0),
|
||||
},
|
||||
}
|
||||
|
||||
SortOrdersByDate(&orders, false)
|
||||
if orders[0].OrderDate.Unix() != time.Unix(0, 0).Unix() {
|
||||
t.Errorf("Expected: '%v', received: '%v'",
|
||||
time.Unix(0, 0).Unix(),
|
||||
orders[0].OrderDate.Unix())
|
||||
}
|
||||
|
||||
SortOrdersByDate(&orders, true)
|
||||
if orders[0].OrderDate.Unix() != time.Unix(2, 0).Unix() {
|
||||
t.Errorf("Expected: '%v', received: '%v'",
|
||||
time.Unix(2, 0).Unix(),
|
||||
orders[0].OrderDate.Unix())
|
||||
}
|
||||
}
|
||||
|
||||
func TestSortOrdersByCurrency(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
orders := []OrderDetail{
|
||||
{
|
||||
CurrencyPair: currency.NewPairWithDelimiter(currency.BTC.String(),
|
||||
currency.USD.String(),
|
||||
"-"),
|
||||
}, {
|
||||
CurrencyPair: currency.NewPairWithDelimiter(currency.DOGE.String(),
|
||||
currency.USD.String(),
|
||||
"-"),
|
||||
}, {
|
||||
CurrencyPair: currency.NewPairWithDelimiter(currency.BTC.String(),
|
||||
currency.RUB.String(),
|
||||
"-"),
|
||||
}, {
|
||||
CurrencyPair: currency.NewPairWithDelimiter(currency.LTC.String(),
|
||||
currency.EUR.String(),
|
||||
"-"),
|
||||
}, {
|
||||
CurrencyPair: currency.NewPairWithDelimiter(currency.LTC.String(),
|
||||
currency.AUD.String(),
|
||||
"-"),
|
||||
},
|
||||
}
|
||||
|
||||
SortOrdersByCurrency(&orders, false)
|
||||
if orders[0].CurrencyPair.String() != currency.BTC.String()+"-"+currency.RUB.String() {
|
||||
t.Errorf("Expected: '%v', received: '%v'",
|
||||
currency.BTC.String()+"-"+currency.RUB.String(),
|
||||
orders[0].CurrencyPair.String())
|
||||
}
|
||||
|
||||
SortOrdersByCurrency(&orders, true)
|
||||
if orders[0].CurrencyPair.String() != currency.LTC.String()+"-"+currency.EUR.String() {
|
||||
t.Errorf("Expected: '%v', received: '%v'",
|
||||
currency.LTC.String()+"-"+currency.EUR.String(),
|
||||
orders[0].CurrencyPair.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestSortOrdersByOrderSide(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
orders := []OrderDetail{
|
||||
{
|
||||
OrderSide: BuyOrderSide,
|
||||
}, {
|
||||
OrderSide: SellOrderSide,
|
||||
}, {
|
||||
OrderSide: SellOrderSide,
|
||||
}, {
|
||||
OrderSide: BuyOrderSide,
|
||||
},
|
||||
}
|
||||
|
||||
SortOrdersBySide(&orders, false)
|
||||
if !strings.EqualFold(orders[0].OrderSide.ToString(), BuyOrderSide.ToString()) {
|
||||
t.Errorf("Expected: '%v', received: '%v'",
|
||||
BuyOrderSide,
|
||||
orders[0].OrderSide)
|
||||
}
|
||||
|
||||
SortOrdersBySide(&orders, true)
|
||||
if !strings.EqualFold(orders[0].OrderSide.ToString(), SellOrderSide.ToString()) {
|
||||
t.Errorf("Expected: '%v', received: '%v'",
|
||||
SellOrderSide,
|
||||
orders[0].OrderSide)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSortOrdersByOrderType(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
orders := []OrderDetail{
|
||||
{
|
||||
OrderType: MarketOrderType,
|
||||
}, {
|
||||
OrderType: LimitOrderType,
|
||||
}, {
|
||||
OrderType: ImmediateOrCancelOrderType,
|
||||
}, {
|
||||
OrderType: TrailingStopOrderType,
|
||||
},
|
||||
}
|
||||
|
||||
SortOrdersByType(&orders, false)
|
||||
if !strings.EqualFold(orders[0].OrderType.ToString(), ImmediateOrCancelOrderType.ToString()) {
|
||||
t.Errorf("Expected: '%v', received: '%v'", ImmediateOrCancelOrderType, orders[0].OrderType)
|
||||
}
|
||||
|
||||
SortOrdersByType(&orders, true)
|
||||
if !strings.EqualFold(orders[0].OrderType.ToString(), TrailingStopOrderType.ToString()) {
|
||||
t.Errorf("Expected: '%v', received: '%v'", TrailingStopOrderType, orders[0].OrderType)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsAssetTypeSupported(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
||||
@@ -8,6 +8,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"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -269,8 +270,8 @@ func TestGetActiveOrders(t *testing.T) {
|
||||
e.SetDefaults()
|
||||
TestSetup(t)
|
||||
|
||||
var getOrdersRequest = exchange.GetOrdersRequest{
|
||||
OrderType: exchange.AnyOrderType,
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
OrderType: order.AnyType,
|
||||
}
|
||||
|
||||
_, err := e.GetActiveOrders(&getOrdersRequest)
|
||||
@@ -285,8 +286,8 @@ func TestGetOrderHistory(t *testing.T) {
|
||||
e.SetDefaults()
|
||||
TestSetup(t)
|
||||
|
||||
var getOrdersRequest = exchange.GetOrdersRequest{
|
||||
OrderType: exchange.AnyOrderType,
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
OrderType: order.AnyType,
|
||||
}
|
||||
currPair := currency.NewPair(currency.BTC, currency.USD)
|
||||
currPair.Delimiter = "_"
|
||||
@@ -313,14 +314,14 @@ 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{
|
||||
Delimiter: "_",
|
||||
Base: currency.BTC,
|
||||
Quote: currency.USD,
|
||||
},
|
||||
OrderSide: exchange.BuyOrderSide,
|
||||
OrderType: exchange.LimitOrderType,
|
||||
OrderSide: order.Buy,
|
||||
OrderType: order.Limit,
|
||||
Price: 1,
|
||||
Amount: 1,
|
||||
ClientID: "meowOrder",
|
||||
@@ -343,7 +344,7 @@ func TestCancelExchangeOrder(t *testing.T) {
|
||||
|
||||
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
|
||||
var orderCancellation = &exchange.OrderCancellation{
|
||||
var orderCancellation = &order.Cancel{
|
||||
OrderID: "1",
|
||||
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
AccountID: "1",
|
||||
@@ -369,7 +370,7 @@ func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
}
|
||||
|
||||
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
var orderCancellation = &exchange.OrderCancellation{
|
||||
var orderCancellation = &order.Cancel{
|
||||
OrderID: "1",
|
||||
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
AccountID: "1",
|
||||
@@ -385,13 +386,13 @@ 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))
|
||||
}
|
||||
}
|
||||
|
||||
func TestModifyOrder(t *testing.T) {
|
||||
_, err := e.ModifyOrder(&exchange.ModifyOrder{})
|
||||
_, err := e.ModifyOrder(&order.Modify{})
|
||||
if err == nil {
|
||||
t.Error("ModifyOrder() Expected error")
|
||||
}
|
||||
|
||||
@@ -13,6 +13,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"
|
||||
@@ -227,7 +228,8 @@ func (e *EXMO) FetchOrderbook(p currency.Pair, assetType asset.Item) (orderbook.
|
||||
// UpdateOrderbook updates and returns the orderbook for a currency pair
|
||||
func (e *EXMO) UpdateOrderbook(p currency.Pair, assetType asset.Item) (orderbook.Base, error) {
|
||||
var orderBook orderbook.Base
|
||||
pairsCollated, err := e.FormatExchangeCurrencies(e.GetEnabledPairs(assetType), assetType)
|
||||
pairsCollated, err := e.FormatExchangeCurrencies(e.GetEnabledPairs(assetType),
|
||||
assetType)
|
||||
if err != nil {
|
||||
return orderBook, err
|
||||
}
|
||||
@@ -249,7 +251,8 @@ func (e *EXMO) UpdateOrderbook(p currency.Pair, assetType asset.Item) (orderbook
|
||||
z := data.Ask[y]
|
||||
price, _ := strconv.ParseFloat(z[0], 64)
|
||||
amount, _ := strconv.ParseFloat(z[1], 64)
|
||||
obItems = append(obItems, orderbook.Item{Price: price, Amount: amount})
|
||||
obItems = append(obItems,
|
||||
orderbook.Item{Price: price, Amount: amount})
|
||||
}
|
||||
|
||||
orderBook.Asks = obItems
|
||||
@@ -258,7 +261,8 @@ func (e *EXMO) UpdateOrderbook(p currency.Pair, assetType asset.Item) (orderbook
|
||||
z := data.Bid[y]
|
||||
price, _ := strconv.ParseFloat(z[0], 64)
|
||||
amount, _ := strconv.ParseFloat(z[1], 64)
|
||||
obItems = append(obItems, orderbook.Item{Price: price, Amount: amount})
|
||||
obItems = append(obItems,
|
||||
orderbook.Item{Price: price, Amount: amount})
|
||||
}
|
||||
|
||||
orderBook.Bids = obItems
|
||||
@@ -319,31 +323,30 @@ func (e *EXMO) GetExchangeHistory(p currency.Pair, assetType asset.Item) ([]exch
|
||||
}
|
||||
|
||||
// SubmitOrder submits a new order
|
||||
func (e *EXMO) 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 (e *EXMO) SubmitOrder(s *order.Submit) (order.SubmitResponse, error) {
|
||||
var submitOrderResponse order.SubmitResponse
|
||||
if err := s.Validate(); err != nil {
|
||||
return submitOrderResponse, err
|
||||
}
|
||||
|
||||
var oT string
|
||||
switch order.OrderType {
|
||||
case exchange.LimitOrderType:
|
||||
switch s.OrderType {
|
||||
case order.Limit:
|
||||
return submitOrderResponse, errors.New("unsupported order type")
|
||||
case exchange.MarketOrderType:
|
||||
oT = "market_buy"
|
||||
if order.OrderSide == exchange.SellOrderSide {
|
||||
case order.Market:
|
||||
if s.OrderSide == order.Sell {
|
||||
oT = "market_sell"
|
||||
} else {
|
||||
oT = "market_buy"
|
||||
}
|
||||
}
|
||||
|
||||
response, err := e.CreateOrder(order.Pair.String(), oT, order.Price,
|
||||
order.Amount)
|
||||
response, err := e.CreateOrder(s.Pair.String(),
|
||||
oT,
|
||||
s.Price,
|
||||
s.Amount)
|
||||
if response > 0 {
|
||||
submitOrderResponse.OrderID = fmt.Sprintf("%v", response)
|
||||
submitOrderResponse.OrderID = strconv.FormatInt(response, 10)
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
@@ -355,12 +358,12 @@ func (e *EXMO) SubmitOrder(order *exchange.OrderSubmission) (exchange.SubmitOrde
|
||||
|
||||
// ModifyOrder will allow of changing orderbook placement and limit to
|
||||
// market conversion
|
||||
func (e *EXMO) ModifyOrder(action *exchange.ModifyOrder) (string, error) {
|
||||
func (e *EXMO) ModifyOrder(action *order.Modify) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// CancelOrder cancels an order by its corresponding ID number
|
||||
func (e *EXMO) CancelOrder(order *exchange.OrderCancellation) error {
|
||||
func (e *EXMO) CancelOrder(order *order.Cancel) error {
|
||||
orderIDInt, err := strconv.ParseInt(order.OrderID, 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -370,9 +373,9 @@ func (e *EXMO) CancelOrder(order *exchange.OrderCancellation) error {
|
||||
}
|
||||
|
||||
// CancelAllOrders cancels all orders associated with a currency pair
|
||||
func (e *EXMO) CancelAllOrders(_ *exchange.OrderCancellation) (exchange.CancelAllOrdersResponse, error) {
|
||||
cancelAllOrdersResponse := exchange.CancelAllOrdersResponse{
|
||||
OrderStatus: make(map[string]string),
|
||||
func (e *EXMO) CancelAllOrders(_ *order.Cancel) (order.CancelAllResponse, error) {
|
||||
cancelAllOrdersResponse := order.CancelAllResponse{
|
||||
Status: make(map[string]string),
|
||||
}
|
||||
|
||||
openOrders, err := e.GetOpenOrders()
|
||||
@@ -383,7 +386,7 @@ func (e *EXMO) CancelAllOrders(_ *exchange.OrderCancellation) (exchange.CancelAl
|
||||
for _, order := range openOrders {
|
||||
err = e.CancelExistingOrder(order.OrderID)
|
||||
if err != nil {
|
||||
cancelAllOrdersResponse.OrderStatus[strconv.FormatInt(order.OrderID, 10)] = err.Error()
|
||||
cancelAllOrdersResponse.Status[strconv.FormatInt(order.OrderID, 10)] = err.Error()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -391,8 +394,8 @@ func (e *EXMO) CancelAllOrders(_ *exchange.OrderCancellation) (exchange.CancelAl
|
||||
}
|
||||
|
||||
// GetOrderInfo returns information on a current open order
|
||||
func (e *EXMO) GetOrderInfo(orderID string) (exchange.OrderDetail, error) {
|
||||
var orderDetail exchange.OrderDetail
|
||||
func (e *EXMO) GetOrderInfo(orderID string) (order.Detail, error) {
|
||||
var orderDetail order.Detail
|
||||
return orderDetail, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
@@ -419,7 +422,7 @@ func (e *EXMO) WithdrawCryptocurrencyFunds(withdrawRequest *exchange.CryptoWithd
|
||||
withdrawRequest.AddressTag,
|
||||
withdrawRequest.Amount)
|
||||
|
||||
return fmt.Sprintf("%v", resp), err
|
||||
return strconv.FormatInt(resp, 10), err
|
||||
}
|
||||
|
||||
// WithdrawFiatFunds returns a withdrawal ID when a
|
||||
@@ -449,43 +452,42 @@ func (e *EXMO) GetFeeByType(feeBuilder *exchange.FeeBuilder) (float64, error) {
|
||||
}
|
||||
|
||||
// GetActiveOrders retrieves any orders that are active/open
|
||||
func (e *EXMO) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
func (e *EXMO) GetActiveOrders(req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
resp, err := e.GetOpenOrders()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var orders []exchange.OrderDetail
|
||||
for _, order := range resp {
|
||||
symbol := currency.NewPairDelimiter(order.Pair, "_")
|
||||
orderDate := time.Unix(order.Created, 0)
|
||||
orderSide := exchange.OrderSide(strings.ToUpper(order.Type))
|
||||
orders = append(orders, exchange.OrderDetail{
|
||||
ID: fmt.Sprintf("%v", order.OrderID),
|
||||
Amount: order.Quantity,
|
||||
var orders []order.Detail
|
||||
for i := range resp {
|
||||
symbol := currency.NewPairDelimiter(resp[i].Pair, "_")
|
||||
orderDate := time.Unix(resp[i].Created, 0)
|
||||
orderSide := order.Side(strings.ToUpper(resp[i].Type))
|
||||
orders = append(orders, order.Detail{
|
||||
ID: strconv.FormatInt(resp[i].OrderID, 10),
|
||||
Amount: resp[i].Quantity,
|
||||
OrderDate: orderDate,
|
||||
Price: order.Price,
|
||||
Price: resp[i].Price,
|
||||
OrderSide: orderSide,
|
||||
Exchange: e.Name,
|
||||
CurrencyPair: symbol,
|
||||
})
|
||||
}
|
||||
|
||||
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks,
|
||||
getOrdersRequest.EndTicks)
|
||||
exchange.FilterOrdersBySide(&orders, getOrdersRequest.OrderSide)
|
||||
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 (e *EXMO) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
if len(getOrdersRequest.Currencies) == 0 {
|
||||
func (e *EXMO) GetOrderHistory(req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
if len(req.Currencies) == 0 {
|
||||
return nil, errors.New("currency must be supplied")
|
||||
}
|
||||
|
||||
var allTrades []UserTrades
|
||||
for _, currency := range getOrdersRequest.Currencies {
|
||||
for _, currency := range req.Currencies {
|
||||
resp, err := e.GetUserTrades(e.FormatExchangeCurrency(currency, asset.Spot).String(), "", "10000")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -495,25 +497,24 @@ func (e *EXMO) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([]e
|
||||
}
|
||||
}
|
||||
|
||||
var orders []exchange.OrderDetail
|
||||
for _, order := range allTrades {
|
||||
symbol := currency.NewPairDelimiter(order.Pair, "_")
|
||||
orderDate := time.Unix(order.Date, 0)
|
||||
orderSide := exchange.OrderSide(strings.ToUpper(order.Type))
|
||||
orders = append(orders, exchange.OrderDetail{
|
||||
ID: fmt.Sprintf("%v", order.TradeID),
|
||||
Amount: order.Quantity,
|
||||
var orders []order.Detail
|
||||
for i := range allTrades {
|
||||
symbol := currency.NewPairDelimiter(allTrades[i].Pair, "_")
|
||||
orderDate := time.Unix(allTrades[i].Date, 0)
|
||||
orderSide := order.Side(strings.ToUpper(allTrades[i].Type))
|
||||
orders = append(orders, order.Detail{
|
||||
ID: strconv.FormatInt(allTrades[i].TradeID, 10),
|
||||
Amount: allTrades[i].Quantity,
|
||||
OrderDate: orderDate,
|
||||
Price: order.Price,
|
||||
Price: allTrades[i].Price,
|
||||
OrderSide: orderSide,
|
||||
Exchange: e.Name,
|
||||
CurrencyPair: symbol,
|
||||
})
|
||||
}
|
||||
|
||||
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks,
|
||||
getOrdersRequest.EndTicks)
|
||||
exchange.FilterOrdersBySide(&orders, getOrdersRequest.OrderSide)
|
||||
order.FilterOrdersByTickRange(&orders, req.StartTicks, req.EndTicks)
|
||||
order.FilterOrdersBySide(&orders, req.OrderSide)
|
||||
return orders, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -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"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/sharedtestvalues"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
)
|
||||
@@ -76,7 +77,7 @@ func TestSpotNewOrder(t *testing.T) {
|
||||
Symbol: "btc_usdt",
|
||||
Amount: 1.1,
|
||||
Price: 10.1,
|
||||
Type: exchange.SellOrderSide.ToLower().ToString(),
|
||||
Type: order.Sell.Lower(),
|
||||
})
|
||||
if err != nil {
|
||||
t.Errorf("Gateio SpotNewOrder: %s", err)
|
||||
@@ -278,8 +279,8 @@ func TestGetActiveOrders(t *testing.T) {
|
||||
g.SetDefaults()
|
||||
TestSetup(t)
|
||||
|
||||
var getOrdersRequest = exchange.GetOrdersRequest{
|
||||
OrderType: exchange.AnyOrderType,
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
OrderType: order.AnyType,
|
||||
}
|
||||
|
||||
_, err := g.GetActiveOrders(&getOrdersRequest)
|
||||
@@ -294,8 +295,8 @@ func TestGetOrderHistory(t *testing.T) {
|
||||
g.SetDefaults()
|
||||
TestSetup(t)
|
||||
|
||||
var getOrdersRequest = exchange.GetOrdersRequest{
|
||||
OrderType: exchange.AnyOrderType,
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
OrderType: order.AnyType,
|
||||
}
|
||||
|
||||
currPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
@@ -324,14 +325,14 @@ func TestSubmitOrder(t *testing.T) {
|
||||
t.Skip()
|
||||
}
|
||||
|
||||
var orderSubmission = &exchange.OrderSubmission{
|
||||
var orderSubmission = &order.Submit{
|
||||
Pair: currency.Pair{
|
||||
Delimiter: "_",
|
||||
Base: currency.LTC,
|
||||
Quote: currency.BTC,
|
||||
},
|
||||
OrderSide: exchange.BuyOrderSide,
|
||||
OrderType: exchange.LimitOrderType,
|
||||
OrderSide: order.Buy,
|
||||
OrderType: order.Limit,
|
||||
Price: 1,
|
||||
Amount: 1,
|
||||
ClientID: "meowOrder",
|
||||
@@ -354,7 +355,7 @@ func TestCancelExchangeOrder(t *testing.T) {
|
||||
|
||||
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
|
||||
var orderCancellation = &exchange.OrderCancellation{
|
||||
var orderCancellation = &order.Cancel{
|
||||
OrderID: "1",
|
||||
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
AccountID: "1",
|
||||
@@ -380,7 +381,7 @@ func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
|
||||
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
|
||||
var orderCancellation = &exchange.OrderCancellation{
|
||||
var orderCancellation = &order.Cancel{
|
||||
OrderID: "1",
|
||||
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
AccountID: "1",
|
||||
@@ -396,8 +397,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))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -416,7 +417,7 @@ func TestGetAccountInfo(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestModifyOrder(t *testing.T) {
|
||||
_, err := g.ModifyOrder(&exchange.ModifyOrder{})
|
||||
_, err := g.ModifyOrder(&order.Modify{})
|
||||
if err == nil {
|
||||
t.Error("ModifyOrder() Expected error")
|
||||
}
|
||||
|
||||
@@ -13,6 +13,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"
|
||||
@@ -376,33 +377,29 @@ func (g *Gateio) GetExchangeHistory(p currency.Pair, assetType asset.Item) ([]ex
|
||||
|
||||
// SubmitOrder submits a new order
|
||||
// TODO: support multiple order types (IOC)
|
||||
func (g *Gateio) 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 (g *Gateio) SubmitOrder(s *order.Submit) (order.SubmitResponse, error) {
|
||||
var submitOrderResponse order.SubmitResponse
|
||||
if err := s.Validate(); err != nil {
|
||||
return submitOrderResponse, err
|
||||
}
|
||||
|
||||
var orderTypeFormat string
|
||||
if order.OrderSide == exchange.BuyOrderSide {
|
||||
orderTypeFormat = exchange.BuyOrderSide.ToLower().ToString()
|
||||
if s.OrderSide == order.Buy {
|
||||
orderTypeFormat = order.Buy.Lower()
|
||||
} else {
|
||||
orderTypeFormat = exchange.SellOrderSide.ToLower().ToString()
|
||||
orderTypeFormat = order.Sell.Lower()
|
||||
}
|
||||
|
||||
var spotNewOrderRequestParams = SpotNewOrderRequestParams{
|
||||
Amount: order.Amount,
|
||||
Price: order.Price,
|
||||
Symbol: order.Pair.String(),
|
||||
Amount: s.Amount,
|
||||
Price: s.Price,
|
||||
Symbol: s.Pair.String(),
|
||||
Type: orderTypeFormat,
|
||||
}
|
||||
|
||||
response, err := g.SpotNewOrder(spotNewOrderRequestParams)
|
||||
if response.OrderNumber > 0 {
|
||||
submitOrderResponse.OrderID = fmt.Sprintf("%v", response.OrderNumber)
|
||||
submitOrderResponse.OrderID = strconv.FormatInt(response.OrderNumber, 10)
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
@@ -414,27 +411,25 @@ func (g *Gateio) SubmitOrder(order *exchange.OrderSubmission) (exchange.SubmitOr
|
||||
|
||||
// ModifyOrder will allow of changing orderbook placement and limit to
|
||||
// market conversion
|
||||
func (g *Gateio) ModifyOrder(action *exchange.ModifyOrder) (string, error) {
|
||||
func (g *Gateio) ModifyOrder(action *order.Modify) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// CancelOrder cancels an order by its corresponding ID number
|
||||
func (g *Gateio) CancelOrder(order *exchange.OrderCancellation) error {
|
||||
func (g *Gateio) CancelOrder(order *order.Cancel) error {
|
||||
orderIDInt, err := strconv.ParseInt(order.OrderID, 10, 64)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = g.CancelExistingOrder(orderIDInt, g.FormatExchangeCurrency(order.CurrencyPair,
|
||||
order.AssetType).String())
|
||||
|
||||
_, err = g.CancelExistingOrder(orderIDInt,
|
||||
g.FormatExchangeCurrency(order.CurrencyPair, order.AssetType).String())
|
||||
return err
|
||||
}
|
||||
|
||||
// CancelAllOrders cancels all orders associated with a currency pair
|
||||
func (g *Gateio) CancelAllOrders(_ *exchange.OrderCancellation) (exchange.CancelAllOrdersResponse, error) {
|
||||
cancelAllOrdersResponse := exchange.CancelAllOrdersResponse{
|
||||
OrderStatus: make(map[string]string),
|
||||
func (g *Gateio) CancelAllOrders(_ *order.Cancel) (order.CancelAllResponse, error) {
|
||||
cancelAllOrdersResponse := order.CancelAllResponse{
|
||||
Status: make(map[string]string),
|
||||
}
|
||||
openOrders, err := g.GetOpenOrders("")
|
||||
if err != nil {
|
||||
@@ -449,7 +444,7 @@ func (g *Gateio) CancelAllOrders(_ *exchange.OrderCancellation) (exchange.Cancel
|
||||
for unique := range uniqueSymbols {
|
||||
err = g.CancelAllExistingOrders(-1, unique)
|
||||
if err != nil {
|
||||
cancelAllOrdersResponse.OrderStatus[unique] = err.Error()
|
||||
cancelAllOrdersResponse.Status[unique] = err.Error()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -457,8 +452,8 @@ func (g *Gateio) CancelAllOrders(_ *exchange.OrderCancellation) (exchange.Cancel
|
||||
}
|
||||
|
||||
// GetOrderInfo returns information on a current open order
|
||||
func (g *Gateio) GetOrderInfo(orderID string) (exchange.OrderDetail, error) {
|
||||
var orderDetail exchange.OrderDetail
|
||||
func (g *Gateio) GetOrderInfo(orderID string) (order.Detail, error) {
|
||||
var orderDetail order.Detail
|
||||
|
||||
orders, err := g.GetOpenOrders("")
|
||||
if err != nil {
|
||||
@@ -474,14 +469,14 @@ func (g *Gateio) GetOrderInfo(orderID string) (exchange.OrderDetail, error) {
|
||||
orderDetail.ExecutedAmount = orders.Orders[x].FilledAmount
|
||||
orderDetail.Amount = orders.Orders[x].InitialAmount
|
||||
orderDetail.OrderDate = time.Unix(orders.Orders[x].Timestamp, 0)
|
||||
orderDetail.Status = orders.Orders[x].Status
|
||||
orderDetail.Status = order.Status(orders.Orders[x].Status)
|
||||
orderDetail.Price = orders.Orders[x].Rate
|
||||
orderDetail.CurrencyPair = currency.NewPairDelimiter(orders.Orders[x].CurrencyPair,
|
||||
g.GetPairFormat(asset.Spot, false).Delimiter)
|
||||
if strings.EqualFold(orders.Orders[x].Type, exchange.AskOrderSide.ToString()) {
|
||||
orderDetail.OrderSide = exchange.AskOrderSide
|
||||
} else if strings.EqualFold(orders.Orders[x].Type, exchange.BidOrderSide.ToString()) {
|
||||
orderDetail.OrderSide = exchange.BuyOrderSide
|
||||
if strings.EqualFold(orders.Orders[x].Type, order.Ask.String()) {
|
||||
orderDetail.OrderSide = order.Ask
|
||||
} else if strings.EqualFold(orders.Orders[x].Type, order.Bid.String()) {
|
||||
orderDetail.OrderSide = order.Buy
|
||||
}
|
||||
return orderDetail, nil
|
||||
}
|
||||
@@ -495,21 +490,11 @@ func (g *Gateio) GetDepositAddress(cryptocurrency currency.Code, _ string) (stri
|
||||
return "", err
|
||||
}
|
||||
|
||||
// Waits for new generated address if not created yet, its variable per
|
||||
// currency
|
||||
if addr == gateioGenerateAddress {
|
||||
time.Sleep(10 * time.Second)
|
||||
addr, err = g.GetCryptoDepositAddress(cryptocurrency.String())
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if addr == gateioGenerateAddress {
|
||||
return "", errors.New("new deposit address is being generated, please retry again shortly")
|
||||
}
|
||||
return addr, nil
|
||||
return "",
|
||||
errors.New("new deposit address is being generated, please retry again shortly")
|
||||
}
|
||||
|
||||
return addr, err
|
||||
return addr, nil
|
||||
}
|
||||
|
||||
// WithdrawCryptocurrencyFunds returns a withdrawal ID when a withdrawal is
|
||||
@@ -545,10 +530,10 @@ func (g *Gateio) GetFeeByType(feeBuilder *exchange.FeeBuilder) (float64, error)
|
||||
}
|
||||
|
||||
// GetActiveOrders retrieves any orders that are active/open
|
||||
func (g *Gateio) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
func (g *Gateio) GetActiveOrders(req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
var currPair string
|
||||
if len(getOrdersRequest.Currencies) == 1 {
|
||||
currPair = getOrdersRequest.Currencies[0].String()
|
||||
if len(req.Currencies) == 1 {
|
||||
currPair = req.Currencies[0].String()
|
||||
}
|
||||
|
||||
resp, err := g.GetOpenOrders(currPair)
|
||||
@@ -556,7 +541,7 @@ func (g *Gateio) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var orders []exchange.OrderDetail
|
||||
var orders []order.Detail
|
||||
for i := range resp.Orders {
|
||||
if resp.Orders[i].Status != "open" {
|
||||
continue
|
||||
@@ -564,10 +549,10 @@ func (g *Gateio) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([
|
||||
|
||||
symbol := currency.NewPairDelimiter(resp.Orders[i].CurrencyPair,
|
||||
g.GetPairFormat(asset.Spot, false).Delimiter)
|
||||
side := exchange.OrderSide(strings.ToUpper(resp.Orders[i].Type))
|
||||
side := order.Side(strings.ToUpper(resp.Orders[i].Type))
|
||||
orderDate := time.Unix(resp.Orders[i].Timestamp, 0)
|
||||
|
||||
orders = append(orders, exchange.OrderDetail{
|
||||
orders = append(orders, order.Detail{
|
||||
ID: resp.Orders[i].OrderNumber,
|
||||
Amount: resp.Orders[i].Amount,
|
||||
Price: resp.Orders[i].Rate,
|
||||
@@ -576,20 +561,20 @@ func (g *Gateio) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([
|
||||
OrderSide: side,
|
||||
Exchange: g.Name,
|
||||
CurrencyPair: symbol,
|
||||
Status: resp.Orders[i].Status,
|
||||
Status: order.Status(resp.Orders[i].Status),
|
||||
})
|
||||
}
|
||||
|
||||
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks, getOrdersRequest.EndTicks)
|
||||
exchange.FilterOrdersBySide(&orders, getOrdersRequest.OrderSide)
|
||||
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 (g *Gateio) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
func (g *Gateio) GetOrderHistory(req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
var trades []TradesResponse
|
||||
for _, currency := range getOrdersRequest.Currencies {
|
||||
for _, currency := range req.Currencies {
|
||||
resp, err := g.GetTradeHistory(currency.String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -597,13 +582,13 @@ func (g *Gateio) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([
|
||||
trades = append(trades, resp.Trades...)
|
||||
}
|
||||
|
||||
var orders []exchange.OrderDetail
|
||||
var orders []order.Detail
|
||||
for _, trade := range trades {
|
||||
symbol := currency.NewPairDelimiter(trade.Pair,
|
||||
g.GetPairFormat(asset.Spot, false).Delimiter)
|
||||
side := exchange.OrderSide(strings.ToUpper(trade.Type))
|
||||
side := order.Side(strings.ToUpper(trade.Type))
|
||||
orderDate := time.Unix(trade.TimeUnix, 0)
|
||||
orders = append(orders, exchange.OrderDetail{
|
||||
orders = append(orders, order.Detail{
|
||||
ID: strconv.FormatInt(trade.OrderID, 10),
|
||||
Amount: trade.Amount,
|
||||
Price: trade.Rate,
|
||||
@@ -614,9 +599,8 @@ func (g *Gateio) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([
|
||||
})
|
||||
}
|
||||
|
||||
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks,
|
||||
getOrdersRequest.EndTicks)
|
||||
exchange.FilterOrdersBySide(&orders, getOrdersRequest.OrderSide)
|
||||
order.FilterOrdersByTickRange(&orders, req.StartTicks, req.EndTicks)
|
||||
order.FilterOrdersBySide(&orders, req.OrderSide)
|
||||
return orders, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"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/order"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/sharedtestvalues"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
)
|
||||
@@ -343,8 +344,8 @@ func TestFormatWithdrawPermissions(t *testing.T) {
|
||||
|
||||
func TestGetActiveOrders(t *testing.T) {
|
||||
t.Parallel()
|
||||
var getOrdersRequest = exchange.GetOrdersRequest{
|
||||
OrderType: exchange.AnyOrderType,
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
OrderType: order.AnyType,
|
||||
Currencies: []currency.Pair{
|
||||
currency.NewPair(currency.LTC, currency.BTC),
|
||||
},
|
||||
@@ -363,8 +364,8 @@ func TestGetActiveOrders(t *testing.T) {
|
||||
|
||||
func TestGetOrderHistory(t *testing.T) {
|
||||
t.Parallel()
|
||||
var getOrdersRequest = exchange.GetOrdersRequest{
|
||||
OrderType: exchange.AnyOrderType,
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
OrderType: order.AnyType,
|
||||
Currencies: []currency.Pair{currency.NewPair(currency.LTC, currency.BTC)},
|
||||
}
|
||||
|
||||
@@ -391,14 +392,14 @@ 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{
|
||||
Delimiter: "_",
|
||||
Base: currency.LTC,
|
||||
Quote: currency.BTC,
|
||||
},
|
||||
OrderSide: exchange.BuyOrderSide,
|
||||
OrderType: exchange.LimitOrderType,
|
||||
OrderSide: order.Buy,
|
||||
OrderType: order.Limit,
|
||||
Price: 10,
|
||||
Amount: 1,
|
||||
ClientID: "1234234",
|
||||
@@ -421,7 +422,7 @@ func TestCancelExchangeOrder(t *testing.T) {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
var orderCancellation = &exchange.OrderCancellation{
|
||||
var orderCancellation = &order.Cancel{
|
||||
OrderID: "266029865",
|
||||
}
|
||||
|
||||
@@ -444,7 +445,7 @@ func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
|
||||
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
|
||||
var orderCancellation = &exchange.OrderCancellation{
|
||||
var orderCancellation = &order.Cancel{
|
||||
OrderID: "1",
|
||||
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
AccountID: "1",
|
||||
@@ -461,14 +462,14 @@ 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))
|
||||
}
|
||||
}
|
||||
|
||||
func TestModifyOrder(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := g.ModifyOrder(&exchange.ModifyOrder{})
|
||||
_, err := g.ModifyOrder(&order.Modify{})
|
||||
if err == nil {
|
||||
t.Error("ModifyOrder() Expected error")
|
||||
}
|
||||
|
||||
@@ -16,6 +16,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"
|
||||
@@ -310,7 +311,7 @@ func (g *Gemini) wsProcessUpdate(result WsMarketUpdateResponse, pair currency.Pa
|
||||
Amount: result.Events[i].Remaining,
|
||||
Price: result.Events[i].Price,
|
||||
}
|
||||
if strings.EqualFold(result.Events[i].Side, exchange.AskOrderSide.ToString()) {
|
||||
if strings.EqualFold(result.Events[i].Side, order.Ask.String()) {
|
||||
asks = append(asks, item)
|
||||
} else {
|
||||
bids = append(bids, item)
|
||||
|
||||
@@ -2,7 +2,6 @@ package gemini
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -14,6 +13,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"
|
||||
@@ -317,28 +317,25 @@ func (g *Gemini) GetExchangeHistory(p currency.Pair, assetType asset.Item) ([]ex
|
||||
}
|
||||
|
||||
// SubmitOrder submits a new order
|
||||
func (g *Gemini) 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 (g *Gemini) SubmitOrder(s *order.Submit) (order.SubmitResponse, error) {
|
||||
var submitOrderResponse order.SubmitResponse
|
||||
if err := s.Validate(); err != nil {
|
||||
return submitOrderResponse, err
|
||||
}
|
||||
|
||||
if order.OrderType != exchange.LimitOrderType {
|
||||
return submitOrderResponse, errors.New("only limit orders are enabled through this exchange")
|
||||
if s.OrderType != order.Limit {
|
||||
return submitOrderResponse,
|
||||
errors.New("only limit orders are enabled through this exchange")
|
||||
}
|
||||
|
||||
response, err := g.NewOrder(
|
||||
g.FormatExchangeCurrency(order.Pair, asset.Spot).String(),
|
||||
order.Amount,
|
||||
order.Price,
|
||||
order.OrderSide.ToString(),
|
||||
g.FormatExchangeCurrency(s.Pair, asset.Spot).String(),
|
||||
s.Amount,
|
||||
s.Price,
|
||||
s.OrderSide.String(),
|
||||
"exchange limit")
|
||||
if response > 0 {
|
||||
submitOrderResponse.OrderID = fmt.Sprintf("%v", response)
|
||||
submitOrderResponse.OrderID = strconv.FormatInt(response, 10)
|
||||
}
|
||||
if err == nil {
|
||||
submitOrderResponse.IsOrderPlaced = true
|
||||
@@ -348,12 +345,12 @@ func (g *Gemini) SubmitOrder(order *exchange.OrderSubmission) (exchange.SubmitOr
|
||||
|
||||
// ModifyOrder will allow of changing orderbook placement and limit to
|
||||
// market conversion
|
||||
func (g *Gemini) ModifyOrder(action *exchange.ModifyOrder) (string, error) {
|
||||
func (g *Gemini) ModifyOrder(action *order.Modify) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// CancelOrder cancels an order by its corresponding ID number
|
||||
func (g *Gemini) CancelOrder(order *exchange.OrderCancellation) error {
|
||||
func (g *Gemini) CancelOrder(order *order.Cancel) error {
|
||||
orderIDInt, err := strconv.ParseInt(order.OrderID, 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -364,9 +361,9 @@ func (g *Gemini) CancelOrder(order *exchange.OrderCancellation) error {
|
||||
}
|
||||
|
||||
// CancelAllOrders cancels all orders associated with a currency pair
|
||||
func (g *Gemini) CancelAllOrders(_ *exchange.OrderCancellation) (exchange.CancelAllOrdersResponse, error) {
|
||||
cancelAllOrdersResponse := exchange.CancelAllOrdersResponse{
|
||||
OrderStatus: make(map[string]string),
|
||||
func (g *Gemini) CancelAllOrders(_ *order.Cancel) (order.CancelAllResponse, error) {
|
||||
cancelAllOrdersResponse := order.CancelAllResponse{
|
||||
Status: make(map[string]string),
|
||||
}
|
||||
resp, err := g.CancelExistingOrders(false)
|
||||
if err != nil {
|
||||
@@ -374,15 +371,15 @@ func (g *Gemini) CancelAllOrders(_ *exchange.OrderCancellation) (exchange.Cancel
|
||||
}
|
||||
|
||||
for _, order := range resp.Details.CancelRejects {
|
||||
cancelAllOrdersResponse.OrderStatus[order] = "Could not cancel order"
|
||||
cancelAllOrdersResponse.Status[order] = "Could not cancel order"
|
||||
}
|
||||
|
||||
return cancelAllOrdersResponse, nil
|
||||
}
|
||||
|
||||
// GetOrderInfo returns information on a current open order
|
||||
func (g *Gemini) GetOrderInfo(orderID string) (exchange.OrderDetail, error) {
|
||||
var orderDetail exchange.OrderDetail
|
||||
func (g *Gemini) GetOrderInfo(orderID string) (order.Detail, error) {
|
||||
var orderDetail order.Detail
|
||||
return orderDetail, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
@@ -436,30 +433,30 @@ func (g *Gemini) GetFeeByType(feeBuilder *exchange.FeeBuilder) (float64, error)
|
||||
}
|
||||
|
||||
// GetActiveOrders retrieves any orders that are active/open
|
||||
func (g *Gemini) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
func (g *Gemini) GetActiveOrders(req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
resp, err := g.GetOrders()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var orders []exchange.OrderDetail
|
||||
var orders []order.Detail
|
||||
for i := range resp {
|
||||
symbol := currency.NewPairDelimiter(resp[i].Symbol,
|
||||
g.GetPairFormat(asset.Spot, false).Delimiter)
|
||||
var orderType exchange.OrderType
|
||||
var orderType order.Type
|
||||
if resp[i].Type == "exchange limit" {
|
||||
orderType = exchange.LimitOrderType
|
||||
orderType = order.Limit
|
||||
} else if resp[i].Type == "market buy" || resp[i].Type == "market sell" {
|
||||
orderType = exchange.MarketOrderType
|
||||
orderType = order.Market
|
||||
}
|
||||
|
||||
side := exchange.OrderSide(strings.ToUpper(resp[i].Type))
|
||||
side := order.Side(strings.ToUpper(resp[i].Type))
|
||||
orderDate := time.Unix(resp[i].Timestamp, 0)
|
||||
|
||||
orders = append(orders, exchange.OrderDetail{
|
||||
orders = append(orders, order.Detail{
|
||||
Amount: resp[i].OriginalAmount,
|
||||
RemainingAmount: resp[i].RemainingAmount,
|
||||
ID: fmt.Sprintf("%v", resp[i].OrderID),
|
||||
ID: strconv.FormatInt(resp[i].OrderID, 10),
|
||||
ExecutedAmount: resp[i].ExecutedAmount,
|
||||
Exchange: g.Name,
|
||||
OrderType: orderType,
|
||||
@@ -470,44 +467,44 @@ func (g *Gemini) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([
|
||||
})
|
||||
}
|
||||
|
||||
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks,
|
||||
getOrdersRequest.EndTicks)
|
||||
exchange.FilterOrdersBySide(&orders, getOrdersRequest.OrderSide)
|
||||
exchange.FilterOrdersByType(&orders, getOrdersRequest.OrderType)
|
||||
exchange.FilterOrdersByCurrencies(&orders, getOrdersRequest.Currencies)
|
||||
order.FilterOrdersByTickRange(&orders, req.StartTicks, req.EndTicks)
|
||||
order.FilterOrdersBySide(&orders, req.OrderSide)
|
||||
order.FilterOrdersByType(&orders, req.OrderType)
|
||||
order.FilterOrdersByCurrencies(&orders, req.Currencies)
|
||||
return orders, nil
|
||||
}
|
||||
|
||||
// GetOrderHistory retrieves account order information
|
||||
// Can Limit response to specific order status
|
||||
func (g *Gemini) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
if len(getOrdersRequest.Currencies) == 0 {
|
||||
func (g *Gemini) GetOrderHistory(req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
if len(req.Currencies) == 0 {
|
||||
return nil, errors.New("currency must be supplied")
|
||||
}
|
||||
|
||||
var trades []TradeHistory
|
||||
for _, currency := range getOrdersRequest.Currencies {
|
||||
resp, err := g.GetTradeHistory(g.FormatExchangeCurrency(currency,
|
||||
asset.Spot).String(), getOrdersRequest.StartTicks.Unix())
|
||||
for j := range req.Currencies {
|
||||
resp, err := g.GetTradeHistory(g.FormatExchangeCurrency(req.Currencies[j],
|
||||
asset.Spot).String(),
|
||||
req.StartTicks.Unix())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for i := range resp {
|
||||
resp[i].BaseCurrency = currency.Base.String()
|
||||
resp[i].QuoteCurrency = currency.Quote.String()
|
||||
resp[i].BaseCurrency = req.Currencies[j].Base.String()
|
||||
resp[i].QuoteCurrency = req.Currencies[j].Quote.String()
|
||||
trades = append(trades, resp[i])
|
||||
}
|
||||
}
|
||||
|
||||
var orders []exchange.OrderDetail
|
||||
var orders []order.Detail
|
||||
for i := range trades {
|
||||
side := exchange.OrderSide(strings.ToUpper(trades[i].Type))
|
||||
side := order.Side(strings.ToUpper(trades[i].Type))
|
||||
orderDate := time.Unix(trades[i].Timestamp, 0)
|
||||
|
||||
orders = append(orders, exchange.OrderDetail{
|
||||
orders = append(orders, order.Detail{
|
||||
Amount: trades[i].Amount,
|
||||
ID: fmt.Sprintf("%v", trades[i].OrderID),
|
||||
ID: strconv.FormatInt(trades[i].OrderID, 10),
|
||||
Exchange: g.Name,
|
||||
OrderDate: orderDate,
|
||||
OrderSide: side,
|
||||
@@ -519,9 +516,8 @@ func (g *Gemini) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([
|
||||
})
|
||||
}
|
||||
|
||||
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks,
|
||||
getOrdersRequest.EndTicks)
|
||||
exchange.FilterOrdersBySide(&orders, getOrdersRequest.OrderSide)
|
||||
order.FilterOrdersByTickRange(&orders, req.StartTicks, req.EndTicks)
|
||||
order.FilterOrdersBySide(&orders, req.OrderSide)
|
||||
return orders, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,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/sharedtestvalues"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
)
|
||||
@@ -232,8 +233,8 @@ func TestGetActiveOrders(t *testing.T) {
|
||||
h.SetDefaults()
|
||||
TestSetup(t)
|
||||
|
||||
var getOrdersRequest = exchange.GetOrdersRequest{
|
||||
OrderType: exchange.AnyOrderType,
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
OrderType: order.AnyType,
|
||||
Currencies: []currency.Pair{currency.NewPair(currency.ETH, currency.BTC)},
|
||||
}
|
||||
|
||||
@@ -249,8 +250,8 @@ func TestGetOrderHistory(t *testing.T) {
|
||||
h.SetDefaults()
|
||||
TestSetup(t)
|
||||
|
||||
var getOrdersRequest = exchange.GetOrdersRequest{
|
||||
OrderType: exchange.AnyOrderType,
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
OrderType: order.AnyType,
|
||||
Currencies: []currency.Pair{currency.NewPair(currency.ETH, currency.BTC)},
|
||||
}
|
||||
|
||||
@@ -276,13 +277,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.DGD,
|
||||
Quote: currency.BTC,
|
||||
},
|
||||
OrderSide: exchange.BuyOrderSide,
|
||||
OrderType: exchange.LimitOrderType,
|
||||
OrderSide: order.Buy,
|
||||
OrderType: order.Limit,
|
||||
Price: 1,
|
||||
Amount: 1,
|
||||
ClientID: "meowOrder",
|
||||
@@ -305,7 +306,7 @@ func TestCancelExchangeOrder(t *testing.T) {
|
||||
|
||||
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
|
||||
var orderCancellation = &exchange.OrderCancellation{
|
||||
var orderCancellation = &order.Cancel{
|
||||
OrderID: "1",
|
||||
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
AccountID: "1",
|
||||
@@ -331,7 +332,7 @@ func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
|
||||
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
|
||||
var orderCancellation = &exchange.OrderCancellation{
|
||||
var orderCancellation = &order.Cancel{
|
||||
OrderID: "1",
|
||||
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
AccountID: "1",
|
||||
@@ -347,13 +348,13 @@ 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))
|
||||
}
|
||||
}
|
||||
|
||||
func TestModifyOrder(t *testing.T) {
|
||||
_, err := h.ModifyOrder(&exchange.ModifyOrder{})
|
||||
_, err := h.ModifyOrder(&order.Modify{})
|
||||
if err == nil {
|
||||
t.Error("ModifyOrder() Expected error")
|
||||
}
|
||||
@@ -480,7 +481,10 @@ func TestWsPlaceOrder(t *testing.T) {
|
||||
if !canManipulateRealOrders {
|
||||
t.Skip("canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
_, err := h.wsPlaceOrder(currency.NewPair(currency.LTC, currency.BTC), exchange.BuyOrderSide.ToString(), 1, 1)
|
||||
_, err := h.wsPlaceOrder(currency.NewPair(currency.LTC, currency.BTC),
|
||||
order.Buy.String(),
|
||||
1,
|
||||
1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -13,6 +13,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"
|
||||
@@ -340,17 +341,18 @@ func (h *HitBTC) GetAccountInfo() (exchange.AccountInfo, error) {
|
||||
}
|
||||
|
||||
var currencies []exchange.AccountCurrencyInfo
|
||||
for _, item := range accountBalance {
|
||||
for i := range accountBalance {
|
||||
var exchangeCurrency exchange.AccountCurrencyInfo
|
||||
exchangeCurrency.CurrencyName = currency.NewCode(item.Currency)
|
||||
exchangeCurrency.TotalValue = item.Available
|
||||
exchangeCurrency.Hold = item.Reserved
|
||||
exchangeCurrency.CurrencyName = currency.NewCode(accountBalance[i].Currency)
|
||||
exchangeCurrency.TotalValue = accountBalance[i].Available
|
||||
exchangeCurrency.Hold = accountBalance[i].Reserved
|
||||
currencies = append(currencies, exchangeCurrency)
|
||||
}
|
||||
|
||||
response.Accounts = append(response.Accounts, exchange.Account{
|
||||
Currencies: currencies,
|
||||
})
|
||||
response.Accounts = append(response.Accounts,
|
||||
exchange.Account{
|
||||
Currencies: currencies,
|
||||
})
|
||||
|
||||
return response, nil
|
||||
}
|
||||
@@ -368,23 +370,19 @@ func (h *HitBTC) GetExchangeHistory(p currency.Pair, assetType asset.Item) ([]ex
|
||||
}
|
||||
|
||||
// SubmitOrder submits a new order
|
||||
func (h *HitBTC) 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 (h *HitBTC) SubmitOrder(s *order.Submit) (order.SubmitResponse, error) {
|
||||
var submitOrderResponse order.SubmitResponse
|
||||
if err := s.Validate(); err != nil {
|
||||
return submitOrderResponse, err
|
||||
}
|
||||
|
||||
response, err := h.PlaceOrder(order.Pair.String(),
|
||||
order.Price,
|
||||
order.Amount,
|
||||
strings.ToLower(order.OrderType.ToString()),
|
||||
strings.ToLower(order.OrderSide.ToString()))
|
||||
response, err := h.PlaceOrder(s.Pair.String(),
|
||||
s.Price,
|
||||
s.Amount,
|
||||
strings.ToLower(s.OrderType.String()),
|
||||
strings.ToLower(s.OrderSide.String()))
|
||||
if response.OrderNumber > 0 {
|
||||
submitOrderResponse.OrderID = fmt.Sprintf("%v", response.OrderNumber)
|
||||
submitOrderResponse.OrderID = strconv.FormatInt(response.OrderNumber, 10)
|
||||
}
|
||||
if err == nil {
|
||||
submitOrderResponse.IsOrderPlaced = true
|
||||
@@ -394,27 +392,25 @@ func (h *HitBTC) SubmitOrder(order *exchange.OrderSubmission) (exchange.SubmitOr
|
||||
|
||||
// ModifyOrder will allow of changing orderbook placement and limit to
|
||||
// market conversion
|
||||
func (h *HitBTC) ModifyOrder(action *exchange.ModifyOrder) (string, error) {
|
||||
func (h *HitBTC) ModifyOrder(action *order.Modify) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// CancelOrder cancels an order by its corresponding ID number
|
||||
func (h *HitBTC) CancelOrder(order *exchange.OrderCancellation) error {
|
||||
func (h *HitBTC) CancelOrder(order *order.Cancel) error {
|
||||
orderIDInt, err := strconv.ParseInt(order.OrderID, 10, 64)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = h.CancelExistingOrder(orderIDInt)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// CancelAllOrders cancels all orders associated with a currency pair
|
||||
func (h *HitBTC) CancelAllOrders(_ *exchange.OrderCancellation) (exchange.CancelAllOrdersResponse, error) {
|
||||
cancelAllOrdersResponse := exchange.CancelAllOrdersResponse{
|
||||
OrderStatus: make(map[string]string),
|
||||
func (h *HitBTC) CancelAllOrders(_ *order.Cancel) (order.CancelAllResponse, error) {
|
||||
cancelAllOrdersResponse := order.CancelAllResponse{
|
||||
Status: make(map[string]string),
|
||||
}
|
||||
|
||||
resp, err := h.CancelAllExistingOrders()
|
||||
@@ -424,7 +420,7 @@ func (h *HitBTC) CancelAllOrders(_ *exchange.OrderCancellation) (exchange.Cancel
|
||||
|
||||
for i := range resp {
|
||||
if resp[i].Status != "canceled" {
|
||||
cancelAllOrdersResponse.OrderStatus[strconv.FormatInt(resp[i].ID, 10)] =
|
||||
cancelAllOrdersResponse.Status[strconv.FormatInt(resp[i].ID, 10)] =
|
||||
fmt.Sprintf("Could not cancel order %v. Status: %v",
|
||||
resp[i].ID,
|
||||
resp[i].Status)
|
||||
@@ -435,8 +431,8 @@ func (h *HitBTC) CancelAllOrders(_ *exchange.OrderCancellation) (exchange.Cancel
|
||||
}
|
||||
|
||||
// GetOrderInfo returns information on a current open order
|
||||
func (h *HitBTC) GetOrderInfo(orderID string) (exchange.OrderDetail, error) {
|
||||
var orderDetail exchange.OrderDetail
|
||||
func (h *HitBTC) GetOrderInfo(orderID string) (order.Detail, error) {
|
||||
var orderDetail order.Detail
|
||||
return orderDetail, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
@@ -454,7 +450,6 @@ func (h *HitBTC) GetDepositAddress(currency currency.Code, _ string) (string, er
|
||||
// submitted
|
||||
func (h *HitBTC) WithdrawCryptocurrencyFunds(withdrawRequest *exchange.CryptoWithdrawRequest) (string, error) {
|
||||
_, err := h.Withdraw(withdrawRequest.Currency.String(), withdrawRequest.Address, withdrawRequest.Amount)
|
||||
|
||||
return "", err
|
||||
}
|
||||
|
||||
@@ -485,26 +480,26 @@ func (h *HitBTC) GetFeeByType(feeBuilder *exchange.FeeBuilder) (float64, error)
|
||||
}
|
||||
|
||||
// GetActiveOrders retrieves any orders that are active/open
|
||||
func (h *HitBTC) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
if len(getOrdersRequest.Currencies) == 0 {
|
||||
func (h *HitBTC) GetActiveOrders(req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
if len(req.Currencies) == 0 {
|
||||
return nil, errors.New("currency must be supplied")
|
||||
}
|
||||
|
||||
var allOrders []OrderHistoryResponse
|
||||
for _, currency := range getOrdersRequest.Currencies {
|
||||
resp, err := h.GetOpenOrders(currency.String())
|
||||
for i := range req.Currencies {
|
||||
resp, err := h.GetOpenOrders(req.Currencies[i].String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
allOrders = append(allOrders, resp...)
|
||||
}
|
||||
|
||||
var orders []exchange.OrderDetail
|
||||
var orders []order.Detail
|
||||
for i := range allOrders {
|
||||
symbol := currency.NewPairDelimiter(allOrders[i].Symbol,
|
||||
h.GetPairFormat(asset.Spot, false).Delimiter)
|
||||
side := exchange.OrderSide(strings.ToUpper(allOrders[i].Side))
|
||||
orders = append(orders, exchange.OrderDetail{
|
||||
side := order.Side(strings.ToUpper(allOrders[i].Side))
|
||||
orders = append(orders, order.Detail{
|
||||
ID: allOrders[i].ID,
|
||||
Amount: allOrders[i].Quantity,
|
||||
Exchange: h.Name,
|
||||
@@ -515,34 +510,33 @@ func (h *HitBTC) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([
|
||||
})
|
||||
}
|
||||
|
||||
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks,
|
||||
getOrdersRequest.EndTicks)
|
||||
exchange.FilterOrdersBySide(&orders, getOrdersRequest.OrderSide)
|
||||
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 (h *HitBTC) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
if len(getOrdersRequest.Currencies) == 0 {
|
||||
func (h *HitBTC) GetOrderHistory(req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
if len(req.Currencies) == 0 {
|
||||
return nil, errors.New("currency must be supplied")
|
||||
}
|
||||
|
||||
var allOrders []OrderHistoryResponse
|
||||
for _, currency := range getOrdersRequest.Currencies {
|
||||
resp, err := h.GetOrders(currency.String())
|
||||
for i := range req.Currencies {
|
||||
resp, err := h.GetOrders(req.Currencies[i].String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
allOrders = append(allOrders, resp...)
|
||||
}
|
||||
|
||||
var orders []exchange.OrderDetail
|
||||
var orders []order.Detail
|
||||
for i := range allOrders {
|
||||
symbol := currency.NewPairDelimiter(allOrders[i].Symbol,
|
||||
h.GetPairFormat(asset.Spot, false).Delimiter)
|
||||
side := exchange.OrderSide(strings.ToUpper(allOrders[i].Side))
|
||||
orders = append(orders, exchange.OrderDetail{
|
||||
side := order.Side(strings.ToUpper(allOrders[i].Side))
|
||||
orders = append(orders, order.Detail{
|
||||
ID: allOrders[i].ID,
|
||||
Amount: allOrders[i].Quantity,
|
||||
Exchange: h.Name,
|
||||
@@ -553,8 +547,8 @@ func (h *HitBTC) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([
|
||||
})
|
||||
}
|
||||
|
||||
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks, getOrdersRequest.EndTicks)
|
||||
exchange.FilterOrdersBySide(&orders, getOrdersRequest.OrderSide)
|
||||
order.FilterOrdersByTickRange(&orders, req.StartTicks, req.EndTicks)
|
||||
order.FilterOrdersBySide(&orders, req.OrderSide)
|
||||
return orders, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,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"
|
||||
)
|
||||
@@ -456,8 +457,8 @@ func TestGetActiveOrders(t *testing.T) {
|
||||
h.SetDefaults()
|
||||
TestSetup(t)
|
||||
|
||||
var getOrdersRequest = exchange.GetOrdersRequest{
|
||||
OrderType: exchange.AnyOrderType,
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
OrderType: order.AnyType,
|
||||
Currencies: []currency.Pair{currency.NewPair(currency.BTC, currency.USDT)},
|
||||
}
|
||||
|
||||
@@ -473,8 +474,8 @@ func TestGetOrderHistory(t *testing.T) {
|
||||
h.SetDefaults()
|
||||
TestSetup(t)
|
||||
|
||||
var getOrdersRequest = exchange.GetOrdersRequest{
|
||||
OrderType: exchange.AnyOrderType,
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
OrderType: order.AnyType,
|
||||
Currencies: []currency.Pair{currency.NewPair(currency.BTC, currency.USDT)},
|
||||
}
|
||||
|
||||
@@ -509,13 +510,13 @@ func TestSubmitOrder(t *testing.T) {
|
||||
t.Fatalf("Failed to get accounts. Err: %s", err)
|
||||
}
|
||||
|
||||
var orderSubmission = &exchange.OrderSubmission{
|
||||
var orderSubmission = &order.Submit{
|
||||
Pair: currency.Pair{
|
||||
Base: currency.BTC,
|
||||
Quote: currency.USDT,
|
||||
},
|
||||
OrderSide: exchange.BuyOrderSide,
|
||||
OrderType: exchange.LimitOrderType,
|
||||
OrderSide: order.Buy,
|
||||
OrderType: order.Limit,
|
||||
Price: 1,
|
||||
Amount: 1,
|
||||
ClientID: strconv.FormatInt(accounts[0].ID, 10),
|
||||
@@ -536,7 +537,7 @@ func TestCancelExchangeOrder(t *testing.T) {
|
||||
|
||||
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
|
||||
var orderCancellation = &exchange.OrderCancellation{
|
||||
var orderCancellation = &order.Cancel{
|
||||
OrderID: "1",
|
||||
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
AccountID: "1",
|
||||
@@ -561,7 +562,7 @@ func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
}
|
||||
|
||||
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
var orderCancellation = exchange.OrderCancellation{
|
||||
var orderCancellation = order.Cancel{
|
||||
OrderID: "1",
|
||||
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
AccountID: "1",
|
||||
@@ -577,8 +578,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))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -597,7 +598,7 @@ func TestGetAccountInfo(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestModifyOrder(t *testing.T) {
|
||||
_, err := h.ModifyOrder(&exchange.ModifyOrder{})
|
||||
_, err := h.ModifyOrder(&order.Modify{})
|
||||
if err == nil {
|
||||
t.Error("ModifyOrder() Expected error")
|
||||
}
|
||||
|
||||
@@ -13,6 +13,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"
|
||||
@@ -193,7 +194,11 @@ func (h *HUOBI) Start(wg *sync.WaitGroup) {
|
||||
// Run implements the HUOBI wrapper
|
||||
func (h *HUOBI) Run() {
|
||||
if h.Verbose {
|
||||
log.Debugf(log.ExchangeSys, "%s Websocket: %s (url: %s).\n", h.GetName(), common.IsEnabled(h.Websocket.IsEnabled()), wsMarketURL)
|
||||
log.Debugf(log.ExchangeSys,
|
||||
"%s Websocket: %s (url: %s).\n",
|
||||
h.GetName(),
|
||||
common.IsEnabled(h.Websocket.IsEnabled()),
|
||||
wsMarketURL)
|
||||
h.PrintEnabledPairs()
|
||||
}
|
||||
|
||||
@@ -207,7 +212,10 @@ func (h *HUOBI) Run() {
|
||||
cfg := config.GetConfig()
|
||||
exchCfg, err := cfg.GetExchangeConfig(h.Name)
|
||||
if err != nil {
|
||||
log.Errorf(log.ExchangeSys, "%s failed to get exchange config. %s\n", h.Name, err)
|
||||
log.Errorf(log.ExchangeSys,
|
||||
"%s failed to get exchange config. %s\n",
|
||||
h.Name,
|
||||
err)
|
||||
return
|
||||
}
|
||||
exchCfg.BaseCurrencies = currency.Currencies{currency.USD}
|
||||
@@ -221,11 +229,14 @@ func (h *HUOBI) Run() {
|
||||
Delimiter: "-",
|
||||
},
|
||||
}
|
||||
log.Warn(log.ExchangeSys, "Available and enabled pairs for Huobi reset due to config upgrade, please enable the ones you would like again")
|
||||
log.Warn(log.ExchangeSys,
|
||||
"Available and enabled pairs for Huobi reset due to config upgrade, please enable the ones you would like again")
|
||||
|
||||
err := h.UpdatePairs(enabledPairs, asset.Spot, true, true)
|
||||
if err != nil {
|
||||
log.Errorf(log.ExchangeSys, "%s Failed to update enabled currencies.\n", h.GetName())
|
||||
log.Errorf(log.ExchangeSys,
|
||||
"%s Failed to update enabled currencies.\n",
|
||||
h.GetName())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -235,7 +246,10 @@ func (h *HUOBI) Run() {
|
||||
|
||||
err := h.UpdateTradablePairs(forceUpdate)
|
||||
if err != nil {
|
||||
log.Errorf(log.ExchangeSys, "%s failed to update tradable pairs. Err: %s", h.Name, err)
|
||||
log.Errorf(log.ExchangeSys,
|
||||
"%s failed to update tradable pairs. Err: %s",
|
||||
h.Name,
|
||||
err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -251,8 +265,10 @@ func (h *HUOBI) FetchTradablePairs(asset asset.Item) ([]string, error) {
|
||||
if symbols[x].State != "online" {
|
||||
continue
|
||||
}
|
||||
pairs = append(pairs, fmt.Sprintf("%v%v%v", symbols[x].BaseCurrency,
|
||||
h.GetPairFormat(asset, false).Delimiter, symbols[x].QuoteCurrency))
|
||||
pairs = append(pairs, fmt.Sprintf("%v%v%v",
|
||||
symbols[x].BaseCurrency,
|
||||
h.GetPairFormat(asset, false).Delimiter,
|
||||
symbols[x].QuoteCurrency))
|
||||
}
|
||||
|
||||
return pairs, nil
|
||||
@@ -266,7 +282,10 @@ func (h *HUOBI) UpdateTradablePairs(forceUpdate bool) error {
|
||||
return err
|
||||
}
|
||||
|
||||
return h.UpdatePairs(currency.NewPairsFromStrings(pairs), asset.Spot, false, forceUpdate)
|
||||
return h.UpdatePairs(currency.NewPairsFromStrings(pairs),
|
||||
asset.Spot,
|
||||
false,
|
||||
forceUpdate)
|
||||
}
|
||||
|
||||
// UpdateTicker updates and returns the ticker for a currency pair
|
||||
@@ -377,30 +396,28 @@ func (h *HUOBI) GetAccountInfo() (exchange.AccountInfo, error) {
|
||||
return info, err
|
||||
}
|
||||
|
||||
for _, account := range accounts {
|
||||
for i := range accounts {
|
||||
var acc exchange.Account
|
||||
|
||||
acc.ID = strconv.FormatInt(account.ID, 10)
|
||||
|
||||
acc.ID = strconv.FormatInt(accounts[i].ID, 10)
|
||||
balances, err := h.GetAccountBalance(acc.ID)
|
||||
if err != nil {
|
||||
return info, err
|
||||
}
|
||||
|
||||
var currencyDetails []exchange.AccountCurrencyInfo
|
||||
for _, balance := range balances {
|
||||
for j := range balances {
|
||||
var frozen bool
|
||||
if balance.Type == "frozen" {
|
||||
if balances[j].Type == "frozen" {
|
||||
frozen = true
|
||||
}
|
||||
|
||||
var updated bool
|
||||
for i := range currencyDetails {
|
||||
if currencyDetails[i].CurrencyName == currency.NewCode(balance.Currency) {
|
||||
if currencyDetails[i].CurrencyName == currency.NewCode(balances[j].Currency) {
|
||||
if frozen {
|
||||
currencyDetails[i].Hold = balance.Balance
|
||||
currencyDetails[i].Hold = balances[j].Balance
|
||||
} else {
|
||||
currencyDetails[i].TotalValue = balance.Balance
|
||||
currencyDetails[i].TotalValue = balances[j].Balance
|
||||
}
|
||||
updated = true
|
||||
}
|
||||
@@ -413,14 +430,14 @@ func (h *HUOBI) GetAccountInfo() (exchange.AccountInfo, error) {
|
||||
if frozen {
|
||||
currencyDetails = append(currencyDetails,
|
||||
exchange.AccountCurrencyInfo{
|
||||
CurrencyName: currency.NewCode(balance.Currency),
|
||||
Hold: balance.Balance,
|
||||
CurrencyName: currency.NewCode(balances[j].Currency),
|
||||
Hold: balances[j].Balance,
|
||||
})
|
||||
} else {
|
||||
currencyDetails = append(currencyDetails,
|
||||
exchange.AccountCurrencyInfo{
|
||||
CurrencyName: currency.NewCode(balance.Currency),
|
||||
TotalValue: balance.Balance,
|
||||
CurrencyName: currency.NewCode(balances[j].Currency),
|
||||
TotalValue: balances[j].Balance,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -445,46 +462,42 @@ func (h *HUOBI) GetExchangeHistory(p currency.Pair, assetType asset.Item) ([]exc
|
||||
}
|
||||
|
||||
// SubmitOrder submits a new order
|
||||
func (h *HUOBI) 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 (h *HUOBI) SubmitOrder(s *order.Submit) (order.SubmitResponse, error) {
|
||||
var submitOrderResponse order.SubmitResponse
|
||||
if err := s.Validate(); err != nil {
|
||||
return submitOrderResponse, err
|
||||
}
|
||||
|
||||
accountID, err := strconv.ParseInt(order.ClientID, 10, 64)
|
||||
accountID, err := strconv.ParseInt(s.ClientID, 10, 64)
|
||||
if err != nil {
|
||||
return submitOrderResponse, err
|
||||
}
|
||||
|
||||
var formattedType SpotNewOrderRequestParamsType
|
||||
var params = SpotNewOrderRequestParams{
|
||||
Amount: order.Amount,
|
||||
Amount: s.Amount,
|
||||
Source: "api",
|
||||
Symbol: strings.ToLower(order.Pair.String()),
|
||||
Symbol: s.Pair.Lower().String(),
|
||||
AccountID: int(accountID),
|
||||
}
|
||||
|
||||
switch {
|
||||
case order.OrderSide == exchange.BuyOrderSide && order.OrderType == exchange.MarketOrderType:
|
||||
case s.OrderSide == order.Buy && s.OrderType == order.Market:
|
||||
formattedType = SpotNewOrderRequestTypeBuyMarket
|
||||
case order.OrderSide == exchange.SellOrderSide && order.OrderType == exchange.MarketOrderType:
|
||||
case s.OrderSide == order.Sell && s.OrderType == order.Market:
|
||||
formattedType = SpotNewOrderRequestTypeSellMarket
|
||||
case order.OrderSide == exchange.BuyOrderSide && order.OrderType == exchange.LimitOrderType:
|
||||
case s.OrderSide == order.Buy && s.OrderType == order.Limit:
|
||||
formattedType = SpotNewOrderRequestTypeBuyLimit
|
||||
params.Price = order.Price
|
||||
case order.OrderSide == exchange.SellOrderSide && order.OrderType == exchange.LimitOrderType:
|
||||
params.Price = s.Price
|
||||
case s.OrderSide == order.Sell && s.OrderType == order.Limit:
|
||||
formattedType = SpotNewOrderRequestTypeSellLimit
|
||||
params.Price = order.Price
|
||||
params.Price = s.Price
|
||||
}
|
||||
|
||||
params.Type = formattedType
|
||||
response, err := h.SpotNewOrder(params)
|
||||
if response > 0 {
|
||||
submitOrderResponse.OrderID = fmt.Sprintf("%v", response)
|
||||
submitOrderResponse.OrderID = strconv.FormatInt(response, 10)
|
||||
}
|
||||
if err == nil {
|
||||
submitOrderResponse.IsOrderPlaced = true
|
||||
@@ -494,26 +507,24 @@ func (h *HUOBI) SubmitOrder(order *exchange.OrderSubmission) (exchange.SubmitOrd
|
||||
|
||||
// ModifyOrder will allow of changing orderbook placement and limit to
|
||||
// market conversion
|
||||
func (h *HUOBI) ModifyOrder(action *exchange.ModifyOrder) (string, error) {
|
||||
func (h *HUOBI) ModifyOrder(action *order.Modify) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// CancelOrder cancels an order by its corresponding ID number
|
||||
func (h *HUOBI) CancelOrder(order *exchange.OrderCancellation) error {
|
||||
func (h *HUOBI) CancelOrder(order *order.Cancel) error {
|
||||
orderIDInt, err := strconv.ParseInt(order.OrderID, 10, 64)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = h.CancelExistingOrder(orderIDInt)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// CancelAllOrders cancels all orders associated with a currency pair
|
||||
func (h *HUOBI) CancelAllOrders(orderCancellation *exchange.OrderCancellation) (exchange.CancelAllOrdersResponse, error) {
|
||||
var cancelAllOrdersResponse exchange.CancelAllOrdersResponse
|
||||
func (h *HUOBI) CancelAllOrders(orderCancellation *order.Cancel) (order.CancelAllResponse, error) {
|
||||
var cancelAllOrdersResponse order.CancelAllResponse
|
||||
for _, currency := range h.GetEnabledPairs(asset.Spot) {
|
||||
resp, err := h.CancelOpenOrdersBatch(orderCancellation.AccountID,
|
||||
h.FormatExchangeCurrency(currency, asset.Spot).String())
|
||||
@@ -522,7 +533,9 @@ func (h *HUOBI) CancelAllOrders(orderCancellation *exchange.OrderCancellation) (
|
||||
}
|
||||
|
||||
if resp.Data.FailedCount > 0 {
|
||||
return cancelAllOrdersResponse, fmt.Errorf("%v orders failed to cancel", resp.Data.FailedCount)
|
||||
return cancelAllOrdersResponse,
|
||||
fmt.Errorf("%v orders failed to cancel",
|
||||
resp.Data.FailedCount)
|
||||
}
|
||||
|
||||
if resp.Status == "error" {
|
||||
@@ -534,8 +547,8 @@ func (h *HUOBI) CancelAllOrders(orderCancellation *exchange.OrderCancellation) (
|
||||
}
|
||||
|
||||
// GetOrderInfo returns information on a current open order
|
||||
func (h *HUOBI) GetOrderInfo(orderID string) (exchange.OrderDetail, error) {
|
||||
var orderDetail exchange.OrderDetail
|
||||
func (h *HUOBI) GetOrderInfo(orderID string) (order.Detail, error) {
|
||||
var orderDetail order.Detail
|
||||
return orderDetail, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
@@ -548,7 +561,7 @@ func (h *HUOBI) GetDepositAddress(cryptocurrency currency.Code, accountID string
|
||||
// submitted
|
||||
func (h *HUOBI) WithdrawCryptocurrencyFunds(withdrawRequest *exchange.CryptoWithdrawRequest) (string, error) {
|
||||
resp, err := h.Withdraw(withdrawRequest.Currency, withdrawRequest.Address, withdrawRequest.AddressTag, withdrawRequest.Amount, withdrawRequest.FeeAmount)
|
||||
return fmt.Sprintf("%v", resp), err
|
||||
return strconv.FormatInt(resp, 10), err
|
||||
}
|
||||
|
||||
// WithdrawFiatFunds returns a withdrawal ID when a
|
||||
@@ -578,37 +591,39 @@ func (h *HUOBI) GetFeeByType(feeBuilder *exchange.FeeBuilder) (float64, error) {
|
||||
}
|
||||
|
||||
// GetActiveOrders retrieves any orders that are active/open
|
||||
func (h *HUOBI) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
if len(getOrdersRequest.Currencies) == 0 {
|
||||
func (h *HUOBI) GetActiveOrders(req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
if len(req.Currencies) == 0 {
|
||||
return nil, errors.New("currency must be supplied")
|
||||
}
|
||||
|
||||
side := ""
|
||||
if getOrdersRequest.OrderSide == exchange.AnyOrderSide || getOrdersRequest.OrderSide == "" {
|
||||
if req.OrderSide == order.AnySide || req.OrderSide == "" {
|
||||
side = ""
|
||||
} else if getOrdersRequest.OrderSide == exchange.SellOrderSide {
|
||||
side = strings.ToLower(string(getOrdersRequest.OrderSide))
|
||||
} else if req.OrderSide == order.Sell {
|
||||
side = strings.ToLower(string(req.OrderSide))
|
||||
}
|
||||
|
||||
var orders []exchange.OrderDetail
|
||||
var orders []order.Detail
|
||||
|
||||
for _, c := range getOrdersRequest.Currencies {
|
||||
for i := range req.Currencies {
|
||||
resp, err := h.GetOpenOrders(h.API.Credentials.ClientID,
|
||||
c.Lower().String(), side, 500)
|
||||
req.Currencies[i].Lower().String(),
|
||||
side,
|
||||
500)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for i := range resp {
|
||||
orderDetail := exchange.OrderDetail{
|
||||
ID: fmt.Sprintf("%v", resp[i].ID),
|
||||
orderDetail := order.Detail{
|
||||
ID: strconv.FormatInt(int64(resp[i].ID), 10),
|
||||
Price: resp[i].Price,
|
||||
Amount: resp[i].Amount,
|
||||
CurrencyPair: c,
|
||||
CurrencyPair: req.Currencies[i],
|
||||
Exchange: h.Name,
|
||||
ExecutedAmount: resp[i].FilledAmount,
|
||||
OrderDate: time.Unix(0, resp[i].CreatedAt*int64(time.Millisecond)),
|
||||
Status: resp[i].State,
|
||||
Status: order.Status(resp[i].State),
|
||||
AccountID: strconv.FormatFloat(resp[i].AccountID, 'f', -1, 64),
|
||||
Fee: resp[i].FilledFees,
|
||||
}
|
||||
@@ -619,22 +634,21 @@ func (h *HUOBI) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([]
|
||||
}
|
||||
}
|
||||
|
||||
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks,
|
||||
getOrdersRequest.EndTicks)
|
||||
order.FilterOrdersByTickRange(&orders, req.StartTicks, req.EndTicks)
|
||||
return orders, nil
|
||||
}
|
||||
|
||||
// GetOrderHistory retrieves account order information
|
||||
// Can Limit response to specific order status
|
||||
func (h *HUOBI) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
if len(getOrdersRequest.Currencies) == 0 {
|
||||
func (h *HUOBI) GetOrderHistory(req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
if len(req.Currencies) == 0 {
|
||||
return nil, errors.New("currency must be supplied")
|
||||
}
|
||||
|
||||
states := "partial-canceled,filled,canceled"
|
||||
var orders []exchange.OrderDetail
|
||||
for _, c := range getOrdersRequest.Currencies {
|
||||
resp, err := h.GetOrders(c.Lower().String(),
|
||||
var orders []order.Detail
|
||||
for i := range req.Currencies {
|
||||
resp, err := h.GetOrders(req.Currencies[i].Lower().String(),
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
@@ -647,15 +661,15 @@ func (h *HUOBI) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([]
|
||||
}
|
||||
|
||||
for i := range resp {
|
||||
orderDetail := exchange.OrderDetail{
|
||||
ID: fmt.Sprintf("%v", resp[i].ID),
|
||||
orderDetail := order.Detail{
|
||||
ID: strconv.FormatInt(int64(resp[i].ID), 10),
|
||||
Price: resp[i].Price,
|
||||
Amount: resp[i].Amount,
|
||||
CurrencyPair: c,
|
||||
CurrencyPair: req.Currencies[i],
|
||||
Exchange: h.Name,
|
||||
ExecutedAmount: resp[i].FilledAmount,
|
||||
OrderDate: time.Unix(0, resp[i].CreatedAt*int64(time.Millisecond)),
|
||||
Status: resp[i].State,
|
||||
Status: order.Status(resp[i].State),
|
||||
AccountID: strconv.FormatFloat(resp[i].AccountID, 'f', -1, 64),
|
||||
Fee: resp[i].FilledFees,
|
||||
}
|
||||
@@ -666,25 +680,24 @@ func (h *HUOBI) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([]
|
||||
}
|
||||
}
|
||||
|
||||
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks,
|
||||
getOrdersRequest.EndTicks)
|
||||
order.FilterOrdersByTickRange(&orders, req.StartTicks, req.EndTicks)
|
||||
return orders, nil
|
||||
}
|
||||
|
||||
func setOrderSideAndType(requestType string, orderDetail *exchange.OrderDetail) {
|
||||
func setOrderSideAndType(requestType string, orderDetail *order.Detail) {
|
||||
switch SpotNewOrderRequestParamsType(requestType) {
|
||||
case SpotNewOrderRequestTypeBuyMarket:
|
||||
orderDetail.OrderSide = exchange.BuyOrderSide
|
||||
orderDetail.OrderType = exchange.MarketOrderType
|
||||
orderDetail.OrderSide = order.Buy
|
||||
orderDetail.OrderType = order.Market
|
||||
case SpotNewOrderRequestTypeSellMarket:
|
||||
orderDetail.OrderSide = exchange.SellOrderSide
|
||||
orderDetail.OrderType = exchange.MarketOrderType
|
||||
orderDetail.OrderSide = order.Sell
|
||||
orderDetail.OrderType = order.Market
|
||||
case SpotNewOrderRequestTypeBuyLimit:
|
||||
orderDetail.OrderSide = exchange.BuyOrderSide
|
||||
orderDetail.OrderType = exchange.LimitOrderType
|
||||
orderDetail.OrderSide = order.Buy
|
||||
orderDetail.OrderType = order.Limit
|
||||
case SpotNewOrderRequestTypeSellLimit:
|
||||
orderDetail.OrderSide = exchange.SellOrderSide
|
||||
orderDetail.OrderType = exchange.LimitOrderType
|
||||
orderDetail.OrderSide = order.Sell
|
||||
orderDetail.OrderType = order.Limit
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/config"
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
"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/ticker"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
@@ -41,14 +42,14 @@ type IBotExchange interface {
|
||||
FormatWithdrawPermissions() string
|
||||
SupportsWithdrawPermissions(permissions uint32) bool
|
||||
GetFundingHistory() ([]FundHistory, error)
|
||||
SubmitOrder(order *OrderSubmission) (SubmitOrderResponse, error)
|
||||
ModifyOrder(action *ModifyOrder) (string, error)
|
||||
CancelOrder(order *OrderCancellation) error
|
||||
CancelAllOrders(orders *OrderCancellation) (CancelAllOrdersResponse, error)
|
||||
GetOrderInfo(orderID string) (OrderDetail, error)
|
||||
SubmitOrder(s *order.Submit) (order.SubmitResponse, error)
|
||||
ModifyOrder(action *order.Modify) (string, error)
|
||||
CancelOrder(order *order.Cancel) error
|
||||
CancelAllOrders(orders *order.Cancel) (order.CancelAllResponse, error)
|
||||
GetOrderInfo(orderID string) (order.Detail, error)
|
||||
GetDepositAddress(cryptocurrency currency.Code, accountID string) (string, error)
|
||||
GetOrderHistory(getOrdersRequest *GetOrdersRequest) ([]OrderDetail, error)
|
||||
GetActiveOrders(getOrdersRequest *GetOrdersRequest) ([]OrderDetail, error)
|
||||
GetOrderHistory(getOrdersRequest *order.GetOrdersRequest) ([]order.Detail, error)
|
||||
GetActiveOrders(getOrdersRequest *order.GetOrdersRequest) ([]order.Detail, error)
|
||||
WithdrawCryptocurrencyFunds(withdrawRequest *CryptoWithdrawRequest) (string, error)
|
||||
WithdrawFiatFunds(withdrawRequest *FiatWithdrawRequest) (string, error)
|
||||
WithdrawFiatFundsToInternationalBank(withdrawRequest *FiatWithdrawRequest) (string, error)
|
||||
|
||||
@@ -8,6 +8,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"
|
||||
)
|
||||
|
||||
var i ItBit
|
||||
@@ -112,8 +113,8 @@ func TestGetFundingHistory(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPlaceOrder(t *testing.T) {
|
||||
_, err := i.PlaceOrder("1337", exchange.BuyOrderSide.ToLower().ToString(),
|
||||
exchange.LimitOrderType.ToLower().ToString(), "USD", 1, 0.2, "banjo",
|
||||
_, err := i.PlaceOrder("1337", order.Buy.Lower(),
|
||||
order.Limit.Lower(), "USD", 1, 0.2, "banjo",
|
||||
"sauce")
|
||||
if err == nil {
|
||||
t.Error("PlaceOrder() Expected error")
|
||||
@@ -268,8 +269,8 @@ func TestGetActiveOrders(t *testing.T) {
|
||||
i.SetDefaults()
|
||||
TestSetup(t)
|
||||
|
||||
var getOrdersRequest = exchange.GetOrdersRequest{
|
||||
OrderType: exchange.AnyOrderType,
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
OrderType: order.AnyType,
|
||||
}
|
||||
|
||||
_, err := i.GetActiveOrders(&getOrdersRequest)
|
||||
@@ -284,8 +285,8 @@ func TestGetOrderHistory(t *testing.T) {
|
||||
i.SetDefaults()
|
||||
TestSetup(t)
|
||||
|
||||
var getOrdersRequest = exchange.GetOrdersRequest{
|
||||
OrderType: exchange.AnyOrderType,
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
OrderType: order.AnyType,
|
||||
}
|
||||
|
||||
_, err := i.GetOrderHistory(&getOrdersRequest)
|
||||
@@ -309,13 +310,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.BTC,
|
||||
Quote: currency.USD,
|
||||
},
|
||||
OrderSide: exchange.BuyOrderSide,
|
||||
OrderType: exchange.LimitOrderType,
|
||||
OrderSide: order.Buy,
|
||||
OrderType: order.Limit,
|
||||
Price: 1,
|
||||
Amount: 1,
|
||||
ClientID: "meowOrder",
|
||||
@@ -338,7 +339,7 @@ func TestCancelExchangeOrder(t *testing.T) {
|
||||
|
||||
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
|
||||
var orderCancellation = &exchange.OrderCancellation{
|
||||
var orderCancellation = &order.Cancel{
|
||||
OrderID: "1",
|
||||
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
AccountID: "1",
|
||||
@@ -365,7 +366,7 @@ func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
|
||||
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
|
||||
var orderCancellation = &exchange.OrderCancellation{
|
||||
var orderCancellation = &order.Cancel{
|
||||
OrderID: "1",
|
||||
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
AccountID: "1",
|
||||
@@ -381,8 +382,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))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -396,7 +397,7 @@ func TestGetAccountInfo(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestModifyOrder(t *testing.T) {
|
||||
_, err := i.ModifyOrder(&exchange.ModifyOrder{})
|
||||
_, err := i.ModifyOrder(&order.Modify{})
|
||||
if err == nil {
|
||||
t.Error("ModifyOrder() Expected error")
|
||||
}
|
||||
|
||||
@@ -13,6 +13,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"
|
||||
@@ -202,7 +203,11 @@ func (i *ItBit) UpdateOrderbook(p currency.Pair, assetType asset.Item) (orderboo
|
||||
if err != nil {
|
||||
return orderBook, err
|
||||
}
|
||||
orderBook.Bids = append(orderBook.Bids, orderbook.Item{Amount: amount, Price: price})
|
||||
orderBook.Bids = append(orderBook.Bids,
|
||||
orderbook.Item{
|
||||
Amount: amount,
|
||||
Price: price,
|
||||
})
|
||||
}
|
||||
|
||||
for x := range orderbookNew.Asks {
|
||||
@@ -216,7 +221,11 @@ func (i *ItBit) UpdateOrderbook(p currency.Pair, assetType asset.Item) (orderboo
|
||||
if err != nil {
|
||||
return orderBook, err
|
||||
}
|
||||
orderBook.Asks = append(orderBook.Asks, orderbook.Item{Amount: amount, Price: price})
|
||||
orderBook.Asks = append(orderBook.Asks,
|
||||
orderbook.Item{
|
||||
Amount: amount,
|
||||
Price: price,
|
||||
})
|
||||
}
|
||||
|
||||
orderBook.Pair = p
|
||||
@@ -248,8 +257,8 @@ func (i *ItBit) GetAccountInfo() (exchange.AccountInfo, error) {
|
||||
|
||||
var amounts = make(map[string]*balance)
|
||||
|
||||
for _, wallet := range wallets {
|
||||
for _, cb := range wallet.Balances {
|
||||
for x := range wallets {
|
||||
for _, cb := range wallets[x].Balances {
|
||||
if _, ok := amounts[cb.Currency]; !ok {
|
||||
amounts[cb.Currency] = &balance{}
|
||||
}
|
||||
@@ -260,12 +269,11 @@ func (i *ItBit) GetAccountInfo() (exchange.AccountInfo, error) {
|
||||
}
|
||||
|
||||
var fullBalance []exchange.AccountCurrencyInfo
|
||||
|
||||
for key, data := range amounts {
|
||||
for key := range amounts {
|
||||
fullBalance = append(fullBalance, exchange.AccountCurrencyInfo{
|
||||
CurrencyName: currency.NewCode(key),
|
||||
TotalValue: data.TotalValue,
|
||||
Hold: data.Hold,
|
||||
TotalValue: amounts[key].TotalValue,
|
||||
Hold: amounts[key].Hold,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -289,13 +297,9 @@ func (i *ItBit) GetExchangeHistory(p currency.Pair, assetType asset.Item) ([]exc
|
||||
}
|
||||
|
||||
// SubmitOrder submits a new order
|
||||
func (i *ItBit) 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 (i *ItBit) SubmitOrder(s *order.Submit) (order.SubmitResponse, error) {
|
||||
var submitOrderResponse order.SubmitResponse
|
||||
if err := s.Validate(); err != nil {
|
||||
return submitOrderResponse, err
|
||||
}
|
||||
|
||||
@@ -306,11 +310,11 @@ func (i *ItBit) SubmitOrder(order *exchange.OrderSubmission) (exchange.SubmitOrd
|
||||
}
|
||||
|
||||
// Determine what wallet ID to use if there is any actual available currency to make the trade!
|
||||
for _, i := range wallets {
|
||||
for j := range i.Balances {
|
||||
if i.Balances[j].Currency == order.Pair.Base.String() &&
|
||||
i.Balances[j].AvailableBalance >= order.Amount {
|
||||
wallet = i.ID
|
||||
for i := range wallets {
|
||||
for j := range wallets[i].Balances {
|
||||
if wallets[i].Balances[j].Currency == s.Pair.Base.String() &&
|
||||
wallets[i].Balances[j].AvailableBalance >= s.Amount {
|
||||
wallet = wallets[i].ID
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -318,17 +322,17 @@ func (i *ItBit) SubmitOrder(order *exchange.OrderSubmission) (exchange.SubmitOrd
|
||||
if wallet == "" {
|
||||
return submitOrderResponse,
|
||||
fmt.Errorf("no wallet found with currency: %s with amount >= %v",
|
||||
order.Pair.Base,
|
||||
order.Amount)
|
||||
s.Pair.Base,
|
||||
s.Amount)
|
||||
}
|
||||
|
||||
response, err := i.PlaceOrder(wallet,
|
||||
order.OrderSide.ToString(),
|
||||
order.OrderType.ToString(),
|
||||
order.Pair.Base.String(),
|
||||
order.Amount,
|
||||
order.Price,
|
||||
order.Pair.String(),
|
||||
s.OrderSide.String(),
|
||||
s.OrderType.String(),
|
||||
s.Pair.Base.String(),
|
||||
s.Amount,
|
||||
s.Price,
|
||||
s.Pair.String(),
|
||||
"")
|
||||
if response.ID != "" {
|
||||
submitOrderResponse.OrderID = response.ID
|
||||
@@ -342,19 +346,19 @@ func (i *ItBit) SubmitOrder(order *exchange.OrderSubmission) (exchange.SubmitOrd
|
||||
|
||||
// ModifyOrder will allow of changing orderbook placement and limit to
|
||||
// market conversion
|
||||
func (i *ItBit) ModifyOrder(action *exchange.ModifyOrder) (string, error) {
|
||||
func (i *ItBit) ModifyOrder(action *order.Modify) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// CancelOrder cancels an order by its corresponding ID number
|
||||
func (i *ItBit) CancelOrder(order *exchange.OrderCancellation) error {
|
||||
func (i *ItBit) CancelOrder(order *order.Cancel) error {
|
||||
return i.CancelExistingOrder(order.WalletAddress, order.OrderID)
|
||||
}
|
||||
|
||||
// CancelAllOrders cancels all orders associated with a currency pair
|
||||
func (i *ItBit) CancelAllOrders(orderCancellation *exchange.OrderCancellation) (exchange.CancelAllOrdersResponse, error) {
|
||||
cancelAllOrdersResponse := exchange.CancelAllOrdersResponse{
|
||||
OrderStatus: make(map[string]string),
|
||||
func (i *ItBit) CancelAllOrders(orderCancellation *order.Cancel) (order.CancelAllResponse, error) {
|
||||
cancelAllOrdersResponse := order.CancelAllResponse{
|
||||
Status: make(map[string]string),
|
||||
}
|
||||
openOrders, err := i.GetOrders(orderCancellation.WalletAddress, "", "open", 0, 0)
|
||||
if err != nil {
|
||||
@@ -364,7 +368,7 @@ func (i *ItBit) CancelAllOrders(orderCancellation *exchange.OrderCancellation) (
|
||||
for j := range openOrders {
|
||||
err = i.CancelExistingOrder(orderCancellation.WalletAddress, openOrders[j].ID)
|
||||
if err != nil {
|
||||
cancelAllOrdersResponse.OrderStatus[openOrders[j].ID] = err.Error()
|
||||
cancelAllOrdersResponse.Status[openOrders[j].ID] = err.Error()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -372,8 +376,8 @@ func (i *ItBit) CancelAllOrders(orderCancellation *exchange.OrderCancellation) (
|
||||
}
|
||||
|
||||
// GetOrderInfo returns information on a current open order
|
||||
func (i *ItBit) GetOrderInfo(orderID string) (exchange.OrderDetail, error) {
|
||||
var orderDetail exchange.OrderDetail
|
||||
func (i *ItBit) GetOrderInfo(orderID string) (order.Detail, error) {
|
||||
var orderDetail order.Detail
|
||||
return orderDetail, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
@@ -418,33 +422,37 @@ func (i *ItBit) GetFeeByType(feeBuilder *exchange.FeeBuilder) (float64, error) {
|
||||
}
|
||||
|
||||
// GetActiveOrders retrieves any orders that are active/open
|
||||
func (i *ItBit) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
func (i *ItBit) GetActiveOrders(req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
wallets, err := i.GetWallets(url.Values{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var allOrders []Order
|
||||
for _, wallet := range wallets {
|
||||
resp, err := i.GetOrders(wallet.ID, "", "open", 0, 0)
|
||||
for x := range wallets {
|
||||
resp, err := i.GetOrders(wallets[x].ID, "", "open", 0, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
allOrders = append(allOrders, resp...)
|
||||
}
|
||||
|
||||
var orders []exchange.OrderDetail
|
||||
var orders []order.Detail
|
||||
for j := range allOrders {
|
||||
symbol := currency.NewPairDelimiter(allOrders[j].Instrument,
|
||||
i.GetPairFormat(asset.Spot, false).Delimiter)
|
||||
side := exchange.OrderSide(strings.ToUpper(allOrders[j].Side))
|
||||
side := order.Side(strings.ToUpper(allOrders[j].Side))
|
||||
orderDate, err := time.Parse(time.RFC3339, allOrders[j].CreatedTime)
|
||||
if err != nil {
|
||||
log.Warnf(log.ExchangeSys, "Exchange %v Func %v Order %v Could not parse date to unix with value of %v",
|
||||
i.Name, "GetActiveOrders", allOrders[j].ID, allOrders[j].CreatedTime)
|
||||
log.Warnf(log.ExchangeSys,
|
||||
"Exchange %v Func %v Order %v Could not parse date to unix with value of %v",
|
||||
i.Name,
|
||||
"GetActiveOrders",
|
||||
allOrders[j].ID,
|
||||
allOrders[j].CreatedTime)
|
||||
}
|
||||
|
||||
orders = append(orders, exchange.OrderDetail{
|
||||
orders = append(orders, order.Detail{
|
||||
ID: allOrders[j].ID,
|
||||
OrderSide: side,
|
||||
Amount: allOrders[j].Amount,
|
||||
@@ -456,31 +464,30 @@ func (i *ItBit) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([]
|
||||
})
|
||||
}
|
||||
|
||||
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks,
|
||||
getOrdersRequest.EndTicks)
|
||||
exchange.FilterOrdersBySide(&orders, getOrdersRequest.OrderSide)
|
||||
exchange.FilterOrdersByCurrencies(&orders, getOrdersRequest.Currencies)
|
||||
order.FilterOrdersByTickRange(&orders, req.StartTicks, req.EndTicks)
|
||||
order.FilterOrdersBySide(&orders, req.OrderSide)
|
||||
order.FilterOrdersByCurrencies(&orders, req.Currencies)
|
||||
return orders, nil
|
||||
}
|
||||
|
||||
// GetOrderHistory retrieves account order information
|
||||
// Can Limit response to specific order status
|
||||
func (i *ItBit) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
func (i *ItBit) GetOrderHistory(req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
wallets, err := i.GetWallets(url.Values{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var allOrders []Order
|
||||
for _, wallet := range wallets {
|
||||
resp, err := i.GetOrders(wallet.ID, "", "", 0, 0)
|
||||
for x := range wallets {
|
||||
resp, err := i.GetOrders(wallets[x].ID, "", "", 0, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
allOrders = append(allOrders, resp...)
|
||||
}
|
||||
|
||||
var orders []exchange.OrderDetail
|
||||
var orders []order.Detail
|
||||
for j := range allOrders {
|
||||
if allOrders[j].Type == "open" {
|
||||
continue
|
||||
@@ -488,14 +495,18 @@ func (i *ItBit) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([]
|
||||
|
||||
symbol := currency.NewPairDelimiter(allOrders[j].Instrument,
|
||||
i.GetPairFormat(asset.Spot, false).Delimiter)
|
||||
side := exchange.OrderSide(strings.ToUpper(allOrders[j].Side))
|
||||
side := order.Side(strings.ToUpper(allOrders[j].Side))
|
||||
orderDate, err := time.Parse(time.RFC3339, allOrders[j].CreatedTime)
|
||||
if err != nil {
|
||||
log.Warnf(log.ExchangeSys, "Exchange %v Func %v Order %v Could not parse date to unix with value of %v",
|
||||
i.Name, "GetActiveOrders", allOrders[j].ID, allOrders[j].CreatedTime)
|
||||
log.Warnf(log.ExchangeSys,
|
||||
"Exchange %v Func %v Order %v Could not parse date to unix with value of %v",
|
||||
i.Name,
|
||||
"GetActiveOrders",
|
||||
allOrders[j].ID,
|
||||
allOrders[j].CreatedTime)
|
||||
}
|
||||
|
||||
orders = append(orders, exchange.OrderDetail{
|
||||
orders = append(orders, order.Detail{
|
||||
ID: allOrders[j].ID,
|
||||
OrderSide: side,
|
||||
Amount: allOrders[j].Amount,
|
||||
@@ -507,10 +518,9 @@ func (i *ItBit) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([]
|
||||
})
|
||||
}
|
||||
|
||||
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks,
|
||||
getOrdersRequest.EndTicks)
|
||||
exchange.FilterOrdersBySide(&orders, getOrdersRequest.OrderSide)
|
||||
exchange.FilterOrdersByCurrencies(&orders, getOrdersRequest.Currencies)
|
||||
order.FilterOrdersByTickRange(&orders, req.StartTicks, req.EndTicks)
|
||||
order.FilterOrdersBySide(&orders, req.OrderSide)
|
||||
order.FilterOrdersByCurrencies(&orders, req.Currencies)
|
||||
return orders, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/common/crypto"
|
||||
"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/websocket/wshandler"
|
||||
log "github.com/thrasher-corp/gocryptotrader/logger"
|
||||
)
|
||||
@@ -154,7 +155,7 @@ func (k *Kraken) GetTicker(symbol string) (Ticker, error) {
|
||||
// GetTickers supports fetching multiple tickers from Kraken
|
||||
// pairList must be in the format pairs separated by commas
|
||||
// ("LTCUSD,ETCUSD")
|
||||
func (k *Kraken) GetTickers(pairList string) (Tickers, error) {
|
||||
func (k *Kraken) GetTickers(pairList string) (map[string]Ticker, error) {
|
||||
values := url.Values{}
|
||||
values.Set("pair", pairList)
|
||||
|
||||
@@ -175,7 +176,7 @@ func (k *Kraken) GetTickers(pairList string) (Tickers, error) {
|
||||
return nil, fmt.Errorf("%s error: %s", k.Name, resp.Error)
|
||||
}
|
||||
|
||||
tickers := make(Tickers)
|
||||
tickers := make(map[string]Ticker)
|
||||
|
||||
for i := range resp.Data {
|
||||
tick := Ticker{}
|
||||
@@ -763,7 +764,7 @@ func (k *Kraken) AddOrder(symbol, side, orderType string, volume, price, price2,
|
||||
"volume": {strconv.FormatFloat(volume, 'f', -1, 64)},
|
||||
}
|
||||
|
||||
if orderType == exchange.LimitOrderType.ToLower().ToString() || price > 0 {
|
||||
if orderType == order.Limit.Lower() || price > 0 {
|
||||
params.Set("price", strconv.FormatFloat(price, 'f', -1, 64))
|
||||
}
|
||||
|
||||
|
||||
@@ -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"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/sharedtestvalues"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
)
|
||||
@@ -244,7 +245,7 @@ func TestAddOrder(t *testing.T) {
|
||||
t.Parallel()
|
||||
args := AddOrderOptions{OrderFlags: "fcib"}
|
||||
_, err := k.AddOrder("XXBTZUSD",
|
||||
exchange.SellOrderSide.ToLower().ToString(), exchange.LimitOrderType.ToLower().ToString(),
|
||||
order.Sell.Lower(), order.Limit.Lower(),
|
||||
0.00000001, 0, 0, 0, &args)
|
||||
if err == nil {
|
||||
t.Error("AddOrder() Expected error")
|
||||
@@ -387,8 +388,8 @@ func TestGetActiveOrders(t *testing.T) {
|
||||
k.SetDefaults()
|
||||
TestSetup(t)
|
||||
|
||||
var getOrdersRequest = exchange.GetOrdersRequest{
|
||||
OrderType: exchange.AnyOrderType,
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
OrderType: order.AnyType,
|
||||
}
|
||||
|
||||
_, err := k.GetActiveOrders(&getOrdersRequest)
|
||||
@@ -404,8 +405,8 @@ func TestGetOrderHistory(t *testing.T) {
|
||||
k.SetDefaults()
|
||||
TestSetup(t)
|
||||
|
||||
var getOrdersRequest = exchange.GetOrdersRequest{
|
||||
OrderType: exchange.AnyOrderType,
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
OrderType: order.AnyType,
|
||||
}
|
||||
|
||||
_, err := k.GetOrderHistory(&getOrdersRequest)
|
||||
@@ -431,13 +432,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",
|
||||
@@ -461,7 +462,7 @@ func TestCancelExchangeOrder(t *testing.T) {
|
||||
|
||||
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
|
||||
var orderCancellation = &exchange.OrderCancellation{
|
||||
var orderCancellation = &order.Cancel{
|
||||
OrderID: "1",
|
||||
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
AccountID: "1",
|
||||
@@ -488,7 +489,7 @@ func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
|
||||
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
|
||||
var orderCancellation = &exchange.OrderCancellation{
|
||||
var orderCancellation = &order.Cancel{
|
||||
OrderID: "1",
|
||||
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
AccountID: "1",
|
||||
@@ -504,8 +505,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))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -526,7 +527,7 @@ func TestGetAccountInfo(t *testing.T) {
|
||||
|
||||
// TestModifyOrder wrapper test
|
||||
func TestModifyOrder(t *testing.T) {
|
||||
_, err := k.ModifyOrder(&exchange.ModifyOrder{})
|
||||
_, err := k.ModifyOrder(&order.Modify{})
|
||||
if err == nil {
|
||||
t.Error("ModifyOrder() Expected error")
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package kraken
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -12,6 +13,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"
|
||||
@@ -203,7 +205,10 @@ func (k *Kraken) Run() {
|
||||
|
||||
err := k.UpdatePairs(enabledPairs, asset.Spot, true, true)
|
||||
if err != nil {
|
||||
log.Errorf(log.ExchangeSys, "%s failed to update currencies. Err: %s\n", k.Name, err)
|
||||
log.Errorf(log.ExchangeSys,
|
||||
"%s failed to update currencies. Err: %s\n",
|
||||
k.Name,
|
||||
err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -213,7 +218,10 @@ func (k *Kraken) Run() {
|
||||
|
||||
err := k.UpdateTradablePairs(forceUpdate)
|
||||
if err != nil {
|
||||
log.Errorf(log.ExchangeSys, "%s failed to update tradable pairs. Err: %s", k.Name, err)
|
||||
log.Errorf(log.ExchangeSys,
|
||||
"%s failed to update tradable pairs. Err: %s",
|
||||
k.Name,
|
||||
err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -238,7 +246,10 @@ func (k *Kraken) FetchTradablePairs(asset asset.Item) ([]string, error) {
|
||||
if v.Quote[0] == 'Z' || v.Quote[0] == 'X' {
|
||||
v.Quote = v.Quote[1:]
|
||||
}
|
||||
products = append(products, fmt.Sprintf("%v%v%v", v.Base, k.GetPairFormat(asset, false).Delimiter, v.Quote))
|
||||
products = append(products, fmt.Sprintf("%v%v%v",
|
||||
v.Base,
|
||||
k.GetPairFormat(asset, false).Delimiter,
|
||||
v.Quote))
|
||||
}
|
||||
return products, nil
|
||||
}
|
||||
@@ -268,12 +279,11 @@ func (k *Kraken) UpdateTicker(p currency.Pair, assetType asset.Item) (ticker.Pri
|
||||
}
|
||||
|
||||
for i := range pairs {
|
||||
for curr, v := range tickers {
|
||||
for c, t := range tickers {
|
||||
pairFmt := k.FormatExchangeCurrency(pairs[i], assetType).String()
|
||||
if !strings.EqualFold(pairFmt, curr) {
|
||||
var altCurrency string
|
||||
var ok bool
|
||||
if altCurrency, ok = assetPairMap[curr]; !ok {
|
||||
if !strings.EqualFold(pairFmt, c) {
|
||||
altCurrency, ok := assetPairMap[c]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
if !strings.EqualFold(pairFmt, altCurrency) {
|
||||
@@ -282,13 +292,13 @@ func (k *Kraken) UpdateTicker(p currency.Pair, assetType asset.Item) (ticker.Pri
|
||||
}
|
||||
|
||||
tickerPrice = ticker.Price{
|
||||
Last: v.Last,
|
||||
High: v.High,
|
||||
Low: v.Low,
|
||||
Bid: v.Bid,
|
||||
Ask: v.Ask,
|
||||
Volume: v.Volume,
|
||||
Open: v.Open,
|
||||
Last: t.Last,
|
||||
High: t.High,
|
||||
Low: t.Low,
|
||||
Bid: t.Bid,
|
||||
Ask: t.Ask,
|
||||
Volume: t.Volume,
|
||||
Open: t.Open,
|
||||
Pair: pairs[i],
|
||||
}
|
||||
err = ticker.ProcessTicker(k.Name, &tickerPrice, assetType)
|
||||
@@ -359,10 +369,10 @@ func (k *Kraken) GetAccountInfo() (exchange.AccountInfo, error) {
|
||||
}
|
||||
|
||||
var balances []exchange.AccountCurrencyInfo
|
||||
for key, data := range bal {
|
||||
for key := range bal {
|
||||
balances = append(balances, exchange.AccountCurrencyInfo{
|
||||
CurrencyName: currency.NewCode(key),
|
||||
TotalValue: data,
|
||||
TotalValue: bal[key],
|
||||
})
|
||||
}
|
||||
|
||||
@@ -386,25 +396,20 @@ func (k *Kraken) GetExchangeHistory(p currency.Pair, assetType asset.Item) ([]ex
|
||||
}
|
||||
|
||||
// SubmitOrder submits a new order
|
||||
func (k *Kraken) 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 (k *Kraken) SubmitOrder(s *order.Submit) (order.SubmitResponse, error) {
|
||||
var submitOrderResponse order.SubmitResponse
|
||||
if err := s.Validate(); err != nil {
|
||||
return submitOrderResponse, err
|
||||
}
|
||||
|
||||
var args = AddOrderOptions{}
|
||||
response, err := k.AddOrder(order.Pair.String(),
|
||||
order.OrderSide.ToString(),
|
||||
order.OrderType.ToString(),
|
||||
order.Amount,
|
||||
order.Price,
|
||||
response, err := k.AddOrder(s.Pair.String(),
|
||||
s.OrderSide.String(),
|
||||
s.OrderType.String(),
|
||||
s.Amount,
|
||||
s.Price,
|
||||
0,
|
||||
0,
|
||||
&args)
|
||||
&AddOrderOptions{})
|
||||
if len(response.TransactionIds) > 0 {
|
||||
submitOrderResponse.OrderID = strings.Join(response.TransactionIds, ", ")
|
||||
}
|
||||
@@ -416,21 +421,21 @@ func (k *Kraken) SubmitOrder(order *exchange.OrderSubmission) (exchange.SubmitOr
|
||||
|
||||
// ModifyOrder will allow of changing orderbook placement and limit to
|
||||
// market conversion
|
||||
func (k *Kraken) ModifyOrder(action *exchange.ModifyOrder) (string, error) {
|
||||
func (k *Kraken) ModifyOrder(action *order.Modify) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// CancelOrder cancels an order by its corresponding ID number
|
||||
func (k *Kraken) CancelOrder(order *exchange.OrderCancellation) error {
|
||||
func (k *Kraken) CancelOrder(order *order.Cancel) error {
|
||||
_, err := k.CancelExistingOrder(order.OrderID)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// CancelAllOrders cancels all orders associated with a currency pair
|
||||
func (k *Kraken) CancelAllOrders(_ *exchange.OrderCancellation) (exchange.CancelAllOrdersResponse, error) {
|
||||
cancelAllOrdersResponse := exchange.CancelAllOrdersResponse{
|
||||
OrderStatus: make(map[string]string),
|
||||
func (k *Kraken) CancelAllOrders(_ *order.Cancel) (order.CancelAllResponse, error) {
|
||||
cancelAllOrdersResponse := order.CancelAllResponse{
|
||||
Status: make(map[string]string),
|
||||
}
|
||||
var emptyOrderOptions OrderInfoOptions
|
||||
openOrders, err := k.GetOpenOrders(emptyOrderOptions)
|
||||
@@ -441,7 +446,7 @@ func (k *Kraken) CancelAllOrders(_ *exchange.OrderCancellation) (exchange.Cancel
|
||||
for orderID := range openOrders.Open {
|
||||
_, err = k.CancelExistingOrder(orderID)
|
||||
if err != nil {
|
||||
cancelAllOrdersResponse.OrderStatus[orderID] = err.Error()
|
||||
cancelAllOrdersResponse.Status[orderID] = err.Error()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -449,8 +454,8 @@ func (k *Kraken) CancelAllOrders(_ *exchange.OrderCancellation) (exchange.Cancel
|
||||
}
|
||||
|
||||
// GetOrderInfo returns information on a current open order
|
||||
func (k *Kraken) GetOrderInfo(orderID string) (exchange.OrderDetail, error) {
|
||||
var orderDetail exchange.OrderDetail
|
||||
func (k *Kraken) GetOrderInfo(orderID string) (order.Detail, error) {
|
||||
var orderDetail order.Detail
|
||||
return orderDetail, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
@@ -506,20 +511,20 @@ func (k *Kraken) GetFeeByType(feeBuilder *exchange.FeeBuilder) (float64, error)
|
||||
}
|
||||
|
||||
// GetActiveOrders retrieves any orders that are active/open
|
||||
func (k *Kraken) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
func (k *Kraken) GetActiveOrders(req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
resp, err := k.GetOpenOrders(OrderInfoOptions{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var orders []exchange.OrderDetail
|
||||
var orders []order.Detail
|
||||
for i := range resp.Open {
|
||||
symbol := currency.NewPairFromString(resp.Open[i].Description.Pair)
|
||||
orderDate := time.Unix(int64(resp.Open[i].StartTime), 0)
|
||||
side := exchange.OrderSide(strings.ToUpper(resp.Open[i].Description.Type))
|
||||
orderType := exchange.OrderType(strings.ToUpper(resp.Open[i].Description.OrderType))
|
||||
side := order.Side(strings.ToUpper(resp.Open[i].Description.Type))
|
||||
orderType := order.Type(strings.ToUpper(resp.Open[i].Description.OrderType))
|
||||
|
||||
orders = append(orders, exchange.OrderDetail{
|
||||
orders = append(orders, order.Detail{
|
||||
ID: i,
|
||||
Amount: resp.Open[i].Volume,
|
||||
RemainingAmount: (resp.Open[i].Volume - resp.Open[i].VolumeExecuted),
|
||||
@@ -533,22 +538,21 @@ func (k *Kraken) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([
|
||||
})
|
||||
}
|
||||
|
||||
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks,
|
||||
getOrdersRequest.EndTicks)
|
||||
exchange.FilterOrdersBySide(&orders, getOrdersRequest.OrderSide)
|
||||
exchange.FilterOrdersByCurrencies(&orders, getOrdersRequest.Currencies)
|
||||
order.FilterOrdersByTickRange(&orders, req.StartTicks, req.EndTicks)
|
||||
order.FilterOrdersBySide(&orders, req.OrderSide)
|
||||
order.FilterOrdersByCurrencies(&orders, req.Currencies)
|
||||
return orders, nil
|
||||
}
|
||||
|
||||
// GetOrderHistory retrieves account order information
|
||||
// Can Limit response to specific order status
|
||||
func (k *Kraken) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
func (k *Kraken) GetOrderHistory(getOrdersRequest *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
req := GetClosedOrdersOptions{}
|
||||
if getOrdersRequest.StartTicks.Unix() > 0 {
|
||||
req.Start = fmt.Sprintf("%v", getOrdersRequest.StartTicks.Unix())
|
||||
req.Start = strconv.FormatInt(getOrdersRequest.StartTicks.Unix(), 10)
|
||||
}
|
||||
if getOrdersRequest.EndTicks.Unix() > 0 {
|
||||
req.End = fmt.Sprintf("%v", getOrdersRequest.EndTicks.Unix())
|
||||
req.End = strconv.FormatInt(getOrdersRequest.EndTicks.Unix(), 10)
|
||||
}
|
||||
|
||||
resp, err := k.GetClosedOrders(req)
|
||||
@@ -556,14 +560,14 @@ func (k *Kraken) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var orders []exchange.OrderDetail
|
||||
var orders []order.Detail
|
||||
for i := range resp.Closed {
|
||||
symbol := currency.NewPairFromString(resp.Closed[i].Description.Pair)
|
||||
orderDate := time.Unix(int64(resp.Closed[i].StartTime), 0)
|
||||
side := exchange.OrderSide(strings.ToUpper(resp.Closed[i].Description.Type))
|
||||
orderType := exchange.OrderType(strings.ToUpper(resp.Closed[i].Description.OrderType))
|
||||
side := order.Side(strings.ToUpper(resp.Closed[i].Description.Type))
|
||||
orderType := order.Type(strings.ToUpper(resp.Closed[i].Description.OrderType))
|
||||
|
||||
orders = append(orders, exchange.OrderDetail{
|
||||
orders = append(orders, order.Detail{
|
||||
ID: i,
|
||||
Amount: resp.Closed[i].Volume,
|
||||
RemainingAmount: (resp.Closed[i].Volume - resp.Closed[i].VolumeExecuted),
|
||||
@@ -577,8 +581,8 @@ func (k *Kraken) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([
|
||||
})
|
||||
}
|
||||
|
||||
exchange.FilterOrdersBySide(&orders, getOrdersRequest.OrderSide)
|
||||
exchange.FilterOrdersByCurrencies(&orders, getOrdersRequest.Currencies)
|
||||
order.FilterOrdersBySide(&orders, getOrdersRequest.OrderSide)
|
||||
order.FilterOrdersByCurrencies(&orders, getOrdersRequest.Currencies)
|
||||
return orders, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,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/sharedtestvalues"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
)
|
||||
@@ -272,8 +273,8 @@ func TestGetActiveOrders(t *testing.T) {
|
||||
l.SetDefaults()
|
||||
TestSetup(t)
|
||||
|
||||
var getOrdersRequest = exchange.GetOrdersRequest{
|
||||
OrderType: exchange.AnyOrderType,
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
OrderType: order.AnyType,
|
||||
}
|
||||
|
||||
_, err := l.GetActiveOrders(&getOrdersRequest)
|
||||
@@ -288,8 +289,8 @@ func TestGetOrderHistory(t *testing.T) {
|
||||
l.SetDefaults()
|
||||
TestSetup(t)
|
||||
|
||||
var getOrdersRequest = exchange.GetOrdersRequest{
|
||||
OrderType: exchange.AnyOrderType,
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
OrderType: order.AnyType,
|
||||
}
|
||||
|
||||
_, err := l.GetOrderHistory(&getOrdersRequest)
|
||||
@@ -314,13 +315,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.BTC,
|
||||
Quote: currency.EUR,
|
||||
},
|
||||
OrderSide: exchange.BuyOrderSide,
|
||||
OrderType: exchange.LimitOrderType,
|
||||
OrderSide: order.Buy,
|
||||
OrderType: order.Limit,
|
||||
Price: 1,
|
||||
Amount: 1,
|
||||
ClientID: "meowOrder",
|
||||
@@ -343,7 +344,7 @@ func TestCancelExchangeOrder(t *testing.T) {
|
||||
|
||||
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
|
||||
var orderCancellation = &exchange.OrderCancellation{
|
||||
var orderCancellation = &order.Cancel{
|
||||
OrderID: "1",
|
||||
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
AccountID: "1",
|
||||
@@ -369,7 +370,7 @@ func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
|
||||
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
|
||||
var orderCancellation = &exchange.OrderCancellation{
|
||||
var orderCancellation = &order.Cancel{
|
||||
OrderID: "1",
|
||||
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
AccountID: "1",
|
||||
@@ -385,13 +386,13 @@ 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))
|
||||
}
|
||||
}
|
||||
|
||||
func TestModifyOrder(t *testing.T) {
|
||||
_, err := l.ModifyOrder(&exchange.ModifyOrder{})
|
||||
_, err := l.ModifyOrder(&order.Modify{})
|
||||
if err == nil {
|
||||
t.Error("ModifyOrder() Expected error")
|
||||
}
|
||||
|
||||
@@ -13,6 +13,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"
|
||||
@@ -324,21 +325,17 @@ func (l *LakeBTC) GetExchangeHistory(p currency.Pair, assetType asset.Item) ([]e
|
||||
}
|
||||
|
||||
// SubmitOrder submits a new order
|
||||
func (l *LakeBTC) 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 (l *LakeBTC) SubmitOrder(s *order.Submit) (order.SubmitResponse, error) {
|
||||
var submitOrderResponse order.SubmitResponse
|
||||
if err := s.Validate(); err != nil {
|
||||
return submitOrderResponse, err
|
||||
}
|
||||
|
||||
isBuyOrder := order.OrderSide == exchange.BuyOrderSide
|
||||
response, err := l.Trade(isBuyOrder, order.Amount, order.Price,
|
||||
order.Pair.Lower().String())
|
||||
isBuyOrder := s.OrderSide == order.Buy
|
||||
response, err := l.Trade(isBuyOrder, s.Amount, s.Price,
|
||||
s.Pair.Lower().String())
|
||||
if response.ID > 0 {
|
||||
submitOrderResponse.OrderID = fmt.Sprintf("%v", response.ID)
|
||||
submitOrderResponse.OrderID = strconv.FormatInt(response.ID, 10)
|
||||
}
|
||||
if err == nil {
|
||||
submitOrderResponse.IsOrderPlaced = true
|
||||
@@ -348,12 +345,12 @@ func (l *LakeBTC) SubmitOrder(order *exchange.OrderSubmission) (exchange.SubmitO
|
||||
|
||||
// ModifyOrder will allow of changing orderbook placement and limit to
|
||||
// market conversion
|
||||
func (l *LakeBTC) ModifyOrder(action *exchange.ModifyOrder) (string, error) {
|
||||
func (l *LakeBTC) ModifyOrder(action *order.Modify) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// CancelOrder cancels an order by its corresponding ID number
|
||||
func (l *LakeBTC) CancelOrder(order *exchange.OrderCancellation) error {
|
||||
func (l *LakeBTC) CancelOrder(order *order.Cancel) error {
|
||||
orderIDInt, err := strconv.ParseInt(order.OrderID, 10, 64)
|
||||
|
||||
if err != nil {
|
||||
@@ -364,8 +361,8 @@ func (l *LakeBTC) CancelOrder(order *exchange.OrderCancellation) error {
|
||||
}
|
||||
|
||||
// CancelAllOrders cancels all orders associated with a currency pair
|
||||
func (l *LakeBTC) CancelAllOrders(_ *exchange.OrderCancellation) (exchange.CancelAllOrdersResponse, error) {
|
||||
var cancelAllOrdersResponse exchange.CancelAllOrdersResponse
|
||||
func (l *LakeBTC) CancelAllOrders(_ *order.Cancel) (order.CancelAllResponse, error) {
|
||||
var cancelAllOrdersResponse order.CancelAllResponse
|
||||
openOrders, err := l.GetOpenOrders()
|
||||
if err != nil {
|
||||
return cancelAllOrdersResponse, err
|
||||
@@ -381,8 +378,8 @@ func (l *LakeBTC) CancelAllOrders(_ *exchange.OrderCancellation) (exchange.Cance
|
||||
}
|
||||
|
||||
// GetOrderInfo returns information on a current open order
|
||||
func (l *LakeBTC) GetOrderInfo(orderID string) (exchange.OrderDetail, error) {
|
||||
var orderDetail exchange.OrderDetail
|
||||
func (l *LakeBTC) GetOrderInfo(orderID string) (order.Detail, error) {
|
||||
var orderDetail order.Detail
|
||||
return orderDetail, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
@@ -413,7 +410,7 @@ func (l *LakeBTC) WithdrawCryptocurrencyFunds(withdrawRequest *exchange.CryptoWi
|
||||
return "", err
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%v", resp.ID), nil
|
||||
return strconv.FormatInt(resp.ID, 10), nil
|
||||
}
|
||||
|
||||
// WithdrawFiatFunds returns a withdrawal ID when a
|
||||
@@ -443,23 +440,23 @@ func (l *LakeBTC) GetFeeByType(feeBuilder *exchange.FeeBuilder) (float64, error)
|
||||
}
|
||||
|
||||
// GetActiveOrders retrieves any orders that are active/open
|
||||
func (l *LakeBTC) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
func (l *LakeBTC) GetActiveOrders(req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
resp, err := l.GetOpenOrders()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var orders []exchange.OrderDetail
|
||||
for _, order := range resp {
|
||||
symbol := currency.NewPairDelimiter(order.Symbol,
|
||||
var orders []order.Detail
|
||||
for i := range resp {
|
||||
symbol := currency.NewPairDelimiter(resp[i].Symbol,
|
||||
l.GetPairFormat(asset.Spot, false).Delimiter)
|
||||
orderDate := time.Unix(order.At, 0)
|
||||
side := exchange.OrderSide(strings.ToUpper(order.Type))
|
||||
orderDate := time.Unix(resp[i].At, 0)
|
||||
side := order.Side(strings.ToUpper(resp[i].Type))
|
||||
|
||||
orders = append(orders, exchange.OrderDetail{
|
||||
Amount: order.Amount,
|
||||
ID: fmt.Sprintf("%v", order.ID),
|
||||
Price: order.Price,
|
||||
orders = append(orders, order.Detail{
|
||||
Amount: resp[i].Amount,
|
||||
ID: strconv.FormatInt(resp[i].ID, 10),
|
||||
Price: resp[i].Price,
|
||||
OrderSide: side,
|
||||
OrderDate: orderDate,
|
||||
CurrencyPair: symbol,
|
||||
@@ -467,36 +464,36 @@ func (l *LakeBTC) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) (
|
||||
})
|
||||
}
|
||||
|
||||
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks, getOrdersRequest.EndTicks)
|
||||
exchange.FilterOrdersBySide(&orders, getOrdersRequest.OrderSide)
|
||||
exchange.FilterOrdersByCurrencies(&orders, getOrdersRequest.Currencies)
|
||||
order.FilterOrdersByTickRange(&orders, req.StartTicks, req.EndTicks)
|
||||
order.FilterOrdersBySide(&orders, req.OrderSide)
|
||||
order.FilterOrdersByCurrencies(&orders, req.Currencies)
|
||||
|
||||
return orders, nil
|
||||
}
|
||||
|
||||
// GetOrderHistory retrieves account order information
|
||||
// Can Limit response to specific order status
|
||||
func (l *LakeBTC) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
func (l *LakeBTC) GetOrderHistory(req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
resp, err := l.GetOrders([]int64{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var orders []exchange.OrderDetail
|
||||
for _, order := range resp {
|
||||
if order.State == "active" {
|
||||
var orders []order.Detail
|
||||
for i := range resp {
|
||||
if resp[i].State == "active" {
|
||||
continue
|
||||
}
|
||||
|
||||
symbol := currency.NewPairDelimiter(order.Symbol,
|
||||
symbol := currency.NewPairDelimiter(resp[i].Symbol,
|
||||
l.GetPairFormat(asset.Spot, false).Delimiter)
|
||||
orderDate := time.Unix(order.At, 0)
|
||||
side := exchange.OrderSide(strings.ToUpper(order.Type))
|
||||
orderDate := time.Unix(resp[i].At, 0)
|
||||
side := order.Side(strings.ToUpper(resp[i].Type))
|
||||
|
||||
orders = append(orders, exchange.OrderDetail{
|
||||
Amount: order.Amount,
|
||||
ID: fmt.Sprintf("%v", order.ID),
|
||||
Price: order.Price,
|
||||
orders = append(orders, order.Detail{
|
||||
Amount: resp[i].Amount,
|
||||
ID: strconv.FormatInt(resp[i].ID, 10),
|
||||
Price: resp[i].Price,
|
||||
OrderSide: side,
|
||||
OrderDate: orderDate,
|
||||
CurrencyPair: symbol,
|
||||
@@ -504,10 +501,9 @@ func (l *LakeBTC) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) (
|
||||
})
|
||||
}
|
||||
|
||||
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks,
|
||||
getOrdersRequest.EndTicks)
|
||||
exchange.FilterOrdersBySide(&orders, getOrdersRequest.OrderSide)
|
||||
exchange.FilterOrdersByCurrencies(&orders, getOrdersRequest.Currencies)
|
||||
order.FilterOrdersByTickRange(&orders, req.StartTicks, req.EndTicks)
|
||||
order.FilterOrdersBySide(&orders, req.OrderSide)
|
||||
order.FilterOrdersByCurrencies(&orders, req.Currencies)
|
||||
|
||||
return orders, nil
|
||||
}
|
||||
|
||||
@@ -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 for due diligence testing
|
||||
@@ -312,14 +313,14 @@ 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.BTC,
|
||||
Quote: currency.USDT,
|
||||
Delimiter: "_",
|
||||
},
|
||||
OrderSide: exchange.BuyOrderSide,
|
||||
OrderType: exchange.LimitOrderType,
|
||||
OrderSide: order.Buy,
|
||||
OrderType: order.Limit,
|
||||
Price: 1,
|
||||
Amount: 1,
|
||||
ClientID: "meowOrder",
|
||||
@@ -338,7 +339,7 @@ func TestCancelOrder(t *testing.T) {
|
||||
t.Skip("skipping test, either api keys or manipulaterealorders isnt set correctly")
|
||||
}
|
||||
cp := currency.NewPairWithDelimiter(currency.ETH.String(), currency.BTC.String(), "_")
|
||||
var a exchange.OrderCancellation
|
||||
var a order.Cancel
|
||||
a.CurrencyPair = cp
|
||||
a.OrderID = "24f7ce27-af1d-4dca-a8c1-ef1cbeec1b23"
|
||||
err := l.CancelOrder(&a)
|
||||
@@ -401,8 +402,8 @@ func TestGetOrderHistory(t *testing.T) {
|
||||
if !areTestAPIKeysSet() {
|
||||
t.Skip("API keys required but not set, skipping test")
|
||||
}
|
||||
var input exchange.GetOrdersRequest
|
||||
input.OrderSide = exchange.BuyOrderSide
|
||||
var input order.GetOrdersRequest
|
||||
input.OrderSide = order.Buy
|
||||
_, err := l.GetOrderHistory(&input)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
|
||||
@@ -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"
|
||||
@@ -293,27 +294,22 @@ func (l *Lbank) GetExchangeHistory(p currency.Pair, assetType asset.Item) ([]exc
|
||||
}
|
||||
|
||||
// SubmitOrder submits a new order
|
||||
func (l *Lbank) 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 (l *Lbank) SubmitOrder(s *order.Submit) (order.SubmitResponse, error) {
|
||||
var resp order.SubmitResponse
|
||||
if err := s.Validate(); err != nil {
|
||||
return resp, err
|
||||
}
|
||||
|
||||
if order.OrderSide != exchange.BuyOrderSide &&
|
||||
order.OrderSide != exchange.SellOrderSide {
|
||||
if s.OrderSide != order.Buy && s.OrderSide != order.Sell {
|
||||
return resp,
|
||||
fmt.Errorf("%s order side is not supported by the exchange",
|
||||
order.OrderSide)
|
||||
s.OrderSide)
|
||||
}
|
||||
tempResp, err := l.CreateOrder(
|
||||
l.FormatExchangeCurrency(order.Pair, asset.Spot).String(),
|
||||
order.OrderSide.ToString(),
|
||||
order.Amount,
|
||||
order.Price)
|
||||
l.FormatExchangeCurrency(s.Pair, asset.Spot).String(),
|
||||
s.OrderSide.String(),
|
||||
s.Amount,
|
||||
s.Price)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -324,20 +320,20 @@ func (l *Lbank) SubmitOrder(order *exchange.OrderSubmission) (exchange.SubmitOrd
|
||||
|
||||
// ModifyOrder will allow of changing orderbook placement and limit to
|
||||
// market conversion
|
||||
func (l *Lbank) ModifyOrder(action *exchange.ModifyOrder) (string, error) {
|
||||
func (l *Lbank) ModifyOrder(action *order.Modify) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// CancelOrder cancels an order by its corresponding ID number
|
||||
func (l *Lbank) CancelOrder(order *exchange.OrderCancellation) error {
|
||||
func (l *Lbank) CancelOrder(order *order.Cancel) error {
|
||||
_, err := l.RemoveOrder(l.FormatExchangeCurrency(order.CurrencyPair,
|
||||
order.AssetType).String(), order.OrderID)
|
||||
return err
|
||||
}
|
||||
|
||||
// CancelAllOrders cancels all orders associated with a currency pair
|
||||
func (l *Lbank) CancelAllOrders(orders *exchange.OrderCancellation) (exchange.CancelAllOrdersResponse, error) {
|
||||
var resp exchange.CancelAllOrdersResponse
|
||||
func (l *Lbank) CancelAllOrders(orders *order.Cancel) (order.CancelAllResponse, error) {
|
||||
var resp order.CancelAllResponse
|
||||
orderIDs, err := l.getAllOpenOrderID()
|
||||
if err != nil {
|
||||
return resp, nil
|
||||
@@ -362,11 +358,11 @@ func (l *Lbank) CancelAllOrders(orders *exchange.OrderCancellation) (exchange.Ca
|
||||
}
|
||||
tempStringSuccess := strings.Split(CancelResponse.Success, ",")
|
||||
for k := range tempStringSuccess {
|
||||
resp.OrderStatus[tempStringSuccess[k]] = "Cancelled"
|
||||
resp.Status[tempStringSuccess[k]] = "Cancelled"
|
||||
}
|
||||
tempStringError := strings.Split(CancelResponse.Err, ",")
|
||||
for l := range tempStringError {
|
||||
resp.OrderStatus[tempStringError[l]] = "Failed"
|
||||
resp.Status[tempStringError[l]] = "Failed"
|
||||
}
|
||||
tempSlice = tempSlice[:0]
|
||||
y++
|
||||
@@ -380,11 +376,11 @@ func (l *Lbank) CancelAllOrders(orders *exchange.OrderCancellation) (exchange.Ca
|
||||
}
|
||||
tempStringSuccess := strings.Split(CancelResponse.Success, ",")
|
||||
for k := range tempStringSuccess {
|
||||
resp.OrderStatus[tempStringSuccess[k]] = "Cancelled"
|
||||
resp.Status[tempStringSuccess[k]] = "Cancelled"
|
||||
}
|
||||
tempStringError := strings.Split(CancelResponse.Err, ",")
|
||||
for l := range tempStringError {
|
||||
resp.OrderStatus[tempStringError[l]] = "Failed"
|
||||
resp.Status[tempStringError[l]] = "Failed"
|
||||
}
|
||||
tempSlice = tempSlice[:0]
|
||||
}
|
||||
@@ -393,8 +389,8 @@ func (l *Lbank) CancelAllOrders(orders *exchange.OrderCancellation) (exchange.Ca
|
||||
}
|
||||
|
||||
// GetOrderInfo returns information on a current open order
|
||||
func (l *Lbank) GetOrderInfo(orderID string) (exchange.OrderDetail, error) {
|
||||
var resp exchange.OrderDetail
|
||||
func (l *Lbank) GetOrderInfo(orderID string) (order.Detail, error) {
|
||||
var resp order.Detail
|
||||
orderIDs, err := l.getAllOpenOrderID()
|
||||
if err != nil {
|
||||
return resp, err
|
||||
@@ -412,9 +408,9 @@ func (l *Lbank) GetOrderInfo(orderID string) (exchange.OrderDetail, error) {
|
||||
resp.Exchange = l.GetName()
|
||||
resp.CurrencyPair = currency.NewPairFromString(key)
|
||||
if strings.EqualFold(tempResp.Orders[0].Type, "buy") {
|
||||
resp.OrderSide = exchange.BuyOrderSide
|
||||
resp.OrderSide = order.Buy
|
||||
} else {
|
||||
resp.OrderSide = exchange.SellOrderSide
|
||||
resp.OrderSide = order.Sell
|
||||
}
|
||||
z := tempResp.Orders[0].Status
|
||||
switch {
|
||||
@@ -477,9 +473,9 @@ func (l *Lbank) GetWebsocket() (*wshandler.Websocket, error) {
|
||||
}
|
||||
|
||||
// GetActiveOrders retrieves any orders that are active/open
|
||||
func (l *Lbank) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
var finalResp []exchange.OrderDetail
|
||||
var resp exchange.OrderDetail
|
||||
func (l *Lbank) GetActiveOrders(getOrdersRequest *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
var finalResp []order.Detail
|
||||
var resp order.Detail
|
||||
tempData, err := l.getAllOpenOrderID()
|
||||
if err != nil {
|
||||
return finalResp, err
|
||||
@@ -494,9 +490,9 @@ func (l *Lbank) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([]
|
||||
resp.Exchange = l.GetName()
|
||||
resp.CurrencyPair = currency.NewPairFromString(key)
|
||||
if strings.EqualFold(tempResp.Orders[0].Type, "buy") {
|
||||
resp.OrderSide = exchange.BuyOrderSide
|
||||
resp.OrderSide = order.Buy
|
||||
} else {
|
||||
resp.OrderSide = exchange.SellOrderSide
|
||||
resp.OrderSide = order.Sell
|
||||
}
|
||||
z := tempResp.Orders[0].Status
|
||||
switch {
|
||||
@@ -533,7 +529,8 @@ func (l *Lbank) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([]
|
||||
finalResp = append(finalResp, resp)
|
||||
continue
|
||||
}
|
||||
if strings.EqualFold(getOrdersRequest.OrderSide.ToString(), tempResp.Orders[0].Type) {
|
||||
if strings.EqualFold(getOrdersRequest.OrderSide.String(),
|
||||
tempResp.Orders[0].Type) {
|
||||
finalResp = append(finalResp, resp)
|
||||
}
|
||||
}
|
||||
@@ -544,9 +541,9 @@ func (l *Lbank) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([]
|
||||
|
||||
// GetOrderHistory retrieves account order information *
|
||||
// Can Limit response to specific order status
|
||||
func (l *Lbank) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
var finalResp []exchange.OrderDetail
|
||||
var resp exchange.OrderDetail
|
||||
func (l *Lbank) GetOrderHistory(getOrdersRequest *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
var finalResp []order.Detail
|
||||
var resp order.Detail
|
||||
var tempCurr currency.Pairs
|
||||
if len(getOrdersRequest.Currencies) == 0 {
|
||||
tempCurr = l.GetEnabledPairs(asset.Spot)
|
||||
@@ -569,9 +566,9 @@ func (l *Lbank) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([]
|
||||
resp.Exchange = l.GetName()
|
||||
resp.CurrencyPair = currency.NewPairFromString(tempResp.Orders[x].Symbol)
|
||||
if strings.EqualFold(tempResp.Orders[x].Type, "buy") {
|
||||
resp.OrderSide = exchange.BuyOrderSide
|
||||
resp.OrderSide = order.Buy
|
||||
} else {
|
||||
resp.OrderSide = exchange.SellOrderSide
|
||||
resp.OrderSide = order.Sell
|
||||
}
|
||||
z := tempResp.Orders[x].Status
|
||||
switch {
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"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/order"
|
||||
)
|
||||
|
||||
// Please supply your own APIKEYS here for due diligence testing
|
||||
@@ -200,8 +201,8 @@ func TestFormatWithdrawPermissions(t *testing.T) {
|
||||
func TestGetActiveOrders(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var getOrdersRequest = exchange.GetOrdersRequest{
|
||||
OrderType: exchange.AnyOrderType,
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
OrderType: order.AnyType,
|
||||
}
|
||||
|
||||
_, err := l.GetActiveOrders(&getOrdersRequest)
|
||||
@@ -218,8 +219,8 @@ func TestGetActiveOrders(t *testing.T) {
|
||||
func TestGetOrderHistory(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var getOrdersRequest = exchange.GetOrdersRequest{
|
||||
OrderType: exchange.AnyOrderType,
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
OrderType: order.AnyType,
|
||||
}
|
||||
|
||||
_, err := l.GetOrderHistory(&getOrdersRequest)
|
||||
@@ -246,13 +247,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.BTC,
|
||||
Quote: currency.EUR,
|
||||
},
|
||||
OrderSide: exchange.BuyOrderSide,
|
||||
OrderType: exchange.LimitOrderType,
|
||||
OrderSide: order.Buy,
|
||||
OrderType: order.Limit,
|
||||
Price: 1,
|
||||
Amount: 1,
|
||||
ClientID: "meowOrder",
|
||||
@@ -275,7 +276,7 @@ func TestCancelExchangeOrder(t *testing.T) {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
var orderCancellation = &exchange.OrderCancellation{
|
||||
var orderCancellation = &order.Cancel{
|
||||
OrderID: "1",
|
||||
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
AccountID: "1",
|
||||
@@ -300,7 +301,7 @@ func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
var orderCancellation = &exchange.OrderCancellation{
|
||||
var orderCancellation = &order.Cancel{
|
||||
OrderID: "1",
|
||||
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
AccountID: "1",
|
||||
@@ -317,15 +318,15 @@ 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))
|
||||
}
|
||||
}
|
||||
|
||||
func TestModifyOrder(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
_, err := l.ModifyOrder(&exchange.ModifyOrder{})
|
||||
_, err := l.ModifyOrder(&order.Modify{})
|
||||
if err != common.ErrFunctionNotSupported {
|
||||
t.Error("ModifyOrder() error", err)
|
||||
}
|
||||
|
||||
@@ -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/protocol"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
|
||||
@@ -271,13 +272,9 @@ func (l *LocalBitcoins) GetExchangeHistory(p currency.Pair, assetType asset.Item
|
||||
}
|
||||
|
||||
// SubmitOrder submits a new order
|
||||
func (l *LocalBitcoins) 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 (l *LocalBitcoins) SubmitOrder(s *order.Submit) (order.SubmitResponse, error) {
|
||||
var submitOrderResponse order.SubmitResponse
|
||||
if err := s.Validate(); err != nil {
|
||||
return submitOrderResponse, err
|
||||
}
|
||||
|
||||
@@ -290,17 +287,17 @@ func (l *LocalBitcoins) SubmitOrder(order *exchange.OrderSubmission) (exchange.S
|
||||
City: "City",
|
||||
Location: "Location",
|
||||
CountryCode: "US",
|
||||
Currency: order.Pair.Quote.String(),
|
||||
Currency: s.Pair.Quote.String(),
|
||||
AccountInfo: "-",
|
||||
BankName: "Bank",
|
||||
MSG: order.OrderSide.ToString(),
|
||||
MSG: s.OrderSide.String(),
|
||||
SMSVerficationRequired: true,
|
||||
TrackMaxAmount: true,
|
||||
RequireTrustedByAdvertiser: true,
|
||||
RequireIdentification: true,
|
||||
OnlineProvider: "",
|
||||
TradeType: "",
|
||||
MinAmount: int(math.Round(order.Amount)),
|
||||
MinAmount: int(math.Round(s.Amount)),
|
||||
}
|
||||
|
||||
// Does not return any orderID, so create the add, then get the order
|
||||
@@ -330,8 +327,8 @@ func (l *LocalBitcoins) SubmitOrder(order *exchange.OrderSubmission) (exchange.S
|
||||
ads.AdList[i].Data.RequireTrustedByAdvertiser == params.RequireTrustedByAdvertiser &&
|
||||
ads.AdList[i].Data.OnlineProvider == params.OnlineProvider &&
|
||||
ads.AdList[i].Data.TradeType == params.TradeType &&
|
||||
ads.AdList[i].Data.MinAmount == fmt.Sprintf("%v", params.MinAmount) {
|
||||
adID = fmt.Sprintf("%v", ads.AdList[i].Data.AdID)
|
||||
ads.AdList[i].Data.MinAmount == strconv.FormatInt(int64(params.MinAmount), 10) {
|
||||
adID = strconv.FormatInt(ads.AdList[i].Data.AdID, 10)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -346,19 +343,19 @@ func (l *LocalBitcoins) SubmitOrder(order *exchange.OrderSubmission) (exchange.S
|
||||
|
||||
// ModifyOrder will allow of changing orderbook placement and limit to
|
||||
// market conversion
|
||||
func (l *LocalBitcoins) ModifyOrder(action *exchange.ModifyOrder) (string, error) {
|
||||
func (l *LocalBitcoins) ModifyOrder(action *order.Modify) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// CancelOrder cancels an order by its corresponding ID number
|
||||
func (l *LocalBitcoins) CancelOrder(order *exchange.OrderCancellation) error {
|
||||
func (l *LocalBitcoins) CancelOrder(order *order.Cancel) error {
|
||||
return l.DeleteAd(order.OrderID)
|
||||
}
|
||||
|
||||
// CancelAllOrders cancels all orders associated with a currency pair
|
||||
func (l *LocalBitcoins) CancelAllOrders(_ *exchange.OrderCancellation) (exchange.CancelAllOrdersResponse, error) {
|
||||
cancelAllOrdersResponse := exchange.CancelAllOrdersResponse{
|
||||
OrderStatus: make(map[string]string),
|
||||
func (l *LocalBitcoins) CancelAllOrders(_ *order.Cancel) (order.CancelAllResponse, error) {
|
||||
cancelAllOrdersResponse := order.CancelAllResponse{
|
||||
Status: make(map[string]string),
|
||||
}
|
||||
ads, err := l.Getads()
|
||||
if err != nil {
|
||||
@@ -369,7 +366,7 @@ func (l *LocalBitcoins) CancelAllOrders(_ *exchange.OrderCancellation) (exchange
|
||||
adIDString := strconv.FormatInt(ads.AdList[i].Data.AdID, 10)
|
||||
err = l.DeleteAd(adIDString)
|
||||
if err != nil {
|
||||
cancelAllOrdersResponse.OrderStatus[adIDString] = err.Error()
|
||||
cancelAllOrdersResponse.Status[adIDString] = err.Error()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -377,8 +374,8 @@ func (l *LocalBitcoins) CancelAllOrders(_ *exchange.OrderCancellation) (exchange
|
||||
}
|
||||
|
||||
// GetOrderInfo returns information on a current open order
|
||||
func (l *LocalBitcoins) GetOrderInfo(orderID string) (exchange.OrderDetail, error) {
|
||||
var orderDetail exchange.OrderDetail
|
||||
func (l *LocalBitcoins) GetOrderInfo(orderID string) (order.Detail, error) {
|
||||
var orderDetail order.Detail
|
||||
return orderDetail, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
@@ -428,13 +425,13 @@ func (l *LocalBitcoins) GetFeeByType(feeBuilder *exchange.FeeBuilder) (float64,
|
||||
}
|
||||
|
||||
// GetActiveOrders retrieves any orders that are active/open
|
||||
func (l *LocalBitcoins) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
func (l *LocalBitcoins) GetActiveOrders(getOrdersRequest *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
resp, err := l.GetDashboardInfo()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var orders []exchange.OrderDetail
|
||||
var orders []order.Detail
|
||||
for i := range resp {
|
||||
orderDate, err := time.Parse(time.RFC3339, resp[i].Data.CreatedAt)
|
||||
if err != nil {
|
||||
@@ -445,17 +442,17 @@ func (l *LocalBitcoins) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequ
|
||||
resp[i].Data.CreatedAt)
|
||||
}
|
||||
|
||||
var side exchange.OrderSide
|
||||
var side order.Side
|
||||
if resp[i].Data.IsBuying {
|
||||
side = exchange.BuyOrderSide
|
||||
side = order.Buy
|
||||
} else if resp[i].Data.IsSelling {
|
||||
side = exchange.SellOrderSide
|
||||
side = order.Sell
|
||||
}
|
||||
|
||||
orders = append(orders, exchange.OrderDetail{
|
||||
orders = append(orders, order.Detail{
|
||||
Amount: resp[i].Data.AmountBTC,
|
||||
Price: resp[i].Data.Amount,
|
||||
ID: fmt.Sprintf("%v", resp[i].Data.Advertisement.ID),
|
||||
ID: strconv.FormatInt(int64(resp[i].Data.Advertisement.ID), 10),
|
||||
OrderDate: orderDate,
|
||||
Fee: resp[i].Data.FeeBTC,
|
||||
OrderSide: side,
|
||||
@@ -466,16 +463,16 @@ func (l *LocalBitcoins) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequ
|
||||
})
|
||||
}
|
||||
|
||||
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks,
|
||||
order.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks,
|
||||
getOrdersRequest.EndTicks)
|
||||
exchange.FilterOrdersBySide(&orders, getOrdersRequest.OrderSide)
|
||||
order.FilterOrdersBySide(&orders, getOrdersRequest.OrderSide)
|
||||
|
||||
return orders, nil
|
||||
}
|
||||
|
||||
// GetOrderHistory retrieves account order information
|
||||
// Can Limit response to specific order status
|
||||
func (l *LocalBitcoins) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
func (l *LocalBitcoins) GetOrderHistory(getOrdersRequest *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
var allTrades []DashBoardInfo
|
||||
resp, err := l.GetDashboardCancelledTrades()
|
||||
if err != nil {
|
||||
@@ -495,43 +492,47 @@ func (l *LocalBitcoins) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequ
|
||||
}
|
||||
allTrades = append(allTrades, resp...)
|
||||
|
||||
var orders []exchange.OrderDetail
|
||||
var orders []order.Detail
|
||||
for i := range allTrades {
|
||||
orderDate, err := time.Parse(time.RFC3339, allTrades[i].Data.CreatedAt)
|
||||
if err != nil {
|
||||
log.Warnf(log.ExchangeSys, "Exchange %v Func %v Order %v Could not parse date to unix with value of %v",
|
||||
log.Warnf(log.ExchangeSys,
|
||||
"Exchange %v Func %v Order %v Could not parse date to unix with value of %v",
|
||||
l.Name,
|
||||
"GetActiveOrders",
|
||||
allTrades[i].Data.Advertisement.ID,
|
||||
allTrades[i].Data.CreatedAt)
|
||||
}
|
||||
|
||||
var side exchange.OrderSide
|
||||
var side order.Side
|
||||
if allTrades[i].Data.IsBuying {
|
||||
side = exchange.BuyOrderSide
|
||||
side = order.Buy
|
||||
} else if allTrades[i].Data.IsSelling {
|
||||
side = exchange.SellOrderSide
|
||||
side = order.Sell
|
||||
}
|
||||
|
||||
status := ""
|
||||
|
||||
switch {
|
||||
case allTrades[i].Data.ReleasedAt != "" && allTrades[i].Data.ReleasedAt != null:
|
||||
case allTrades[i].Data.ReleasedAt != "" &&
|
||||
allTrades[i].Data.ReleasedAt != null:
|
||||
status = "Released"
|
||||
case allTrades[i].Data.CanceledAt != "" && allTrades[i].Data.CanceledAt != null:
|
||||
case allTrades[i].Data.CanceledAt != "" &&
|
||||
allTrades[i].Data.CanceledAt != null:
|
||||
status = "Cancelled"
|
||||
case allTrades[i].Data.ClosedAt != "" && allTrades[i].Data.ClosedAt != null:
|
||||
case allTrades[i].Data.ClosedAt != "" &&
|
||||
allTrades[i].Data.ClosedAt != null:
|
||||
status = "Closed"
|
||||
}
|
||||
|
||||
orders = append(orders, exchange.OrderDetail{
|
||||
orders = append(orders, order.Detail{
|
||||
Amount: allTrades[i].Data.AmountBTC,
|
||||
Price: allTrades[i].Data.Amount,
|
||||
ID: fmt.Sprintf("%v", allTrades[i].Data.Advertisement.ID),
|
||||
ID: strconv.FormatInt(int64(allTrades[i].Data.Advertisement.ID), 10),
|
||||
OrderDate: orderDate,
|
||||
Fee: allTrades[i].Data.FeeBTC,
|
||||
OrderSide: side,
|
||||
Status: status,
|
||||
Status: order.Status(status),
|
||||
CurrencyPair: currency.NewPairWithDelimiter(currency.BTC.String(),
|
||||
allTrades[i].Data.Currency,
|
||||
l.GetPairFormat(asset.Spot, false).Delimiter),
|
||||
@@ -539,9 +540,9 @@ func (l *LocalBitcoins) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequ
|
||||
})
|
||||
}
|
||||
|
||||
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks,
|
||||
order.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks,
|
||||
getOrdersRequest.EndTicks)
|
||||
exchange.FilterOrdersBySide(&orders, getOrdersRequest.OrderSide)
|
||||
order.FilterOrdersBySide(&orders, getOrdersRequest.OrderSide)
|
||||
|
||||
return orders, nil
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/okgroup"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/sharedtestvalues"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
)
|
||||
@@ -286,8 +287,8 @@ func TestPlaceSpotOrderLimit(t *testing.T) {
|
||||
TestSetRealOrderDefaults(t)
|
||||
request := okgroup.PlaceSpotOrderRequest{
|
||||
InstrumentID: spotCurrency,
|
||||
Type: exchange.LimitOrderType.ToLower().ToString(),
|
||||
Side: exchange.BuyOrderSide.ToLower().ToString(),
|
||||
Type: order.Limit.Lower(),
|
||||
Side: order.Buy.Lower(),
|
||||
MarginTrading: "1",
|
||||
Price: "100",
|
||||
Size: "100",
|
||||
@@ -302,8 +303,8 @@ func TestPlaceSpotOrderMarket(t *testing.T) {
|
||||
TestSetRealOrderDefaults(t)
|
||||
request := okgroup.PlaceSpotOrderRequest{
|
||||
InstrumentID: spotCurrency,
|
||||
Type: exchange.MarketOrderType.ToLower().ToString(),
|
||||
Side: exchange.BuyOrderSide.ToLower().ToString(),
|
||||
Type: order.Market.Lower(),
|
||||
Side: order.Buy.Lower(),
|
||||
MarginTrading: "1",
|
||||
Size: "-100",
|
||||
Notional: "100",
|
||||
@@ -318,8 +319,8 @@ func TestPlaceMultipleSpotOrders(t *testing.T) {
|
||||
TestSetRealOrderDefaults(t)
|
||||
order := okgroup.PlaceSpotOrderRequest{
|
||||
InstrumentID: spotCurrency,
|
||||
Type: exchange.LimitOrderType.ToLower().ToString(),
|
||||
Side: exchange.BuyOrderSide.ToLower().ToString(),
|
||||
Type: order.Limit.Lower(),
|
||||
Side: order.Buy.Lower(),
|
||||
MarginTrading: "1",
|
||||
Size: "100",
|
||||
Notional: "100",
|
||||
@@ -340,8 +341,8 @@ func TestPlaceMultipleSpotOrdersOverCurrencyLimits(t *testing.T) {
|
||||
TestSetDefaults(t)
|
||||
order := okgroup.PlaceSpotOrderRequest{
|
||||
InstrumentID: spotCurrency,
|
||||
Type: exchange.LimitOrderType.ToLower().ToString(),
|
||||
Side: exchange.BuyOrderSide.ToLower().ToString(),
|
||||
Type: order.Limit.Lower(),
|
||||
Side: order.Buy.Lower(),
|
||||
MarginTrading: "1",
|
||||
Size: "100",
|
||||
Notional: "100",
|
||||
@@ -366,8 +367,8 @@ func TestPlaceMultipleSpotOrdersOverPairLimits(t *testing.T) {
|
||||
TestSetDefaults(t)
|
||||
order := okgroup.PlaceSpotOrderRequest{
|
||||
InstrumentID: spotCurrency,
|
||||
Type: exchange.LimitOrderType.ToLower().ToString(),
|
||||
Side: exchange.BuyOrderSide.ToLower().ToString(),
|
||||
Type: order.Limit.Lower(),
|
||||
Side: order.Buy.Lower(),
|
||||
MarginTrading: "1",
|
||||
Size: "100",
|
||||
Notional: "100",
|
||||
@@ -613,8 +614,8 @@ func TestPlaceMarginOrderLimit(t *testing.T) {
|
||||
TestSetRealOrderDefaults(t)
|
||||
request := okgroup.PlaceSpotOrderRequest{
|
||||
InstrumentID: spotCurrency,
|
||||
Type: exchange.LimitOrderType.ToLower().ToString(),
|
||||
Side: exchange.BuyOrderSide.ToLower().ToString(),
|
||||
Type: order.Limit.Lower(),
|
||||
Side: order.Buy.Lower(),
|
||||
MarginTrading: "2",
|
||||
Price: "100",
|
||||
Size: "100",
|
||||
@@ -629,8 +630,8 @@ func TestPlaceMarginOrderMarket(t *testing.T) {
|
||||
TestSetRealOrderDefaults(t)
|
||||
request := okgroup.PlaceSpotOrderRequest{
|
||||
InstrumentID: spotCurrency,
|
||||
Type: exchange.MarketOrderType.ToLower().ToString(),
|
||||
Side: exchange.BuyOrderSide.ToLower().ToString(),
|
||||
Type: order.Market.Lower(),
|
||||
Side: order.Buy.Lower(),
|
||||
MarginTrading: "2",
|
||||
Size: "-100",
|
||||
Notional: "100",
|
||||
@@ -645,8 +646,8 @@ func TestPlaceMultipleMarginOrders(t *testing.T) {
|
||||
TestSetRealOrderDefaults(t)
|
||||
order := okgroup.PlaceSpotOrderRequest{
|
||||
InstrumentID: spotCurrency,
|
||||
Type: exchange.LimitOrderType.ToLower().ToString(),
|
||||
Side: exchange.BuyOrderSide.ToLower().ToString(),
|
||||
Type: order.Limit.Lower(),
|
||||
Side: order.Buy.Lower(),
|
||||
MarginTrading: "1",
|
||||
Size: "100",
|
||||
Notional: "100",
|
||||
@@ -667,8 +668,8 @@ func TestPlaceMultipleMarginOrdersOverCurrencyLimits(t *testing.T) {
|
||||
TestSetDefaults(t)
|
||||
order := okgroup.PlaceSpotOrderRequest{
|
||||
InstrumentID: spotCurrency,
|
||||
Type: exchange.LimitOrderType.ToLower().ToString(),
|
||||
Side: exchange.BuyOrderSide.ToLower().ToString(),
|
||||
Type: order.Limit.Lower(),
|
||||
Side: order.Buy.Lower(),
|
||||
MarginTrading: "1",
|
||||
Size: "100",
|
||||
Notional: "100",
|
||||
@@ -693,8 +694,8 @@ func TestPlaceMultipleMarginOrdersOverPairLimits(t *testing.T) {
|
||||
TestSetDefaults(t)
|
||||
order := okgroup.PlaceSpotOrderRequest{
|
||||
InstrumentID: spotCurrency,
|
||||
Type: exchange.LimitOrderType.ToLower().ToString(),
|
||||
Side: exchange.BuyOrderSide.ToLower().ToString(),
|
||||
Type: order.Limit.Lower(),
|
||||
Side: order.Buy.Lower(),
|
||||
MarginTrading: "1",
|
||||
Size: "100",
|
||||
Notional: "100",
|
||||
@@ -1053,13 +1054,13 @@ func TestFormatWithdrawPermissions(t *testing.T) {
|
||||
// TestSubmitOrder Wrapper test
|
||||
func TestSubmitOrder(t *testing.T) {
|
||||
TestSetRealOrderDefaults(t)
|
||||
var orderSubmission = &exchange.OrderSubmission{
|
||||
var orderSubmission = &order.Submit{
|
||||
Pair: currency.Pair{
|
||||
Base: currency.BTC,
|
||||
Quote: currency.USD,
|
||||
},
|
||||
OrderSide: exchange.BuyOrderSide,
|
||||
OrderType: exchange.LimitOrderType,
|
||||
OrderSide: order.Buy,
|
||||
OrderType: order.Limit,
|
||||
Price: 1,
|
||||
Amount: 1,
|
||||
ClientID: "meowOrder",
|
||||
@@ -1076,7 +1077,7 @@ func TestSubmitOrder(t *testing.T) {
|
||||
func TestCancelExchangeOrder(t *testing.T) {
|
||||
TestSetRealOrderDefaults(t)
|
||||
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
var orderCancellation = exchange.OrderCancellation{
|
||||
var orderCancellation = order.Cancel{
|
||||
OrderID: "1",
|
||||
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
AccountID: "1",
|
||||
@@ -1092,7 +1093,7 @@ func TestCancelExchangeOrder(t *testing.T) {
|
||||
func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
TestSetRealOrderDefaults(t)
|
||||
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
var orderCancellation = exchange.OrderCancellation{
|
||||
var orderCancellation = order.Cancel{
|
||||
OrderID: "1",
|
||||
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
AccountID: "1",
|
||||
@@ -1101,8 +1102,8 @@ func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
|
||||
resp, err := o.CancelAllOrders(&orderCancellation)
|
||||
testStandardErrorHandling(t, 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))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1115,7 +1116,7 @@ func TestGetAccountInfo(t *testing.T) {
|
||||
// TestModifyOrder Wrapper test
|
||||
func TestModifyOrder(t *testing.T) {
|
||||
TestSetRealOrderDefaults(t)
|
||||
_, err := o.ModifyOrder(&exchange.ModifyOrder{})
|
||||
_, err := o.ModifyOrder(&order.Modify{})
|
||||
if err != common.ErrFunctionNotSupported {
|
||||
t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err)
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/okgroup"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/sharedtestvalues"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
)
|
||||
@@ -307,8 +308,8 @@ func TestPlaceSpotOrderLimit(t *testing.T) {
|
||||
t.Parallel()
|
||||
request := okgroup.PlaceSpotOrderRequest{
|
||||
InstrumentID: spotCurrency,
|
||||
Type: exchange.LimitOrderType.ToLower().ToString(),
|
||||
Side: exchange.BuyOrderSide.ToLower().ToString(),
|
||||
Type: order.Limit.Lower(),
|
||||
Side: order.Buy.Lower(),
|
||||
MarginTrading: "1",
|
||||
Price: "100",
|
||||
Size: "100",
|
||||
@@ -324,8 +325,8 @@ func TestPlaceSpotOrderMarket(t *testing.T) {
|
||||
t.Parallel()
|
||||
request := okgroup.PlaceSpotOrderRequest{
|
||||
InstrumentID: spotCurrency,
|
||||
Type: exchange.MarketOrderType.ToLower().ToString(),
|
||||
Side: exchange.BuyOrderSide.ToLower().ToString(),
|
||||
Type: order.Market.Lower(),
|
||||
Side: order.Buy.Lower(),
|
||||
MarginTrading: "1",
|
||||
Size: "-100",
|
||||
Notional: "100",
|
||||
@@ -341,8 +342,8 @@ func TestPlaceMultipleSpotOrders(t *testing.T) {
|
||||
t.Parallel()
|
||||
order := okgroup.PlaceSpotOrderRequest{
|
||||
InstrumentID: spotCurrency,
|
||||
Type: exchange.LimitOrderType.ToLower().ToString(),
|
||||
Side: exchange.BuyOrderSide.ToLower().ToString(),
|
||||
Type: order.Limit.Lower(),
|
||||
Side: order.Buy.Lower(),
|
||||
MarginTrading: "1",
|
||||
Size: "100",
|
||||
Notional: "100",
|
||||
@@ -364,8 +365,8 @@ func TestPlaceMultipleSpotOrdersOverCurrencyLimits(t *testing.T) {
|
||||
t.Parallel()
|
||||
order := okgroup.PlaceSpotOrderRequest{
|
||||
InstrumentID: spotCurrency,
|
||||
Type: exchange.LimitOrderType.ToLower().ToString(),
|
||||
Side: exchange.BuyOrderSide.ToLower().ToString(),
|
||||
Type: order.Limit.Lower(),
|
||||
Side: order.Buy.Lower(),
|
||||
MarginTrading: "1",
|
||||
Size: "100",
|
||||
Notional: "100",
|
||||
@@ -391,8 +392,8 @@ func TestPlaceMultipleSpotOrdersOverPairLimits(t *testing.T) {
|
||||
t.Parallel()
|
||||
order := okgroup.PlaceSpotOrderRequest{
|
||||
InstrumentID: spotCurrency,
|
||||
Type: exchange.LimitOrderType.ToLower().ToString(),
|
||||
Side: exchange.BuyOrderSide.ToLower().ToString(),
|
||||
Type: order.Limit.Lower(),
|
||||
Side: order.Buy.Lower(),
|
||||
MarginTrading: "1",
|
||||
Size: "100",
|
||||
Notional: "100",
|
||||
@@ -661,8 +662,8 @@ func TestPlaceMarginOrderLimit(t *testing.T) {
|
||||
t.Parallel()
|
||||
request := okgroup.PlaceSpotOrderRequest{
|
||||
InstrumentID: spotCurrency,
|
||||
Type: exchange.LimitOrderType.ToLower().ToString(),
|
||||
Side: exchange.BuyOrderSide.ToLower().ToString(),
|
||||
Type: order.Limit.Lower(),
|
||||
Side: order.Buy.Lower(),
|
||||
MarginTrading: "2",
|
||||
Price: "100",
|
||||
Size: "100",
|
||||
@@ -678,8 +679,8 @@ func TestPlaceMarginOrderMarket(t *testing.T) {
|
||||
t.Parallel()
|
||||
request := okgroup.PlaceSpotOrderRequest{
|
||||
InstrumentID: spotCurrency,
|
||||
Type: exchange.MarketOrderType.ToLower().ToString(),
|
||||
Side: exchange.BuyOrderSide.ToLower().ToString(),
|
||||
Type: order.Market.Lower(),
|
||||
Side: order.Buy.Lower(),
|
||||
MarginTrading: "2",
|
||||
Size: "-100",
|
||||
Notional: "100",
|
||||
@@ -695,8 +696,8 @@ func TestPlaceMultipleMarginOrders(t *testing.T) {
|
||||
t.Parallel()
|
||||
order := okgroup.PlaceSpotOrderRequest{
|
||||
InstrumentID: spotCurrency,
|
||||
Type: exchange.LimitOrderType.ToLower().ToString(),
|
||||
Side: exchange.BuyOrderSide.ToLower().ToString(),
|
||||
Type: order.Limit.Lower(),
|
||||
Side: order.Buy.Lower(),
|
||||
MarginTrading: "1",
|
||||
Size: "100",
|
||||
Notional: "100",
|
||||
@@ -718,8 +719,8 @@ func TestPlaceMultipleMarginOrdersOverCurrencyLimits(t *testing.T) {
|
||||
t.Parallel()
|
||||
order := okgroup.PlaceSpotOrderRequest{
|
||||
InstrumentID: spotCurrency,
|
||||
Type: exchange.LimitOrderType.ToLower().ToString(),
|
||||
Side: exchange.BuyOrderSide.ToLower().ToString(),
|
||||
Type: order.Limit.Lower(),
|
||||
Side: order.Buy.Lower(),
|
||||
MarginTrading: "1",
|
||||
Size: "100",
|
||||
Notional: "100",
|
||||
@@ -745,8 +746,8 @@ func TestPlaceMultipleMarginOrdersOverPairLimits(t *testing.T) {
|
||||
t.Parallel()
|
||||
order := okgroup.PlaceSpotOrderRequest{
|
||||
InstrumentID: spotCurrency,
|
||||
Type: exchange.LimitOrderType.ToLower().ToString(),
|
||||
Side: exchange.BuyOrderSide.ToLower().ToString(),
|
||||
Type: order.Limit.Lower(),
|
||||
Side: order.Buy.Lower(),
|
||||
MarginTrading: "1",
|
||||
Size: "100",
|
||||
Notional: "100",
|
||||
@@ -1819,13 +1820,13 @@ func TestFormatWithdrawPermissions(t *testing.T) {
|
||||
func TestSubmitOrder(t *testing.T) {
|
||||
TestSetRealOrderDefaults(t)
|
||||
t.Parallel()
|
||||
var orderSubmission = &exchange.OrderSubmission{
|
||||
var orderSubmission = &order.Submit{
|
||||
Pair: currency.Pair{
|
||||
Base: currency.BTC,
|
||||
Quote: currency.USDT,
|
||||
},
|
||||
OrderSide: exchange.BuyOrderSide,
|
||||
OrderType: exchange.LimitOrderType,
|
||||
OrderSide: order.Buy,
|
||||
OrderType: order.Limit,
|
||||
Price: 1,
|
||||
Amount: 1,
|
||||
ClientID: "meowOrder",
|
||||
@@ -1843,7 +1844,7 @@ func TestCancelExchangeOrder(t *testing.T) {
|
||||
TestSetRealOrderDefaults(t)
|
||||
t.Parallel()
|
||||
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
var orderCancellation = exchange.OrderCancellation{
|
||||
var orderCancellation = order.Cancel{
|
||||
OrderID: "1",
|
||||
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
AccountID: "1",
|
||||
@@ -1860,7 +1861,7 @@ func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
TestSetRealOrderDefaults(t)
|
||||
t.Parallel()
|
||||
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
var orderCancellation = exchange.OrderCancellation{
|
||||
var orderCancellation = order.Cancel{
|
||||
OrderID: "1",
|
||||
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
AccountID: "1",
|
||||
@@ -1870,8 +1871,8 @@ func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
resp, err := o.CancelAllOrders(&orderCancellation)
|
||||
testStandardErrorHandling(t, err)
|
||||
|
||||
if len(resp.OrderStatus) > 0 {
|
||||
t.Errorf("%v orders failed to cancel", len(resp.OrderStatus))
|
||||
if len(resp.Status) > 0 {
|
||||
t.Errorf("%d orders failed to cancel", len(resp.Status))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1885,9 +1886,11 @@ func TestGetAccountInfo(t *testing.T) {
|
||||
func TestModifyOrder(t *testing.T) {
|
||||
TestSetRealOrderDefaults(t)
|
||||
t.Parallel()
|
||||
_, err := o.ModifyOrder(&exchange.ModifyOrder{})
|
||||
_, err := o.ModifyOrder(&order.Modify{})
|
||||
if err != common.ErrFunctionNotSupported {
|
||||
t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err)
|
||||
t.Errorf("Expected '%v', received: '%v'",
|
||||
common.ErrFunctionNotSupported,
|
||||
err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1916,7 +1919,9 @@ func TestWithdrawFiat(t *testing.T) {
|
||||
var withdrawFiatRequest = exchange.FiatWithdrawRequest{}
|
||||
_, err := o.WithdrawFiatFunds(&withdrawFiatRequest)
|
||||
if err != common.ErrFunctionNotSupported {
|
||||
t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err)
|
||||
t.Errorf("Expected '%v', received: '%v'",
|
||||
common.ErrFunctionNotSupported,
|
||||
err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1927,6 +1932,8 @@ func TestWithdrawInternationalBank(t *testing.T) {
|
||||
var withdrawFiatRequest = exchange.FiatWithdrawRequest{}
|
||||
_, err := o.WithdrawFiatFundsToInternationalBank(&withdrawFiatRequest)
|
||||
if err != common.ErrFunctionNotSupported {
|
||||
t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err)
|
||||
t.Errorf("Expected '%v', received: '%v'",
|
||||
common.ErrFunctionNotSupported,
|
||||
err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,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"
|
||||
log "github.com/thrasher-corp/gocryptotrader/logger"
|
||||
@@ -89,11 +90,15 @@ func (o *OKGroup) UpdateOrderbook(p currency.Pair, assetType asset.Item) (resp o
|
||||
for x := range orderbookNew.Bids {
|
||||
amount, convErr := strconv.ParseFloat(orderbookNew.Bids[x][1], 64)
|
||||
if convErr != nil {
|
||||
log.Errorf(log.ExchangeSys, "Could not convert %v to float64", orderbookNew.Bids[x][1])
|
||||
log.Errorf(log.ExchangeSys,
|
||||
"Could not convert %v to float64",
|
||||
orderbookNew.Bids[x][1])
|
||||
}
|
||||
price, convErr := strconv.ParseFloat(orderbookNew.Bids[x][0], 64)
|
||||
if convErr != nil {
|
||||
log.Errorf(log.ExchangeSys, "Could not convert %v to float64", orderbookNew.Bids[x][0])
|
||||
log.Errorf(log.ExchangeSys,
|
||||
"Could not convert %v to float64",
|
||||
orderbookNew.Bids[x][0])
|
||||
}
|
||||
resp.Bids = append(resp.Bids, orderbook.Item{
|
||||
Amount: amount,
|
||||
@@ -104,11 +109,15 @@ func (o *OKGroup) UpdateOrderbook(p currency.Pair, assetType asset.Item) (resp o
|
||||
for x := range orderbookNew.Asks {
|
||||
amount, convErr := strconv.ParseFloat(orderbookNew.Asks[x][1], 64)
|
||||
if convErr != nil {
|
||||
log.Errorf(log.ExchangeSys, "Could not convert %v to float64", orderbookNew.Asks[x][1])
|
||||
log.Errorf(log.ExchangeSys,
|
||||
"Could not convert %v to float64",
|
||||
orderbookNew.Asks[x][1])
|
||||
}
|
||||
price, convErr := strconv.ParseFloat(orderbookNew.Asks[x][0], 64)
|
||||
if convErr != nil {
|
||||
log.Errorf(log.ExchangeSys, "Could not convert %v to float64", orderbookNew.Asks[x][0])
|
||||
log.Errorf(log.ExchangeSys,
|
||||
"Could not convert %v to float64",
|
||||
orderbookNew.Asks[x][0])
|
||||
}
|
||||
resp.Asks = append(resp.Asks, orderbook.Item{
|
||||
Amount: amount,
|
||||
@@ -134,20 +143,25 @@ func (o *OKGroup) GetAccountInfo() (resp exchange.AccountInfo, err error) {
|
||||
currencies, err := o.GetSpotTradingAccounts()
|
||||
currencyAccount := exchange.Account{}
|
||||
|
||||
for _, curr := range currencies {
|
||||
hold, err := strconv.ParseFloat(curr.Hold, 64)
|
||||
for i := range currencies {
|
||||
hold, err := strconv.ParseFloat(currencies[i].Hold, 64)
|
||||
if err != nil {
|
||||
log.Errorf(log.ExchangeSys, "Could not convert %v to float64", curr.Hold)
|
||||
log.Errorf(log.ExchangeSys,
|
||||
"Could not convert %v to float64",
|
||||
currencies[i].Hold)
|
||||
}
|
||||
totalValue, err := strconv.ParseFloat(curr.Balance, 64)
|
||||
totalValue, err := strconv.ParseFloat(currencies[i].Balance, 64)
|
||||
if err != nil {
|
||||
log.Errorf(log.ExchangeSys, "Could not convert %v to float64", curr.Balance)
|
||||
log.Errorf(log.ExchangeSys,
|
||||
"Could not convert %v to float64",
|
||||
currencies[i].Balance)
|
||||
}
|
||||
currencyAccount.Currencies = append(currencyAccount.Currencies, exchange.AccountCurrencyInfo{
|
||||
CurrencyName: currency.NewCode(curr.Currency),
|
||||
Hold: hold,
|
||||
TotalValue: totalValue,
|
||||
})
|
||||
currencyAccount.Currencies = append(currencyAccount.Currencies,
|
||||
exchange.AccountCurrencyInfo{
|
||||
CurrencyName: currency.NewCode(currencies[i].Currency),
|
||||
Hold: hold,
|
||||
TotalValue: totalValue,
|
||||
})
|
||||
}
|
||||
|
||||
resp.Accounts = append(resp.Accounts, currencyAccount)
|
||||
@@ -161,9 +175,9 @@ func (o *OKGroup) GetFundingHistory() (resp []exchange.FundHistory, err error) {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
for _, deposit := range accountDepositHistory {
|
||||
for x := range accountDepositHistory {
|
||||
orderStatus := ""
|
||||
switch deposit.Status {
|
||||
switch accountDepositHistory[x].Status {
|
||||
case 0:
|
||||
orderStatus = "waiting"
|
||||
case 1:
|
||||
@@ -173,12 +187,12 @@ func (o *OKGroup) GetFundingHistory() (resp []exchange.FundHistory, err error) {
|
||||
}
|
||||
|
||||
resp = append(resp, exchange.FundHistory{
|
||||
Amount: deposit.Amount,
|
||||
Currency: deposit.Currency,
|
||||
Amount: accountDepositHistory[x].Amount,
|
||||
Currency: accountDepositHistory[x].Currency,
|
||||
ExchangeName: o.Name,
|
||||
Status: orderStatus,
|
||||
Timestamp: deposit.Timestamp,
|
||||
TransferID: deposit.TransactionID,
|
||||
Timestamp: accountDepositHistory[x].Timestamp,
|
||||
TransferID: accountDepositHistory[x].TransactionID,
|
||||
TransferType: "deposit",
|
||||
})
|
||||
}
|
||||
@@ -203,25 +217,21 @@ func (o *OKGroup) GetExchangeHistory(p currency.Pair, assetType asset.Item) ([]e
|
||||
}
|
||||
|
||||
// SubmitOrder submits a new order
|
||||
func (o *OKGroup) SubmitOrder(order *exchange.OrderSubmission) (resp exchange.SubmitOrderResponse, err error) {
|
||||
if order == nil {
|
||||
return resp, exchange.ErrOrderSubmissionIsNil
|
||||
}
|
||||
|
||||
err = order.Validate()
|
||||
func (o *OKGroup) SubmitOrder(s *order.Submit) (resp order.SubmitResponse, err error) {
|
||||
err = s.Validate()
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
|
||||
request := PlaceSpotOrderRequest{
|
||||
ClientOID: order.ClientID,
|
||||
InstrumentID: o.FormatExchangeCurrency(order.Pair, asset.Spot).String(),
|
||||
Side: strings.ToLower(order.OrderSide.ToString()),
|
||||
Type: strings.ToLower(order.OrderType.ToString()),
|
||||
Size: strconv.FormatFloat(order.Amount, 'f', -1, 64),
|
||||
ClientOID: s.ClientID,
|
||||
InstrumentID: o.FormatExchangeCurrency(s.Pair, asset.Spot).String(),
|
||||
Side: strings.ToLower(s.OrderSide.String()),
|
||||
Type: strings.ToLower(s.OrderType.String()),
|
||||
Size: strconv.FormatFloat(s.Amount, 'f', -1, 64),
|
||||
}
|
||||
if order.OrderType == exchange.LimitOrderType {
|
||||
request.Price = strconv.FormatFloat(order.Price, 'f', -1, 64)
|
||||
if s.OrderType == order.Limit {
|
||||
request.Price = strconv.FormatFloat(s.Price, 'f', -1, 64)
|
||||
}
|
||||
|
||||
orderResponse, err := o.PlaceSpotOrder(&request)
|
||||
@@ -236,12 +246,12 @@ func (o *OKGroup) SubmitOrder(order *exchange.OrderSubmission) (resp exchange.Su
|
||||
|
||||
// ModifyOrder will allow of changing orderbook placement and limit to
|
||||
// market conversion
|
||||
func (o *OKGroup) ModifyOrder(action *exchange.ModifyOrder) (string, error) {
|
||||
func (o *OKGroup) ModifyOrder(action *order.Modify) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// CancelOrder cancels an order by its corresponding ID number
|
||||
func (o *OKGroup) CancelOrder(orderCancellation *exchange.OrderCancellation) (err error) {
|
||||
func (o *OKGroup) CancelOrder(orderCancellation *order.Cancel) (err error) {
|
||||
orderID, err := strconv.ParseInt(orderCancellation.OrderID, 10, 64)
|
||||
if err != nil {
|
||||
return
|
||||
@@ -252,21 +262,22 @@ func (o *OKGroup) CancelOrder(orderCancellation *exchange.OrderCancellation) (er
|
||||
OrderID: orderID,
|
||||
})
|
||||
if !orderCancellationResponse.Result {
|
||||
err = fmt.Errorf("order %v failed to be cancelled", orderCancellationResponse.OrderID)
|
||||
err = fmt.Errorf("order %d failed to be cancelled",
|
||||
orderCancellationResponse.OrderID)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// CancelAllOrders cancels all orders associated with a currency pair
|
||||
func (o *OKGroup) CancelAllOrders(orderCancellation *exchange.OrderCancellation) (resp exchange.CancelAllOrdersResponse, err error) {
|
||||
func (o *OKGroup) CancelAllOrders(orderCancellation *order.Cancel) (resp order.CancelAllResponse, err error) {
|
||||
orderIDs := strings.Split(orderCancellation.OrderID, ",")
|
||||
resp.OrderStatus = make(map[string]string)
|
||||
resp.Status = make(map[string]string)
|
||||
var orderIDNumbers []int64
|
||||
for _, i := range orderIDs {
|
||||
orderIDNumber, strConvErr := strconv.ParseInt(i, 10, 64)
|
||||
for i := range orderIDs {
|
||||
orderIDNumber, strConvErr := strconv.ParseInt(orderIDs[i], 10, 64)
|
||||
if strConvErr != nil {
|
||||
resp.OrderStatus[i] = strConvErr.Error()
|
||||
resp.Status[orderIDs[i]] = strConvErr.Error()
|
||||
continue
|
||||
}
|
||||
orderIDNumbers = append(orderIDNumbers, orderIDNumber)
|
||||
@@ -281,9 +292,9 @@ func (o *OKGroup) CancelAllOrders(orderCancellation *exchange.OrderCancellation)
|
||||
return
|
||||
}
|
||||
|
||||
for _, orderMap := range cancelOrdersResponse {
|
||||
for _, cancelledOrder := range orderMap {
|
||||
resp.OrderStatus[fmt.Sprintf("%v", cancelledOrder.OrderID)] = fmt.Sprintf("%v", cancelledOrder.Result)
|
||||
for x := range cancelOrdersResponse {
|
||||
for y := range cancelOrdersResponse[x] {
|
||||
resp.Status[strconv.FormatInt(cancelOrdersResponse[x][y].OrderID, 10)] = strconv.FormatBool(cancelOrdersResponse[x][y].Result)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -291,29 +302,29 @@ func (o *OKGroup) CancelAllOrders(orderCancellation *exchange.OrderCancellation)
|
||||
}
|
||||
|
||||
// GetOrderInfo returns information on a current open order
|
||||
func (o *OKGroup) GetOrderInfo(orderID string) (resp exchange.OrderDetail, err error) {
|
||||
order, err := o.GetSpotOrder(GetSpotOrderRequest{OrderID: orderID})
|
||||
func (o *OKGroup) GetOrderInfo(orderID string) (resp order.Detail, err error) {
|
||||
mOrder, err := o.GetSpotOrder(GetSpotOrderRequest{OrderID: orderID})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
resp = exchange.OrderDetail{
|
||||
Amount: order.Size,
|
||||
CurrencyPair: currency.NewPairDelimiter(order.InstrumentID,
|
||||
resp = order.Detail{
|
||||
Amount: mOrder.Size,
|
||||
CurrencyPair: currency.NewPairDelimiter(mOrder.InstrumentID,
|
||||
o.GetPairFormat(asset.Spot, false).Delimiter),
|
||||
Exchange: o.Name,
|
||||
OrderDate: order.Timestamp,
|
||||
ExecutedAmount: order.FilledSize,
|
||||
Status: order.Status,
|
||||
OrderSide: exchange.OrderSide(order.Side),
|
||||
OrderDate: mOrder.Timestamp,
|
||||
ExecutedAmount: mOrder.FilledSize,
|
||||
Status: order.Status(mOrder.Status),
|
||||
OrderSide: order.Side(mOrder.Side),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// GetDepositAddress returns a deposit address for a specified currency
|
||||
func (o *OKGroup) GetDepositAddress(p currency.Code, accountID string) (_ string, err error) {
|
||||
func (o *OKGroup) GetDepositAddress(p currency.Code, accountID string) (string, error) {
|
||||
wallet, err := o.GetAccountDepositAddressForCurrency(p.Lower().String())
|
||||
if err != nil || len(wallet) == 0 {
|
||||
return
|
||||
return "", err
|
||||
}
|
||||
return wallet[0].Address, nil
|
||||
}
|
||||
@@ -333,10 +344,13 @@ func (o *OKGroup) WithdrawCryptocurrencyFunds(withdrawRequest *exchange.CryptoWi
|
||||
return "", err
|
||||
}
|
||||
if !withdrawal.Result {
|
||||
return fmt.Sprintf("%v", withdrawal.WithdrawalID), fmt.Errorf("could not withdraw currency %v to %v, no error specified", withdrawRequest.Currency.String(), withdrawRequest.Address)
|
||||
return strconv.FormatInt(withdrawal.WithdrawalID, 10),
|
||||
fmt.Errorf("could not withdraw currency %s to %s, no error specified",
|
||||
withdrawRequest.Currency,
|
||||
withdrawRequest.Address)
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%v", withdrawal.WithdrawalID), nil
|
||||
return strconv.FormatInt(withdrawal.WithdrawalID, 10), nil
|
||||
}
|
||||
|
||||
// WithdrawFiatFunds returns a withdrawal ID when a
|
||||
@@ -352,27 +366,27 @@ func (o *OKGroup) WithdrawFiatFundsToInternationalBank(withdrawRequest *exchange
|
||||
}
|
||||
|
||||
// GetActiveOrders retrieves any orders that are active/open
|
||||
func (o *OKGroup) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) (resp []exchange.OrderDetail, err error) {
|
||||
for _, currency := range getOrdersRequest.Currencies {
|
||||
func (o *OKGroup) GetActiveOrders(req *order.GetOrdersRequest) (resp []order.Detail, err error) {
|
||||
for x := range req.Currencies {
|
||||
spotOpenOrders, err := o.GetSpotOpenOrders(GetSpotOpenOrdersRequest{
|
||||
InstrumentID: o.FormatExchangeCurrency(currency,
|
||||
InstrumentID: o.FormatExchangeCurrency(req.Currencies[x],
|
||||
asset.Spot).String(),
|
||||
})
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
for i := range spotOpenOrders {
|
||||
resp = append(resp, exchange.OrderDetail{
|
||||
resp = append(resp, order.Detail{
|
||||
ID: spotOpenOrders[i].OrderID,
|
||||
Price: spotOpenOrders[i].Price,
|
||||
Amount: spotOpenOrders[i].Size,
|
||||
CurrencyPair: currency,
|
||||
CurrencyPair: req.Currencies[x],
|
||||
Exchange: o.Name,
|
||||
OrderSide: exchange.OrderSide(spotOpenOrders[i].Side),
|
||||
OrderType: exchange.OrderType(spotOpenOrders[i].Type),
|
||||
OrderSide: order.Side(spotOpenOrders[i].Side),
|
||||
OrderType: order.Type(spotOpenOrders[i].Type),
|
||||
ExecutedAmount: spotOpenOrders[i].FilledSize,
|
||||
OrderDate: spotOpenOrders[i].Timestamp,
|
||||
Status: spotOpenOrders[i].Status,
|
||||
Status: order.Status(spotOpenOrders[i].Status),
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -382,28 +396,28 @@ func (o *OKGroup) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) (
|
||||
|
||||
// GetOrderHistory retrieves account order information
|
||||
// Can Limit response to specific order status
|
||||
func (o *OKGroup) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) (resp []exchange.OrderDetail, err error) {
|
||||
for _, currency := range getOrdersRequest.Currencies {
|
||||
func (o *OKGroup) GetOrderHistory(req *order.GetOrdersRequest) (resp []order.Detail, err error) {
|
||||
for x := range req.Currencies {
|
||||
spotOpenOrders, err := o.GetSpotOrders(GetSpotOrdersRequest{
|
||||
Status: strings.Join([]string{"filled", "cancelled", "failure"}, "|"),
|
||||
InstrumentID: o.FormatExchangeCurrency(currency,
|
||||
InstrumentID: o.FormatExchangeCurrency(req.Currencies[x],
|
||||
asset.Spot).String(),
|
||||
})
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
for i := range spotOpenOrders {
|
||||
resp = append(resp, exchange.OrderDetail{
|
||||
resp = append(resp, order.Detail{
|
||||
ID: spotOpenOrders[i].OrderID,
|
||||
Price: spotOpenOrders[i].Price,
|
||||
Amount: spotOpenOrders[i].Size,
|
||||
CurrencyPair: currency,
|
||||
CurrencyPair: req.Currencies[x],
|
||||
Exchange: o.Name,
|
||||
OrderSide: exchange.OrderSide(spotOpenOrders[i].Side),
|
||||
OrderType: exchange.OrderType(spotOpenOrders[i].Type),
|
||||
OrderSide: order.Side(spotOpenOrders[i].Side),
|
||||
OrderType: order.Type(spotOpenOrders[i].Type),
|
||||
ExecutedAmount: spotOpenOrders[i].FilledSize,
|
||||
OrderDate: spotOpenOrders[i].Timestamp,
|
||||
Status: spotOpenOrders[i].Status,
|
||||
Status: order.Status(spotOpenOrders[i].Status),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
400
exchanges/order/order_test.go
Normal file
400
exchanges/order/order_test.go
Normal file
@@ -0,0 +1,400 @@
|
||||
package order
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
)
|
||||
|
||||
func TestValidate(t *testing.T) {
|
||||
testPair := currency.NewPair(currency.BTC, currency.LTC)
|
||||
tester := []struct {
|
||||
Pair currency.Pair
|
||||
Side
|
||||
Type
|
||||
Amount float64
|
||||
Price float64
|
||||
ExpectedErr error
|
||||
}{
|
||||
{
|
||||
ExpectedErr: ErrPairIsEmpty,
|
||||
}, // empty pair
|
||||
{
|
||||
Pair: testPair,
|
||||
ExpectedErr: ErrSideIsInvalid,
|
||||
}, // valid pair but invalid order side
|
||||
{
|
||||
Pair: testPair,
|
||||
Side: Buy,
|
||||
ExpectedErr: ErrTypeIsInvalid,
|
||||
}, // valid pair and order side but invalid order type
|
||||
{
|
||||
Pair: testPair,
|
||||
Side: Sell,
|
||||
ExpectedErr: ErrTypeIsInvalid,
|
||||
}, // valid pair and order side but invalid order type
|
||||
{
|
||||
Pair: testPair,
|
||||
Side: Bid,
|
||||
ExpectedErr: ErrTypeIsInvalid,
|
||||
}, // valid pair and order side but invalid order type
|
||||
{
|
||||
Pair: testPair,
|
||||
Side: Ask,
|
||||
ExpectedErr: ErrTypeIsInvalid,
|
||||
}, // valid pair and order side but invalid order type
|
||||
{
|
||||
Pair: testPair,
|
||||
Side: Ask,
|
||||
Type: Market,
|
||||
ExpectedErr: ErrAmountIsInvalid,
|
||||
}, // valid pair, order side, type but invalid amount
|
||||
{
|
||||
Pair: testPair,
|
||||
Side: Ask,
|
||||
Type: Limit,
|
||||
Amount: 1,
|
||||
ExpectedErr: ErrPriceMustBeSetIfLimitOrder,
|
||||
}, // valid pair, order side, type, amount but invalid price
|
||||
{
|
||||
Pair: testPair,
|
||||
Side: Ask,
|
||||
Type: Limit,
|
||||
Amount: 1,
|
||||
Price: 1000,
|
||||
ExpectedErr: nil,
|
||||
}, // valid order!
|
||||
}
|
||||
|
||||
for x := range tester {
|
||||
s := Submit{
|
||||
Pair: tester[x].Pair,
|
||||
OrderSide: tester[x].Side,
|
||||
OrderType: tester[x].Type,
|
||||
Amount: tester[x].Amount,
|
||||
Price: tester[x].Price,
|
||||
}
|
||||
if err := s.Validate(); err != tester[x].ExpectedErr {
|
||||
t.Errorf("Unexpected result. Got: %s, want: %s", err, tester[x].ExpectedErr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestOrderSides(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var os = Buy
|
||||
if os.String() != "BUY" {
|
||||
t.Errorf("unexpected string %s", os.String())
|
||||
}
|
||||
|
||||
if os.Lower() != "buy" {
|
||||
t.Errorf("unexpected string %s", os.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestOrderTypes(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var ot Type = "Mo'Money"
|
||||
|
||||
if ot.String() != "Mo'Money" {
|
||||
t.Errorf("unexpected string %s", ot.String())
|
||||
}
|
||||
|
||||
if ot.Lower() != "mo'money" {
|
||||
t.Errorf("unexpected string %s", ot.Lower())
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterOrdersByType(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var orders = []Detail{
|
||||
{
|
||||
OrderType: ImmediateOrCancel,
|
||||
},
|
||||
{
|
||||
OrderType: Limit,
|
||||
},
|
||||
}
|
||||
|
||||
FilterOrdersByType(&orders, AnyType)
|
||||
if len(orders) != 2 {
|
||||
t.Errorf("Orders failed to be filtered. Expected %v, received %v", 2, len(orders))
|
||||
}
|
||||
|
||||
FilterOrdersByType(&orders, Limit)
|
||||
if len(orders) != 1 {
|
||||
t.Errorf("Orders failed to be filtered. Expected %v, received %v", 1, len(orders))
|
||||
}
|
||||
|
||||
FilterOrdersByType(&orders, Stop)
|
||||
if len(orders) != 0 {
|
||||
t.Errorf("Orders failed to be filtered. Expected %v, received %v", 0, len(orders))
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterOrdersBySide(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var orders = []Detail{
|
||||
{
|
||||
OrderSide: Buy,
|
||||
},
|
||||
{
|
||||
OrderSide: Sell,
|
||||
},
|
||||
{},
|
||||
}
|
||||
|
||||
FilterOrdersBySide(&orders, AnySide)
|
||||
if len(orders) != 3 {
|
||||
t.Errorf("Orders failed to be filtered. Expected %v, received %v", 3, len(orders))
|
||||
}
|
||||
|
||||
FilterOrdersBySide(&orders, Buy)
|
||||
if len(orders) != 1 {
|
||||
t.Errorf("Orders failed to be filtered. Expected %v, received %v", 1, len(orders))
|
||||
}
|
||||
|
||||
FilterOrdersBySide(&orders, Sell)
|
||||
if len(orders) != 0 {
|
||||
t.Errorf("Orders failed to be filtered. Expected %v, received %v", 0, len(orders))
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterOrdersByTickRange(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var orders = []Detail{
|
||||
{
|
||||
OrderDate: time.Unix(100, 0),
|
||||
},
|
||||
{
|
||||
OrderDate: time.Unix(110, 0),
|
||||
},
|
||||
{
|
||||
OrderDate: time.Unix(111, 0),
|
||||
},
|
||||
}
|
||||
|
||||
FilterOrdersByTickRange(&orders, time.Unix(0, 0), time.Unix(0, 0))
|
||||
if len(orders) != 3 {
|
||||
t.Errorf("Orders failed to be filtered. Expected %v, received %v", 3, len(orders))
|
||||
}
|
||||
|
||||
FilterOrdersByTickRange(&orders, time.Unix(100, 0), time.Unix(111, 0))
|
||||
if len(orders) != 3 {
|
||||
t.Errorf("Orders failed to be filtered. Expected %v, received %v", 3, len(orders))
|
||||
}
|
||||
|
||||
FilterOrdersByTickRange(&orders, time.Unix(101, 0), time.Unix(111, 0))
|
||||
if len(orders) != 2 {
|
||||
t.Errorf("Orders failed to be filtered. Expected %v, received %v", 2, len(orders))
|
||||
}
|
||||
|
||||
FilterOrdersByTickRange(&orders, time.Unix(200, 0), time.Unix(300, 0))
|
||||
if len(orders) != 0 {
|
||||
t.Errorf("Orders failed to be filtered. Expected %v, received %v", 0, len(orders))
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterOrdersByCurrencies(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var orders = []Detail{
|
||||
{
|
||||
CurrencyPair: currency.NewPair(currency.BTC, currency.USD),
|
||||
},
|
||||
{
|
||||
CurrencyPair: currency.NewPair(currency.LTC, currency.EUR),
|
||||
},
|
||||
{
|
||||
CurrencyPair: currency.NewPair(currency.DOGE, currency.RUB),
|
||||
},
|
||||
}
|
||||
|
||||
currencies := []currency.Pair{currency.NewPair(currency.BTC, currency.USD),
|
||||
currency.NewPair(currency.LTC, currency.EUR),
|
||||
currency.NewPair(currency.DOGE, currency.RUB)}
|
||||
FilterOrdersByCurrencies(&orders, currencies)
|
||||
if len(orders) != 3 {
|
||||
t.Errorf("Orders failed to be filtered. Expected %v, received %v", 3, len(orders))
|
||||
}
|
||||
|
||||
currencies = []currency.Pair{currency.NewPair(currency.BTC, currency.USD),
|
||||
currency.NewPair(currency.LTC, currency.EUR)}
|
||||
FilterOrdersByCurrencies(&orders, currencies)
|
||||
if len(orders) != 2 {
|
||||
t.Errorf("Orders failed to be filtered. Expected %v, received %v", 2, len(orders))
|
||||
}
|
||||
|
||||
currencies = []currency.Pair{currency.NewPair(currency.BTC, currency.USD)}
|
||||
FilterOrdersByCurrencies(&orders, currencies)
|
||||
if len(orders) != 1 {
|
||||
t.Errorf("Orders failed to be filtered. Expected %v, received %v", 1, len(orders))
|
||||
}
|
||||
|
||||
currencies = []currency.Pair{}
|
||||
FilterOrdersByCurrencies(&orders, currencies)
|
||||
if len(orders) != 1 {
|
||||
t.Errorf("Orders failed to be filtered. Expected %v, received %v", 1, len(orders))
|
||||
}
|
||||
}
|
||||
|
||||
func TestSortOrdersByPrice(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
orders := []Detail{
|
||||
{
|
||||
Price: 100,
|
||||
}, {
|
||||
Price: 0,
|
||||
}, {
|
||||
Price: 50,
|
||||
},
|
||||
}
|
||||
|
||||
SortOrdersByPrice(&orders, false)
|
||||
if orders[0].Price != 0 {
|
||||
t.Errorf("Expected: '%v', received: '%v'", 0, orders[0].Price)
|
||||
}
|
||||
|
||||
SortOrdersByPrice(&orders, true)
|
||||
if orders[0].Price != 100 {
|
||||
t.Errorf("Expected: '%v', received: '%v'", 100, orders[0].Price)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSortOrdersByDate(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
orders := []Detail{
|
||||
{
|
||||
OrderDate: time.Unix(0, 0),
|
||||
}, {
|
||||
OrderDate: time.Unix(1, 0),
|
||||
}, {
|
||||
OrderDate: time.Unix(2, 0),
|
||||
},
|
||||
}
|
||||
|
||||
SortOrdersByDate(&orders, false)
|
||||
if orders[0].OrderDate.Unix() != time.Unix(0, 0).Unix() {
|
||||
t.Errorf("Expected: '%v', received: '%v'",
|
||||
time.Unix(0, 0).Unix(),
|
||||
orders[0].OrderDate.Unix())
|
||||
}
|
||||
|
||||
SortOrdersByDate(&orders, true)
|
||||
if orders[0].OrderDate.Unix() != time.Unix(2, 0).Unix() {
|
||||
t.Errorf("Expected: '%v', received: '%v'",
|
||||
time.Unix(2, 0).Unix(),
|
||||
orders[0].OrderDate.Unix())
|
||||
}
|
||||
}
|
||||
|
||||
func TestSortOrdersByCurrency(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
orders := []Detail{
|
||||
{
|
||||
CurrencyPair: currency.NewPairWithDelimiter(currency.BTC.String(),
|
||||
currency.USD.String(),
|
||||
"-"),
|
||||
}, {
|
||||
CurrencyPair: currency.NewPairWithDelimiter(currency.DOGE.String(),
|
||||
currency.USD.String(),
|
||||
"-"),
|
||||
}, {
|
||||
CurrencyPair: currency.NewPairWithDelimiter(currency.BTC.String(),
|
||||
currency.RUB.String(),
|
||||
"-"),
|
||||
}, {
|
||||
CurrencyPair: currency.NewPairWithDelimiter(currency.LTC.String(),
|
||||
currency.EUR.String(),
|
||||
"-"),
|
||||
}, {
|
||||
CurrencyPair: currency.NewPairWithDelimiter(currency.LTC.String(),
|
||||
currency.AUD.String(),
|
||||
"-"),
|
||||
},
|
||||
}
|
||||
|
||||
SortOrdersByCurrency(&orders, false)
|
||||
if orders[0].CurrencyPair.String() != currency.BTC.String()+"-"+currency.RUB.String() {
|
||||
t.Errorf("Expected: '%v', received: '%v'",
|
||||
currency.BTC.String()+"-"+currency.RUB.String(),
|
||||
orders[0].CurrencyPair.String())
|
||||
}
|
||||
|
||||
SortOrdersByCurrency(&orders, true)
|
||||
if orders[0].CurrencyPair.String() != currency.LTC.String()+"-"+currency.EUR.String() {
|
||||
t.Errorf("Expected: '%v', received: '%v'",
|
||||
currency.LTC.String()+"-"+currency.EUR.String(),
|
||||
orders[0].CurrencyPair.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestSortOrdersByOrderSide(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
orders := []Detail{
|
||||
{
|
||||
OrderSide: Buy,
|
||||
}, {
|
||||
OrderSide: Sell,
|
||||
}, {
|
||||
OrderSide: Sell,
|
||||
}, {
|
||||
OrderSide: Buy,
|
||||
},
|
||||
}
|
||||
|
||||
SortOrdersBySide(&orders, false)
|
||||
if !strings.EqualFold(orders[0].OrderSide.String(), Buy.String()) {
|
||||
t.Errorf("Expected: '%v', received: '%v'",
|
||||
Buy,
|
||||
orders[0].OrderSide)
|
||||
}
|
||||
|
||||
SortOrdersBySide(&orders, true)
|
||||
if !strings.EqualFold(orders[0].OrderSide.String(), Sell.String()) {
|
||||
t.Errorf("Expected: '%v', received: '%v'",
|
||||
Sell,
|
||||
orders[0].OrderSide)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSortOrdersByOrderType(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
orders := []Detail{
|
||||
{
|
||||
OrderType: Market,
|
||||
}, {
|
||||
OrderType: Limit,
|
||||
}, {
|
||||
OrderType: ImmediateOrCancel,
|
||||
}, {
|
||||
OrderType: TrailingStop,
|
||||
},
|
||||
}
|
||||
|
||||
SortOrdersByType(&orders, false)
|
||||
if !strings.EqualFold(orders[0].OrderType.String(), ImmediateOrCancel.String()) {
|
||||
t.Errorf("Expected: '%v', received: '%v'",
|
||||
ImmediateOrCancel,
|
||||
orders[0].OrderType)
|
||||
}
|
||||
|
||||
SortOrdersByType(&orders, true)
|
||||
if !strings.EqualFold(orders[0].OrderType.String(), TrailingStop.String()) {
|
||||
t.Errorf("Expected: '%v', received: '%v'",
|
||||
TrailingStop,
|
||||
orders[0].OrderType)
|
||||
}
|
||||
}
|
||||
190
exchanges/order/order_types.go
Normal file
190
exchanges/order/order_types.go
Normal file
@@ -0,0 +1,190 @@
|
||||
package order
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
)
|
||||
|
||||
const (
|
||||
limitOrder = iota
|
||||
marketOrder
|
||||
)
|
||||
|
||||
// Orders variable holds an array of pointers to order structs
|
||||
var Orders []*Order
|
||||
|
||||
// Order struct holds order values
|
||||
type Order struct {
|
||||
OrderID int
|
||||
Exchange string
|
||||
Type int
|
||||
Amount float64
|
||||
Price float64
|
||||
}
|
||||
|
||||
// vars related to orders
|
||||
var (
|
||||
ErrSubmissionIsNil = errors.New("order submission is nil")
|
||||
ErrPairIsEmpty = errors.New("order pair is empty")
|
||||
ErrSideIsInvalid = errors.New("order side is invalid")
|
||||
ErrTypeIsInvalid = errors.New("order type is invalid")
|
||||
ErrAmountIsInvalid = errors.New("order amount is invalid")
|
||||
ErrPriceMustBeSetIfLimitOrder = errors.New("order price must be set if limit order type is desired")
|
||||
)
|
||||
|
||||
// Submit contains the order submission data
|
||||
type Submit struct {
|
||||
Pair currency.Pair
|
||||
OrderType Type
|
||||
OrderSide Side
|
||||
Price float64
|
||||
Amount float64
|
||||
ClientID string
|
||||
}
|
||||
|
||||
// SubmitResponse is what is returned after submitting an order to an exchange
|
||||
type SubmitResponse struct {
|
||||
IsOrderPlaced bool
|
||||
OrderID string
|
||||
}
|
||||
|
||||
// Modify is an order modifyer
|
||||
type Modify struct {
|
||||
OrderID string
|
||||
Type
|
||||
Side
|
||||
Price float64
|
||||
Amount float64
|
||||
LimitPriceUpper float64
|
||||
LimitPriceLower float64
|
||||
CurrencyPair currency.Pair
|
||||
ImmediateOrCancel bool
|
||||
HiddenOrder bool
|
||||
FillOrKill bool
|
||||
PostOnly bool
|
||||
}
|
||||
|
||||
// ModifyResponse is an order modifying return type
|
||||
type ModifyResponse struct {
|
||||
OrderID string
|
||||
}
|
||||
|
||||
// CancelAllResponse returns the status from attempting to cancel all orders on
|
||||
// an exchagne
|
||||
type CancelAllResponse struct {
|
||||
Status map[string]string
|
||||
}
|
||||
|
||||
// Type enforces a standard for order types across the code base
|
||||
type Type string
|
||||
|
||||
// Defined package order types
|
||||
const (
|
||||
AnyType Type = "ANY"
|
||||
Limit Type = "LIMIT"
|
||||
Market Type = "MARKET"
|
||||
ImmediateOrCancel Type = "IMMEDIATE_OR_CANCEL"
|
||||
Stop Type = "STOP"
|
||||
TrailingStop Type = "TRAILINGSTOP"
|
||||
Unknown Type = "UNKNOWN"
|
||||
)
|
||||
|
||||
// Side enforces a standard for order sides across the code base
|
||||
type Side string
|
||||
|
||||
// Order side types
|
||||
const (
|
||||
AnySide Side = "ANY"
|
||||
Buy Side = "BUY"
|
||||
Sell Side = "SELL"
|
||||
Bid Side = "BID"
|
||||
Ask Side = "ASK"
|
||||
)
|
||||
|
||||
// Detail holds order detail data
|
||||
type Detail struct {
|
||||
Exchange string
|
||||
AccountID string
|
||||
ID string
|
||||
CurrencyPair currency.Pair
|
||||
OrderSide Side
|
||||
OrderType Type
|
||||
OrderDate time.Time
|
||||
Status
|
||||
Price float64
|
||||
Amount float64
|
||||
ExecutedAmount float64
|
||||
RemainingAmount float64
|
||||
Fee float64
|
||||
Trades []TradeHistory
|
||||
}
|
||||
|
||||
// TradeHistory holds exchange history data
|
||||
type TradeHistory struct {
|
||||
Timestamp time.Time
|
||||
TID int64
|
||||
Price float64
|
||||
Amount float64
|
||||
Exchange string
|
||||
Type
|
||||
Side
|
||||
Fee float64
|
||||
Description string
|
||||
}
|
||||
|
||||
// Cancel type required when requesting to cancel an order
|
||||
type Cancel struct {
|
||||
AccountID string
|
||||
OrderID string
|
||||
CurrencyPair currency.Pair
|
||||
AssetType asset.Item
|
||||
WalletAddress string
|
||||
Side
|
||||
}
|
||||
|
||||
// GetOrdersRequest used for GetOrderHistory and GetOpenOrders wrapper functions
|
||||
type GetOrdersRequest struct {
|
||||
OrderType Type
|
||||
OrderSide Side
|
||||
StartTicks time.Time
|
||||
EndTicks time.Time
|
||||
// Currencies Empty array = all currencies. Some endpoints only support
|
||||
// singular currency enquiries
|
||||
Currencies []currency.Pair
|
||||
}
|
||||
|
||||
// Status defines order status types
|
||||
type Status string
|
||||
|
||||
// All order status types
|
||||
const (
|
||||
AnyStatus Status = "ANY"
|
||||
New Status = "NEW"
|
||||
Active Status = "ACTIVE"
|
||||
PartiallyFilled Status = "PARTIALLY_FILLED"
|
||||
Filled Status = "FILLED"
|
||||
Cancelled Status = "CANCELED"
|
||||
PendingCancel Status = "PENDING_CANCEL"
|
||||
Rejected Status = "REJECTED"
|
||||
Expired Status = "EXPIRED"
|
||||
Hidden Status = "HIDDEN"
|
||||
UnknownStatus Status = "UNKNOWN"
|
||||
)
|
||||
|
||||
// ByPrice used for sorting orders by price
|
||||
type ByPrice []Detail
|
||||
|
||||
// ByOrderType used for sorting orders by order type
|
||||
type ByOrderType []Detail
|
||||
|
||||
// ByCurrency used for sorting orders by order currency
|
||||
type ByCurrency []Detail
|
||||
|
||||
// ByDate used for sorting orders by order date
|
||||
type ByDate []Detail
|
||||
|
||||
// ByOrderSide used for sorting orders by order side (buy sell)
|
||||
type ByOrderSide []Detail
|
||||
302
exchanges/order/orders.go
Normal file
302
exchanges/order/orders.go
Normal file
@@ -0,0 +1,302 @@
|
||||
package order
|
||||
|
||||
import (
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
)
|
||||
|
||||
// NewOrder creates a new order and returns a an orderID
|
||||
func NewOrder(exchangeName string, amount, price float64) int {
|
||||
order := &Order{}
|
||||
if len(Orders) == 0 {
|
||||
order.OrderID = 0
|
||||
} else {
|
||||
order.OrderID = len(Orders)
|
||||
}
|
||||
|
||||
order.Exchange = exchangeName
|
||||
order.Amount = amount
|
||||
order.Price = price
|
||||
Orders = append(Orders, order)
|
||||
return order.OrderID
|
||||
}
|
||||
|
||||
// DeleteOrder deletes orders by ID and returns state
|
||||
func DeleteOrder(orderID int) bool {
|
||||
for i := range Orders {
|
||||
if Orders[i].OrderID == orderID {
|
||||
Orders = append(Orders[:i], Orders[i+1:]...)
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// GetOrdersByExchange returns order pointer grouped by exchange
|
||||
func GetOrdersByExchange(exchange string) []*Order {
|
||||
var orders []*Order
|
||||
for i := range Orders {
|
||||
if Orders[i].Exchange == exchange {
|
||||
orders = append(orders, Orders[i])
|
||||
}
|
||||
}
|
||||
if len(orders) > 0 {
|
||||
return orders
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetOrderByOrderID returns order pointer by ID
|
||||
func GetOrderByOrderID(orderID int) *Order {
|
||||
for i := range Orders {
|
||||
if Orders[i].OrderID == orderID {
|
||||
return Orders[i]
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Validate checks the supplied data and returns whether or not it's valid
|
||||
func (s *Submit) Validate() error {
|
||||
if s == nil {
|
||||
return ErrSubmissionIsNil
|
||||
}
|
||||
|
||||
if s.Pair.IsEmpty() {
|
||||
return ErrPairIsEmpty
|
||||
}
|
||||
|
||||
if s.OrderSide != Buy &&
|
||||
s.OrderSide != Sell &&
|
||||
s.OrderSide != Bid &&
|
||||
s.OrderSide != Ask {
|
||||
return ErrSideIsInvalid
|
||||
}
|
||||
|
||||
if s.OrderType != Market && s.OrderType != Limit {
|
||||
return ErrTypeIsInvalid
|
||||
}
|
||||
|
||||
if s.Amount <= 0 {
|
||||
return ErrAmountIsInvalid
|
||||
}
|
||||
|
||||
if s.OrderType == Limit && s.Price <= 0 {
|
||||
return ErrPriceMustBeSetIfLimitOrder
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// String implements the stringer interface
|
||||
func (t Type) String() string {
|
||||
return string(t)
|
||||
}
|
||||
|
||||
// Lower returns the type lower case string
|
||||
func (t Type) Lower() string {
|
||||
return strings.ToLower(string(t))
|
||||
}
|
||||
|
||||
// String implements the stringer interface
|
||||
func (s Side) String() string {
|
||||
return string(s)
|
||||
}
|
||||
|
||||
// Lower returns the side lower case string
|
||||
func (s Side) Lower() string {
|
||||
return strings.ToLower(string(s))
|
||||
}
|
||||
|
||||
// String implements the stringer interface
|
||||
func (s Status) String() string {
|
||||
return string(s)
|
||||
}
|
||||
|
||||
// FilterOrdersBySide removes any order details that don't match the
|
||||
// order status provided
|
||||
func FilterOrdersBySide(orders *[]Detail, side Side) {
|
||||
if side == "" || side == AnySide {
|
||||
return
|
||||
}
|
||||
|
||||
var filteredOrders []Detail
|
||||
for i := range *orders {
|
||||
if strings.EqualFold(string((*orders)[i].OrderSide), string(side)) {
|
||||
filteredOrders = append(filteredOrders, (*orders)[i])
|
||||
}
|
||||
}
|
||||
|
||||
*orders = filteredOrders
|
||||
}
|
||||
|
||||
// FilterOrdersByType removes any order details that don't match the order type
|
||||
// provided
|
||||
func FilterOrdersByType(orders *[]Detail, orderType Type) {
|
||||
if orderType == "" || orderType == AnyType {
|
||||
return
|
||||
}
|
||||
|
||||
var filteredOrders []Detail
|
||||
for i := range *orders {
|
||||
if strings.EqualFold(string((*orders)[i].OrderType), string(orderType)) {
|
||||
filteredOrders = append(filteredOrders, (*orders)[i])
|
||||
}
|
||||
}
|
||||
|
||||
*orders = filteredOrders
|
||||
}
|
||||
|
||||
// FilterOrdersByTickRange removes any OrderDetails outside of the tick range
|
||||
func FilterOrdersByTickRange(orders *[]Detail, startTicks, endTicks time.Time) {
|
||||
if startTicks.IsZero() ||
|
||||
endTicks.IsZero() ||
|
||||
startTicks.Unix() == 0 ||
|
||||
endTicks.Unix() == 0 ||
|
||||
endTicks.Before(startTicks) {
|
||||
return
|
||||
}
|
||||
|
||||
var filteredOrders []Detail
|
||||
for i := range *orders {
|
||||
if (*orders)[i].OrderDate.Unix() >= startTicks.Unix() &&
|
||||
(*orders)[i].OrderDate.Unix() <= endTicks.Unix() {
|
||||
filteredOrders = append(filteredOrders, (*orders)[i])
|
||||
}
|
||||
}
|
||||
|
||||
*orders = filteredOrders
|
||||
}
|
||||
|
||||
// FilterOrdersByCurrencies removes any order details that do not match the
|
||||
// provided currency list. It is forgiving in that the provided currencies can
|
||||
// match quote or base currencies
|
||||
func FilterOrdersByCurrencies(orders *[]Detail, currencies []currency.Pair) {
|
||||
if len(currencies) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
var filteredOrders []Detail
|
||||
for i := range *orders {
|
||||
matchFound := false
|
||||
for _, c := range currencies {
|
||||
if !matchFound && (*orders)[i].CurrencyPair.EqualIncludeReciprocal(c) {
|
||||
matchFound = true
|
||||
}
|
||||
}
|
||||
|
||||
if matchFound {
|
||||
filteredOrders = append(filteredOrders, (*orders)[i])
|
||||
}
|
||||
}
|
||||
|
||||
*orders = filteredOrders
|
||||
}
|
||||
|
||||
func (b ByPrice) Len() int {
|
||||
return len(b)
|
||||
}
|
||||
|
||||
func (b ByPrice) Less(i, j int) bool {
|
||||
return b[i].Price < b[j].Price
|
||||
}
|
||||
|
||||
func (b ByPrice) Swap(i, j int) {
|
||||
b[i], b[j] = b[j], b[i]
|
||||
}
|
||||
|
||||
// SortOrdersByPrice the caller function to sort orders
|
||||
func SortOrdersByPrice(orders *[]Detail, reverse bool) {
|
||||
if reverse {
|
||||
sort.Sort(sort.Reverse(ByPrice(*orders)))
|
||||
} else {
|
||||
sort.Sort(ByPrice(*orders))
|
||||
}
|
||||
}
|
||||
|
||||
func (b ByOrderType) Len() int {
|
||||
return len(b)
|
||||
}
|
||||
|
||||
func (b ByOrderType) Less(i, j int) bool {
|
||||
return b[i].OrderType.String() < b[j].OrderType.String()
|
||||
}
|
||||
|
||||
func (b ByOrderType) Swap(i, j int) {
|
||||
b[i], b[j] = b[j], b[i]
|
||||
}
|
||||
|
||||
// SortOrdersByType the caller function to sort orders
|
||||
func SortOrdersByType(orders *[]Detail, reverse bool) {
|
||||
if reverse {
|
||||
sort.Sort(sort.Reverse(ByOrderType(*orders)))
|
||||
} else {
|
||||
sort.Sort(ByOrderType(*orders))
|
||||
}
|
||||
}
|
||||
|
||||
func (b ByCurrency) Len() int {
|
||||
return len(b)
|
||||
}
|
||||
|
||||
func (b ByCurrency) Less(i, j int) bool {
|
||||
return b[i].CurrencyPair.String() < b[j].CurrencyPair.String()
|
||||
}
|
||||
|
||||
func (b ByCurrency) Swap(i, j int) {
|
||||
b[i], b[j] = b[j], b[i]
|
||||
}
|
||||
|
||||
// SortOrdersByCurrency the caller function to sort orders
|
||||
func SortOrdersByCurrency(orders *[]Detail, reverse bool) {
|
||||
if reverse {
|
||||
sort.Sort(sort.Reverse(ByCurrency(*orders)))
|
||||
} else {
|
||||
sort.Sort(ByCurrency(*orders))
|
||||
}
|
||||
}
|
||||
|
||||
func (b ByDate) Len() int {
|
||||
return len(b)
|
||||
}
|
||||
|
||||
func (b ByDate) Less(i, j int) bool {
|
||||
return b[i].OrderDate.Unix() < b[j].OrderDate.Unix()
|
||||
}
|
||||
|
||||
func (b ByDate) Swap(i, j int) {
|
||||
b[i], b[j] = b[j], b[i]
|
||||
}
|
||||
|
||||
// SortOrdersByDate the caller function to sort orders
|
||||
func SortOrdersByDate(orders *[]Detail, reverse bool) {
|
||||
if reverse {
|
||||
sort.Sort(sort.Reverse(ByDate(*orders)))
|
||||
} else {
|
||||
sort.Sort(ByDate(*orders))
|
||||
}
|
||||
}
|
||||
|
||||
func (b ByOrderSide) Len() int {
|
||||
return len(b)
|
||||
}
|
||||
|
||||
func (b ByOrderSide) Less(i, j int) bool {
|
||||
return b[i].OrderSide.String() < b[j].OrderSide.String()
|
||||
}
|
||||
|
||||
func (b ByOrderSide) Swap(i, j int) {
|
||||
b[i], b[j] = b[j], b[i]
|
||||
}
|
||||
|
||||
// SortOrdersBySide the caller function to sort orders
|
||||
func SortOrdersBySide(orders *[]Detail, reverse bool) {
|
||||
if reverse {
|
||||
sort.Sort(sort.Reverse(ByOrderSide(*orders)))
|
||||
} else {
|
||||
sort.Sort(ByOrderSide(*orders))
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package orders
|
||||
package order
|
||||
|
||||
import (
|
||||
"testing"
|
||||
@@ -1,81 +0,0 @@
|
||||
package exchange
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
)
|
||||
|
||||
func TestValidate(t *testing.T) {
|
||||
testPair := currency.NewPair(currency.BTC, currency.LTC)
|
||||
tester := []struct {
|
||||
Pair currency.Pair
|
||||
Side OrderSide
|
||||
Type OrderType
|
||||
Amount float64
|
||||
Price float64
|
||||
ExpectedErr error
|
||||
}{
|
||||
{
|
||||
ExpectedErr: ErrOrderPairIsEmpty,
|
||||
}, // empty pair
|
||||
{
|
||||
Pair: testPair,
|
||||
ExpectedErr: ErrOrderSideIsInvalid,
|
||||
}, // valid pair but invalid order side
|
||||
{
|
||||
Pair: testPair,
|
||||
Side: BuyOrderSide,
|
||||
ExpectedErr: ErrOrderTypeIsInvalid,
|
||||
}, // valid pair and order side but invalid order type
|
||||
{
|
||||
Pair: testPair,
|
||||
Side: SellOrderSide,
|
||||
ExpectedErr: ErrOrderTypeIsInvalid,
|
||||
}, // valid pair and order side but invalid order type
|
||||
{
|
||||
Pair: testPair,
|
||||
Side: BidOrderSide,
|
||||
ExpectedErr: ErrOrderTypeIsInvalid,
|
||||
}, // valid pair and order side but invalid order type
|
||||
{
|
||||
Pair: testPair,
|
||||
Side: AskOrderSide,
|
||||
ExpectedErr: ErrOrderTypeIsInvalid,
|
||||
}, // valid pair and order side but invalid order type
|
||||
{
|
||||
Pair: testPair,
|
||||
Side: AskOrderSide,
|
||||
Type: MarketOrderType,
|
||||
ExpectedErr: ErrOrderAmountIsInvalid,
|
||||
}, // valid pair, order side, type but invalid amount
|
||||
{
|
||||
Pair: testPair,
|
||||
Side: AskOrderSide,
|
||||
Type: LimitOrderType,
|
||||
Amount: 1,
|
||||
ExpectedErr: ErrOrderPriceMustBeSetIfLimitOrder,
|
||||
}, // valid pair, order side, type, amount but invalid price
|
||||
{
|
||||
Pair: testPair,
|
||||
Side: AskOrderSide,
|
||||
Type: LimitOrderType,
|
||||
Amount: 1,
|
||||
Price: 1000,
|
||||
ExpectedErr: nil,
|
||||
}, // valid order!
|
||||
}
|
||||
|
||||
for x := range tester {
|
||||
s := OrderSubmission{
|
||||
Pair: tester[x].Pair,
|
||||
OrderSide: tester[x].Side,
|
||||
OrderType: tester[x].Type,
|
||||
Amount: tester[x].Amount,
|
||||
Price: tester[x].Price,
|
||||
}
|
||||
if err := s.Validate(); err != tester[x].ExpectedErr {
|
||||
t.Errorf("Unexpected result. Got: %s, want: %s", err, tester[x].ExpectedErr)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,387 +0,0 @@
|
||||
package exchange
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
)
|
||||
|
||||
// vars related to orders
|
||||
var (
|
||||
ErrOrderSubmissionIsNil = errors.New("order submission is nil")
|
||||
ErrOrderPairIsEmpty = errors.New("order pair is empty")
|
||||
ErrOrderSideIsInvalid = errors.New("order side is invalid")
|
||||
ErrOrderTypeIsInvalid = errors.New("order type is invalid")
|
||||
ErrOrderAmountIsInvalid = errors.New("order amount is invalid")
|
||||
ErrOrderPriceMustBeSetIfLimitOrder = errors.New("order price must be set if limit order type is desired")
|
||||
)
|
||||
|
||||
// OrderSubmission contains the order submission data
|
||||
type OrderSubmission struct {
|
||||
Pair currency.Pair
|
||||
OrderSide OrderSide
|
||||
OrderType OrderType
|
||||
Price float64
|
||||
Amount float64
|
||||
ClientID string
|
||||
}
|
||||
|
||||
// Validate checks the supplied data and returns whether or not its valid
|
||||
func (o *OrderSubmission) Validate() error {
|
||||
if o.Pair.IsEmpty() {
|
||||
return ErrOrderPairIsEmpty
|
||||
}
|
||||
|
||||
o.OrderSide = OrderSide(strings.ToUpper(o.OrderSide.ToString()))
|
||||
if o.OrderSide != BuyOrderSide && o.OrderSide != SellOrderSide &&
|
||||
o.OrderSide != BidOrderSide && o.OrderSide != AskOrderSide {
|
||||
return ErrOrderSideIsInvalid
|
||||
}
|
||||
|
||||
o.OrderType = OrderType(strings.ToUpper(o.OrderType.ToString()))
|
||||
if o.OrderType != MarketOrderType && o.OrderType != LimitOrderType {
|
||||
return ErrOrderTypeIsInvalid
|
||||
}
|
||||
|
||||
if o.Amount <= 0 {
|
||||
return ErrOrderAmountIsInvalid
|
||||
}
|
||||
|
||||
if o.OrderType == LimitOrderType && o.Price <= 0 {
|
||||
return ErrOrderPriceMustBeSetIfLimitOrder
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SubmitOrderResponse is what is returned after submitting an order to an exchange
|
||||
type SubmitOrderResponse struct {
|
||||
IsOrderPlaced bool
|
||||
OrderID string
|
||||
}
|
||||
|
||||
// ModifyOrder is a an order modifyer
|
||||
type ModifyOrder struct {
|
||||
OrderID string
|
||||
OrderType
|
||||
OrderSide
|
||||
Price float64
|
||||
Amount float64
|
||||
LimitPriceUpper float64
|
||||
LimitPriceLower float64
|
||||
CurrencyPair currency.Pair
|
||||
ImmediateOrCancel bool
|
||||
HiddenOrder bool
|
||||
FillOrKill bool
|
||||
PostOnly bool
|
||||
}
|
||||
|
||||
// ModifyOrderResponse is an order modifying return type
|
||||
type ModifyOrderResponse struct {
|
||||
OrderID string
|
||||
}
|
||||
|
||||
// CancelAllOrdersResponse returns the status from attempting to cancel all orders on an exchagne
|
||||
type CancelAllOrdersResponse struct {
|
||||
OrderStatus map[string]string
|
||||
}
|
||||
|
||||
// OrderType enforces a standard for Ordertypes across the code base
|
||||
type OrderType string
|
||||
|
||||
// OrderType ...types
|
||||
const (
|
||||
AnyOrderType OrderType = "ANY"
|
||||
LimitOrderType OrderType = "LIMIT"
|
||||
MarketOrderType OrderType = "MARKET"
|
||||
ImmediateOrCancelOrderType OrderType = "IMMEDIATE_OR_CANCEL"
|
||||
StopOrderType OrderType = "STOP"
|
||||
TrailingStopOrderType OrderType = "TRAILINGSTOP"
|
||||
UnknownOrderType OrderType = "UNKNOWN"
|
||||
)
|
||||
|
||||
// ToLower changes the ordertype to lower case
|
||||
func (o OrderType) ToLower() OrderType {
|
||||
return OrderType(strings.ToLower(string(o)))
|
||||
}
|
||||
|
||||
// ToString changes the ordertype to the exchange standard and returns a string
|
||||
func (o OrderType) ToString() string {
|
||||
return fmt.Sprintf("%v", o)
|
||||
}
|
||||
|
||||
// OrderSide enforces a standard for OrderSides across the code base
|
||||
type OrderSide string
|
||||
|
||||
// OrderSide types
|
||||
const (
|
||||
AnyOrderSide OrderSide = "ANY"
|
||||
BuyOrderSide OrderSide = "BUY"
|
||||
SellOrderSide OrderSide = "SELL"
|
||||
BidOrderSide OrderSide = "BID"
|
||||
AskOrderSide OrderSide = "ASK"
|
||||
)
|
||||
|
||||
// ToLower changes the ordertype to lower case
|
||||
func (o OrderSide) ToLower() OrderSide {
|
||||
return OrderSide(strings.ToLower(string(o)))
|
||||
}
|
||||
|
||||
// ToString changes the ordertype to the exchange standard and returns a string
|
||||
func (o OrderSide) ToString() string {
|
||||
return fmt.Sprintf("%v", o)
|
||||
}
|
||||
|
||||
// OrderDetail holds order detail data
|
||||
type OrderDetail struct {
|
||||
Exchange string
|
||||
AccountID string
|
||||
ID string
|
||||
CurrencyPair currency.Pair
|
||||
OrderSide OrderSide
|
||||
OrderType OrderType
|
||||
OrderDate time.Time
|
||||
Status string
|
||||
Price float64
|
||||
Amount float64
|
||||
ExecutedAmount float64
|
||||
RemainingAmount float64
|
||||
Fee float64
|
||||
Trades []TradeHistory
|
||||
}
|
||||
|
||||
// OrderCancellation type required when requesting to cancel an order
|
||||
type OrderCancellation struct {
|
||||
AccountID string
|
||||
OrderID string
|
||||
CurrencyPair currency.Pair
|
||||
AssetType asset.Item
|
||||
WalletAddress string
|
||||
Side OrderSide
|
||||
}
|
||||
|
||||
// GetOrdersRequest used for GetOrderHistory and GetOpenOrders wrapper functions
|
||||
type GetOrdersRequest struct {
|
||||
OrderType OrderType
|
||||
OrderSide OrderSide
|
||||
StartTicks time.Time
|
||||
EndTicks time.Time
|
||||
// Currencies Empty array = all currencies. Some endpoints only support singular currency enquiries
|
||||
Currencies []currency.Pair
|
||||
}
|
||||
|
||||
// OrderStatus defines order status types
|
||||
type OrderStatus string
|
||||
|
||||
// All OrderStatus types
|
||||
const (
|
||||
AnyOrderStatus OrderStatus = "ANY"
|
||||
NewOrderStatus OrderStatus = "NEW"
|
||||
ActiveOrderStatus OrderStatus = "ACTIVE"
|
||||
PartiallyFilledOrderStatus OrderStatus = "PARTIALLY_FILLED"
|
||||
FilledOrderStatus OrderStatus = "FILLED"
|
||||
CancelledOrderStatus OrderStatus = "CANCELED"
|
||||
PendingCancelOrderStatus OrderStatus = "PENDING_CANCEL"
|
||||
RejectedOrderStatus OrderStatus = "REJECTED"
|
||||
ExpiredOrderStatus OrderStatus = "EXPIRED"
|
||||
HiddenOrderStatus OrderStatus = "HIDDEN"
|
||||
UnknownOrderStatus OrderStatus = "UNKNOWN"
|
||||
)
|
||||
|
||||
// FilterOrdersBySide removes any OrderDetails that don't match the orderStatus provided
|
||||
func FilterOrdersBySide(orders *[]OrderDetail, orderSide OrderSide) {
|
||||
if orderSide == "" || orderSide == AnyOrderSide {
|
||||
return
|
||||
}
|
||||
|
||||
var filteredOrders []OrderDetail
|
||||
for i := range *orders {
|
||||
if strings.EqualFold(string((*orders)[i].OrderSide), string(orderSide)) {
|
||||
filteredOrders = append(filteredOrders, (*orders)[i])
|
||||
}
|
||||
}
|
||||
|
||||
*orders = filteredOrders
|
||||
}
|
||||
|
||||
// FilterOrdersByType removes any OrderDetails that don't match the orderType provided
|
||||
func FilterOrdersByType(orders *[]OrderDetail, orderType OrderType) {
|
||||
if orderType == "" || orderType == AnyOrderType {
|
||||
return
|
||||
}
|
||||
|
||||
var filteredOrders []OrderDetail
|
||||
for i := range *orders {
|
||||
if strings.EqualFold(string((*orders)[i].OrderType), string(orderType)) {
|
||||
filteredOrders = append(filteredOrders, (*orders)[i])
|
||||
}
|
||||
}
|
||||
|
||||
*orders = filteredOrders
|
||||
}
|
||||
|
||||
// FilterOrdersByTickRange removes any OrderDetails outside of the tick range
|
||||
func FilterOrdersByTickRange(orders *[]OrderDetail, startTicks, endTicks time.Time) {
|
||||
if startTicks.IsZero() || endTicks.IsZero() ||
|
||||
startTicks.Unix() == 0 || endTicks.Unix() == 0 || endTicks.Before(startTicks) {
|
||||
return
|
||||
}
|
||||
|
||||
var filteredOrders []OrderDetail
|
||||
for i := range *orders {
|
||||
if (*orders)[i].OrderDate.Unix() >= startTicks.Unix() && (*orders)[i].OrderDate.Unix() <= endTicks.Unix() {
|
||||
filteredOrders = append(filteredOrders, (*orders)[i])
|
||||
}
|
||||
}
|
||||
|
||||
*orders = filteredOrders
|
||||
}
|
||||
|
||||
// FilterOrdersByCurrencies removes any OrderDetails that do not match the provided currency list
|
||||
// It is forgiving in that the provided currencies can match quote or base currencies
|
||||
func FilterOrdersByCurrencies(orders *[]OrderDetail, currencies []currency.Pair) {
|
||||
if len(currencies) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
var filteredOrders []OrderDetail
|
||||
for i := range *orders {
|
||||
matchFound := false
|
||||
for _, c := range currencies {
|
||||
if !matchFound && (*orders)[i].CurrencyPair.EqualIncludeReciprocal(c) {
|
||||
matchFound = true
|
||||
}
|
||||
}
|
||||
|
||||
if matchFound {
|
||||
filteredOrders = append(filteredOrders, (*orders)[i])
|
||||
}
|
||||
}
|
||||
|
||||
*orders = filteredOrders
|
||||
}
|
||||
|
||||
// ByPrice used for sorting orders by price
|
||||
type ByPrice []OrderDetail
|
||||
|
||||
func (b ByPrice) Len() int {
|
||||
return len(b)
|
||||
}
|
||||
|
||||
func (b ByPrice) Less(i, j int) bool {
|
||||
return b[i].Price < b[j].Price
|
||||
}
|
||||
|
||||
func (b ByPrice) Swap(i, j int) {
|
||||
b[i], b[j] = b[j], b[i]
|
||||
}
|
||||
|
||||
// SortOrdersByPrice the caller function to sort orders
|
||||
func SortOrdersByPrice(orders *[]OrderDetail, reverse bool) {
|
||||
if reverse {
|
||||
sort.Sort(sort.Reverse(ByPrice(*orders)))
|
||||
} else {
|
||||
sort.Sort(ByPrice(*orders))
|
||||
}
|
||||
}
|
||||
|
||||
// ByOrderType used for sorting orders by order type
|
||||
type ByOrderType []OrderDetail
|
||||
|
||||
func (b ByOrderType) Len() int {
|
||||
return len(b)
|
||||
}
|
||||
|
||||
func (b ByOrderType) Less(i, j int) bool {
|
||||
return b[i].OrderType.ToString() < b[j].OrderType.ToString()
|
||||
}
|
||||
|
||||
func (b ByOrderType) Swap(i, j int) {
|
||||
b[i], b[j] = b[j], b[i]
|
||||
}
|
||||
|
||||
// SortOrdersByType the caller function to sort orders
|
||||
func SortOrdersByType(orders *[]OrderDetail, reverse bool) {
|
||||
if reverse {
|
||||
sort.Sort(sort.Reverse(ByOrderType(*orders)))
|
||||
} else {
|
||||
sort.Sort(ByOrderType(*orders))
|
||||
}
|
||||
}
|
||||
|
||||
// ByCurrency used for sorting orders by order currency
|
||||
type ByCurrency []OrderDetail
|
||||
|
||||
func (b ByCurrency) Len() int {
|
||||
return len(b)
|
||||
}
|
||||
|
||||
func (b ByCurrency) Less(i, j int) bool {
|
||||
return b[i].CurrencyPair.String() < b[j].CurrencyPair.String()
|
||||
}
|
||||
|
||||
func (b ByCurrency) Swap(i, j int) {
|
||||
b[i], b[j] = b[j], b[i]
|
||||
}
|
||||
|
||||
// SortOrdersByCurrency the caller function to sort orders
|
||||
func SortOrdersByCurrency(orders *[]OrderDetail, reverse bool) {
|
||||
if reverse {
|
||||
sort.Sort(sort.Reverse(ByCurrency(*orders)))
|
||||
} else {
|
||||
sort.Sort(ByCurrency(*orders))
|
||||
}
|
||||
}
|
||||
|
||||
// ByDate used for sorting orders by order date
|
||||
type ByDate []OrderDetail
|
||||
|
||||
func (b ByDate) Len() int {
|
||||
return len(b)
|
||||
}
|
||||
|
||||
func (b ByDate) Less(i, j int) bool {
|
||||
return b[i].OrderDate.Unix() < b[j].OrderDate.Unix()
|
||||
}
|
||||
|
||||
func (b ByDate) Swap(i, j int) {
|
||||
b[i], b[j] = b[j], b[i]
|
||||
}
|
||||
|
||||
// SortOrdersByDate the caller function to sort orders
|
||||
func SortOrdersByDate(orders *[]OrderDetail, reverse bool) {
|
||||
if reverse {
|
||||
sort.Sort(sort.Reverse(ByDate(*orders)))
|
||||
} else {
|
||||
sort.Sort(ByDate(*orders))
|
||||
}
|
||||
}
|
||||
|
||||
// ByOrderSide used for sorting orders by order side (buy sell)
|
||||
type ByOrderSide []OrderDetail
|
||||
|
||||
func (b ByOrderSide) Len() int {
|
||||
return len(b)
|
||||
}
|
||||
|
||||
func (b ByOrderSide) Less(i, j int) bool {
|
||||
return b[i].OrderSide.ToString() < b[j].OrderSide.ToString()
|
||||
}
|
||||
|
||||
func (b ByOrderSide) Swap(i, j int) {
|
||||
b[i], b[j] = b[j], b[i]
|
||||
}
|
||||
|
||||
// SortOrdersBySide the caller function to sort orders
|
||||
func SortOrdersBySide(orders *[]OrderDetail, reverse bool) {
|
||||
if reverse {
|
||||
sort.Sort(sort.Reverse(ByOrderSide(*orders)))
|
||||
} else {
|
||||
sort.Sort(ByOrderSide(*orders))
|
||||
}
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
package orders
|
||||
|
||||
const (
|
||||
limitOrder = iota
|
||||
marketOrder
|
||||
)
|
||||
|
||||
// Orders variable holds an array of pointers to order structs
|
||||
var Orders []*Order
|
||||
|
||||
// Order struct holds order values
|
||||
type Order struct {
|
||||
OrderID int
|
||||
Exchange string
|
||||
Type int
|
||||
Amount float64
|
||||
Price float64
|
||||
}
|
||||
|
||||
// NewOrder creates a new order and returns a an orderID
|
||||
func NewOrder(exchangeName string, amount, price float64) int {
|
||||
order := &Order{}
|
||||
if len(Orders) == 0 {
|
||||
order.OrderID = 0
|
||||
} else {
|
||||
order.OrderID = len(Orders)
|
||||
}
|
||||
|
||||
order.Exchange = exchangeName
|
||||
order.Amount = amount
|
||||
order.Price = price
|
||||
Orders = append(Orders, order)
|
||||
return order.OrderID
|
||||
}
|
||||
|
||||
// DeleteOrder deletes orders by ID and returns state
|
||||
func DeleteOrder(orderID int) bool {
|
||||
for i := range Orders {
|
||||
if Orders[i].OrderID == orderID {
|
||||
Orders = append(Orders[:i], Orders[i+1:]...)
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// GetOrdersByExchange returns order pointer grouped by exchange
|
||||
func GetOrdersByExchange(exchange string) []*Order {
|
||||
var orders []*Order
|
||||
for i := range Orders {
|
||||
if Orders[i].Exchange == exchange {
|
||||
orders = append(orders, Orders[i])
|
||||
}
|
||||
}
|
||||
if len(orders) > 0 {
|
||||
return orders
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetOrderByOrderID returns order pointer by ID
|
||||
func GetOrderByOrderID(orderID int) *Order {
|
||||
for i := range Orders {
|
||||
if Orders[i].OrderID == orderID {
|
||||
return Orders[i]
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/common/crypto"
|
||||
"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/websocket/wshandler"
|
||||
)
|
||||
|
||||
@@ -410,9 +411,9 @@ func (p *Poloniex) PlaceOrder(currency string, rate, amount float64, immediate,
|
||||
|
||||
var orderType string
|
||||
if buy {
|
||||
orderType = exchange.BuyOrderSide.ToLower().ToString()
|
||||
orderType = order.Buy.Lower()
|
||||
} else {
|
||||
orderType = exchange.SellOrderSide.ToLower().ToString()
|
||||
orderType = order.Sell.Lower()
|
||||
}
|
||||
|
||||
values.Set("currencyPair", currency)
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"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/order"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/sharedtestvalues"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
)
|
||||
@@ -212,8 +213,8 @@ func TestFormatWithdrawPermissions(t *testing.T) {
|
||||
|
||||
func TestGetActiveOrders(t *testing.T) {
|
||||
t.Parallel()
|
||||
var getOrdersRequest = exchange.GetOrdersRequest{
|
||||
OrderType: exchange.AnyOrderType,
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
OrderType: order.AnyType,
|
||||
}
|
||||
|
||||
_, err := p.GetActiveOrders(&getOrdersRequest)
|
||||
@@ -229,8 +230,8 @@ func TestGetActiveOrders(t *testing.T) {
|
||||
|
||||
func TestGetOrderHistory(t *testing.T) {
|
||||
t.Parallel()
|
||||
var getOrdersRequest = exchange.GetOrdersRequest{
|
||||
OrderType: exchange.AnyOrderType,
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
OrderType: order.AnyType,
|
||||
}
|
||||
|
||||
_, err := p.GetOrderHistory(&getOrdersRequest)
|
||||
@@ -253,14 +254,14 @@ 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{
|
||||
Delimiter: "_",
|
||||
Base: currency.BTC,
|
||||
Quote: currency.LTC,
|
||||
},
|
||||
OrderSide: exchange.BuyOrderSide,
|
||||
OrderType: exchange.MarketOrderType,
|
||||
OrderSide: order.Buy,
|
||||
OrderType: order.Market,
|
||||
Price: 10,
|
||||
Amount: 10000000,
|
||||
ClientID: "hi",
|
||||
@@ -283,7 +284,7 @@ func TestCancelExchangeOrder(t *testing.T) {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
var orderCancellation = &exchange.OrderCancellation{
|
||||
var orderCancellation = &order.Cancel{
|
||||
OrderID: "1",
|
||||
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
AccountID: "1",
|
||||
@@ -309,7 +310,7 @@ func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
|
||||
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
|
||||
var orderCancellation = &exchange.OrderCancellation{
|
||||
var orderCancellation = &order.Cancel{
|
||||
OrderID: "1",
|
||||
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
AccountID: "1",
|
||||
@@ -325,8 +326,8 @@ func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
case mockTests && err != nil:
|
||||
t.Error("Mock CancelAllExchangeOrders() err", 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))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -336,7 +337,7 @@ func TestModifyOrder(t *testing.T) {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
_, err := p.ModifyOrder(&exchange.ModifyOrder{OrderID: "1337", Price: 1337})
|
||||
_, err := p.ModifyOrder(&order.Modify{OrderID: "1337", Price: 1337})
|
||||
switch {
|
||||
case areTestAPIKeysSet() && err != nil && mockTests:
|
||||
t.Error("ModifyOrder() error", err)
|
||||
|
||||
@@ -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"
|
||||
@@ -359,26 +360,22 @@ func (p *Poloniex) GetExchangeHistory(currencyPair currency.Pair, assetType asse
|
||||
}
|
||||
|
||||
// SubmitOrder submits a new order
|
||||
func (p *Poloniex) 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 (p *Poloniex) SubmitOrder(s *order.Submit) (order.SubmitResponse, error) {
|
||||
var submitOrderResponse order.SubmitResponse
|
||||
if err := s.Validate(); err != nil {
|
||||
return submitOrderResponse, err
|
||||
}
|
||||
|
||||
fillOrKill := order.OrderType == exchange.MarketOrderType
|
||||
isBuyOrder := order.OrderSide == exchange.BuyOrderSide
|
||||
response, err := p.PlaceOrder(order.Pair.String(),
|
||||
order.Price,
|
||||
order.Amount,
|
||||
fillOrKill := s.OrderType == order.Market
|
||||
isBuyOrder := s.OrderSide == order.Buy
|
||||
response, err := p.PlaceOrder(s.Pair.String(),
|
||||
s.Price,
|
||||
s.Amount,
|
||||
false,
|
||||
fillOrKill,
|
||||
isBuyOrder)
|
||||
if response.OrderNumber > 0 {
|
||||
submitOrderResponse.OrderID = fmt.Sprintf("%v", response.OrderNumber)
|
||||
submitOrderResponse.OrderID = strconv.FormatInt(response.OrderNumber, 10)
|
||||
}
|
||||
if err == nil {
|
||||
submitOrderResponse.IsOrderPlaced = true
|
||||
@@ -388,7 +385,7 @@ func (p *Poloniex) SubmitOrder(order *exchange.OrderSubmission) (exchange.Submit
|
||||
|
||||
// ModifyOrder will allow of changing orderbook placement and limit to
|
||||
// market conversion
|
||||
func (p *Poloniex) ModifyOrder(action *exchange.ModifyOrder) (string, error) {
|
||||
func (p *Poloniex) ModifyOrder(action *order.Modify) (string, error) {
|
||||
oID, err := strconv.ParseInt(action.OrderID, 10, 64)
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -407,7 +404,7 @@ func (p *Poloniex) ModifyOrder(action *exchange.ModifyOrder) (string, error) {
|
||||
}
|
||||
|
||||
// CancelOrder cancels an order by its corresponding ID number
|
||||
func (p *Poloniex) CancelOrder(order *exchange.OrderCancellation) error {
|
||||
func (p *Poloniex) CancelOrder(order *order.Cancel) error {
|
||||
orderIDInt, err := strconv.ParseInt(order.OrderID, 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -417,20 +414,21 @@ func (p *Poloniex) CancelOrder(order *exchange.OrderCancellation) error {
|
||||
}
|
||||
|
||||
// CancelAllOrders cancels all orders associated with a currency pair
|
||||
func (p *Poloniex) CancelAllOrders(_ *exchange.OrderCancellation) (exchange.CancelAllOrdersResponse, error) {
|
||||
cancelAllOrdersResponse := exchange.CancelAllOrdersResponse{
|
||||
OrderStatus: make(map[string]string),
|
||||
func (p *Poloniex) CancelAllOrders(_ *order.Cancel) (order.CancelAllResponse, error) {
|
||||
cancelAllOrdersResponse := order.CancelAllResponse{
|
||||
Status: make(map[string]string),
|
||||
}
|
||||
openOrders, err := p.GetOpenOrdersForAllCurrencies()
|
||||
if err != nil {
|
||||
return cancelAllOrdersResponse, err
|
||||
}
|
||||
|
||||
for _, openOrderPerCurrency := range openOrders.Data {
|
||||
for _, openOrder := range openOrderPerCurrency {
|
||||
err = p.CancelExistingOrder(openOrder.OrderNumber)
|
||||
for key := range openOrders.Data {
|
||||
for i := range openOrders.Data[key] {
|
||||
err = p.CancelExistingOrder(openOrders.Data[key][i].OrderNumber)
|
||||
if err != nil {
|
||||
cancelAllOrdersResponse.OrderStatus[strconv.FormatInt(openOrder.OrderNumber, 10)] = err.Error()
|
||||
id := strconv.FormatInt(openOrders.Data[key][i].OrderNumber, 10)
|
||||
cancelAllOrdersResponse.Status[id] = err.Error()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -439,8 +437,8 @@ func (p *Poloniex) CancelAllOrders(_ *exchange.OrderCancellation) (exchange.Canc
|
||||
}
|
||||
|
||||
// GetOrderInfo returns information on a current open order
|
||||
func (p *Poloniex) GetOrderInfo(orderID string) (exchange.OrderDetail, error) {
|
||||
var orderDetail exchange.OrderDetail
|
||||
func (p *Poloniex) GetOrderInfo(orderID string) (order.Detail, error) {
|
||||
var orderDetail order.Detail
|
||||
return orderDetail, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
@@ -494,81 +492,90 @@ func (p *Poloniex) GetFeeByType(feeBuilder *exchange.FeeBuilder) (float64, error
|
||||
}
|
||||
|
||||
// GetActiveOrders retrieves any orders that are active/open
|
||||
func (p *Poloniex) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
func (p *Poloniex) GetActiveOrders(req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
resp, err := p.GetOpenOrdersForAllCurrencies()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var orders []exchange.OrderDetail
|
||||
for currencyPair, openOrders := range resp.Data {
|
||||
symbol := currency.NewPairDelimiter(currencyPair,
|
||||
var orders []order.Detail
|
||||
for key := range resp.Data {
|
||||
symbol := currency.NewPairDelimiter(key,
|
||||
p.GetPairFormat(asset.Spot, false).Delimiter)
|
||||
|
||||
for _, order := range openOrders {
|
||||
orderSide := exchange.OrderSide(strings.ToUpper(order.Type))
|
||||
orderDate, err := time.Parse(poloniexDateLayout, order.Date)
|
||||
for i := range resp.Data[key] {
|
||||
orderSide := order.Side(strings.ToUpper(resp.Data[key][i].Type))
|
||||
orderDate, err := time.Parse(poloniexDateLayout, resp.Data[key][i].Date)
|
||||
if err != nil {
|
||||
log.Warnf(log.ExchangeSys, "Exchange %v Func %v Order %v Could not parse date to unix with value of %v",
|
||||
p.Name, "GetActiveOrders", order.OrderNumber, order.Date)
|
||||
log.Warnf(log.ExchangeSys,
|
||||
"Exchange %v Func %v Order %v Could not parse date to unix with value of %v",
|
||||
p.Name,
|
||||
"GetActiveOrders",
|
||||
resp.Data[key][i].OrderNumber,
|
||||
resp.Data[key][i].Date)
|
||||
}
|
||||
|
||||
orders = append(orders, exchange.OrderDetail{
|
||||
ID: fmt.Sprintf("%v", order.OrderNumber),
|
||||
orders = append(orders, order.Detail{
|
||||
ID: strconv.FormatInt(resp.Data[key][i].OrderNumber, 10),
|
||||
OrderSide: orderSide,
|
||||
Amount: order.Amount,
|
||||
Amount: resp.Data[key][i].Amount,
|
||||
OrderDate: orderDate,
|
||||
Price: order.Rate,
|
||||
Price: resp.Data[key][i].Rate,
|
||||
CurrencyPair: symbol,
|
||||
Exchange: p.Name,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks, getOrdersRequest.EndTicks)
|
||||
exchange.FilterOrdersByCurrencies(&orders, getOrdersRequest.Currencies)
|
||||
exchange.FilterOrdersBySide(&orders, getOrdersRequest.OrderSide)
|
||||
order.FilterOrdersByTickRange(&orders, req.StartTicks, req.EndTicks)
|
||||
order.FilterOrdersByCurrencies(&orders, req.Currencies)
|
||||
order.FilterOrdersBySide(&orders, req.OrderSide)
|
||||
|
||||
return orders, nil
|
||||
}
|
||||
|
||||
// GetOrderHistory retrieves account order information
|
||||
// Can Limit response to specific order status
|
||||
func (p *Poloniex) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
resp, err := p.GetAuthenticatedTradeHistory(getOrdersRequest.StartTicks.Unix(),
|
||||
getOrdersRequest.EndTicks.Unix(),
|
||||
func (p *Poloniex) GetOrderHistory(req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
resp, err := p.GetAuthenticatedTradeHistory(req.StartTicks.Unix(),
|
||||
req.EndTicks.Unix(),
|
||||
10000)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var orders []exchange.OrderDetail
|
||||
for currencyPair, historicOrders := range resp.Data {
|
||||
symbol := currency.NewPairDelimiter(currencyPair,
|
||||
var orders []order.Detail
|
||||
for key := range resp.Data {
|
||||
symbol := currency.NewPairDelimiter(key,
|
||||
p.GetPairFormat(asset.Spot, false).Delimiter)
|
||||
|
||||
for _, order := range historicOrders {
|
||||
orderSide := exchange.OrderSide(strings.ToUpper(order.Type))
|
||||
orderDate, err := time.Parse(poloniexDateLayout, order.Date)
|
||||
for i := range resp.Data[key] {
|
||||
orderSide := order.Side(strings.ToUpper(resp.Data[key][i].Type))
|
||||
orderDate, err := time.Parse(poloniexDateLayout,
|
||||
resp.Data[key][i].Date)
|
||||
if err != nil {
|
||||
log.Warnf(log.ExchangeSys, "Exchange %v Func %v Order %v Could not parse date to unix with value of %v",
|
||||
p.Name, "GetActiveOrders", order.OrderNumber, order.Date)
|
||||
log.Warnf(log.ExchangeSys,
|
||||
"Exchange %v Func %v Order %v Could not parse date to unix with value of %v",
|
||||
p.Name,
|
||||
"GetActiveOrders",
|
||||
resp.Data[key][i].OrderNumber,
|
||||
resp.Data[key][i].Date)
|
||||
}
|
||||
|
||||
orders = append(orders, exchange.OrderDetail{
|
||||
ID: fmt.Sprintf("%v", order.GlobalTradeID),
|
||||
orders = append(orders, order.Detail{
|
||||
ID: strconv.FormatInt(resp.Data[key][i].GlobalTradeID, 10),
|
||||
OrderSide: orderSide,
|
||||
Amount: order.Amount,
|
||||
Amount: resp.Data[key][i].Amount,
|
||||
OrderDate: orderDate,
|
||||
Price: order.Rate,
|
||||
Price: resp.Data[key][i].Rate,
|
||||
CurrencyPair: symbol,
|
||||
Exchange: p.Name,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
exchange.FilterOrdersByCurrencies(&orders, getOrdersRequest.Currencies)
|
||||
exchange.FilterOrdersBySide(&orders, getOrdersRequest.OrderSide)
|
||||
order.FilterOrdersByCurrencies(&orders, req.Currencies)
|
||||
order.FilterOrdersBySide(&orders, req.OrderSide)
|
||||
|
||||
return orders, nil
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ func (y *Yobit) GetAccountInformation() (AccountInfo, error) {
|
||||
func (y *Yobit) Trade(pair, orderType string, amount, price float64) (int64, error) {
|
||||
req := url.Values{}
|
||||
req.Add("pair", pair)
|
||||
req.Add("type", orderType)
|
||||
req.Add("type", strings.ToLower(orderType))
|
||||
req.Add("amount", strconv.FormatFloat(amount, 'f', -1, 64))
|
||||
req.Add("rate", strconv.FormatFloat(price, 'f', -1, 64))
|
||||
|
||||
@@ -142,7 +142,7 @@ func (y *Yobit) GetOrderInformation(orderID int64) (map[string]OrderInfo, error)
|
||||
}
|
||||
|
||||
// CancelExistingOrder cancels an order for a specific order ID
|
||||
func (y *Yobit) CancelExistingOrder(orderID int64) (bool, error) {
|
||||
func (y *Yobit) CancelExistingOrder(orderID int64) error {
|
||||
req := url.Values{}
|
||||
req.Add("order_id", strconv.FormatInt(orderID, 10))
|
||||
|
||||
@@ -150,12 +150,12 @@ func (y *Yobit) CancelExistingOrder(orderID int64) (bool, error) {
|
||||
|
||||
err := y.SendAuthenticatedHTTPRequest(privateCancelOrder, req, &result)
|
||||
if err != nil {
|
||||
return false, err
|
||||
return err
|
||||
}
|
||||
if result.Error != "" {
|
||||
return false, errors.New(result.Error)
|
||||
return errors.New(result.Error)
|
||||
}
|
||||
return true, nil
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetTradeHistory returns the trade history
|
||||
|
||||
@@ -10,6 +10,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"
|
||||
)
|
||||
|
||||
var y Yobit
|
||||
@@ -111,7 +112,7 @@ func TestGetOrderInfo(t *testing.T) {
|
||||
|
||||
func TestCancelOrder(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := y.CancelExistingOrder(1337)
|
||||
err := y.CancelExistingOrder(1337)
|
||||
if err == nil {
|
||||
t.Error("CancelOrder() Expected error")
|
||||
}
|
||||
@@ -119,7 +120,7 @@ func TestCancelOrder(t *testing.T) {
|
||||
|
||||
func TestTrade(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := y.Trade("", exchange.BuyOrderSide.ToLower().ToString(), 0, 0)
|
||||
_, err := y.Trade("", order.Buy.String(), 0, 0)
|
||||
if err == nil {
|
||||
t.Error("Trade() Expected error")
|
||||
}
|
||||
@@ -330,8 +331,8 @@ func TestGetActiveOrders(t *testing.T) {
|
||||
y.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)},
|
||||
}
|
||||
@@ -348,8 +349,8 @@ func TestGetOrderHistory(t *testing.T) {
|
||||
y.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)},
|
||||
StartTicks: time.Unix(0, 0),
|
||||
@@ -378,14 +379,14 @@ 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{
|
||||
Delimiter: "_",
|
||||
Base: currency.BTC,
|
||||
Quote: currency.USD,
|
||||
},
|
||||
OrderSide: exchange.BuyOrderSide,
|
||||
OrderType: exchange.LimitOrderType,
|
||||
OrderSide: order.Buy,
|
||||
OrderType: order.Limit,
|
||||
Price: 1,
|
||||
Amount: 1,
|
||||
ClientID: "meowOrder",
|
||||
@@ -408,7 +409,7 @@ func TestCancelExchangeOrder(t *testing.T) {
|
||||
|
||||
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
|
||||
var orderCancellation = &exchange.OrderCancellation{
|
||||
var orderCancellation = &order.Cancel{
|
||||
OrderID: "1",
|
||||
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
AccountID: "1",
|
||||
@@ -434,7 +435,7 @@ func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
|
||||
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
|
||||
var orderCancellation = &exchange.OrderCancellation{
|
||||
var orderCancellation = &order.Cancel{
|
||||
OrderID: "1",
|
||||
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
AccountID: "1",
|
||||
@@ -450,13 +451,13 @@ 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))
|
||||
}
|
||||
}
|
||||
|
||||
func TestModifyOrder(t *testing.T) {
|
||||
_, err := y.ModifyOrder(&exchange.ModifyOrder{})
|
||||
_, err := y.ModifyOrder(&order.Modify{})
|
||||
if err == nil {
|
||||
t.Error("ModifyOrder() Expected error")
|
||||
}
|
||||
@@ -498,7 +499,9 @@ func TestWithdrawFiat(t *testing.T) {
|
||||
var withdrawFiatRequest = exchange.FiatWithdrawRequest{}
|
||||
_, err := y.WithdrawFiatFunds(&withdrawFiatRequest)
|
||||
if err != common.ErrFunctionNotSupported {
|
||||
t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err)
|
||||
t.Errorf("Expected '%v', received: '%v'",
|
||||
common.ErrFunctionNotSupported,
|
||||
err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -513,7 +516,9 @@ func TestWithdrawInternationalBank(t *testing.T) {
|
||||
var withdrawFiatRequest = exchange.FiatWithdrawRequest{}
|
||||
_, err := y.WithdrawFiatFundsToInternationalBank(&withdrawFiatRequest)
|
||||
if err != common.ErrFunctionNotSupported {
|
||||
t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err)
|
||||
t.Errorf("Expected '%v', received: '%v'",
|
||||
common.ErrFunctionNotSupported,
|
||||
err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package yobit
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -14,6 +13,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"
|
||||
@@ -141,7 +141,10 @@ func (y *Yobit) Run() {
|
||||
|
||||
err := y.UpdateTradablePairs(false)
|
||||
if err != nil {
|
||||
log.Errorf(log.ExchangeSys, "%s failed to update tradable pairs. Err: %s", y.Name, err)
|
||||
log.Errorf(log.ExchangeSys,
|
||||
"%s failed to update tradable pairs. Err: %s",
|
||||
y.Name,
|
||||
err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -233,14 +236,20 @@ func (y *Yobit) UpdateOrderbook(p currency.Pair, assetType asset.Item) (orderboo
|
||||
return orderBook, err
|
||||
}
|
||||
|
||||
for x := range orderbookNew.Bids {
|
||||
data := orderbookNew.Bids[x]
|
||||
orderBook.Bids = append(orderBook.Bids, orderbook.Item{Price: data[0], Amount: data[1]})
|
||||
for i := range orderbookNew.Bids {
|
||||
orderBook.Bids = append(orderBook.Bids,
|
||||
orderbook.Item{
|
||||
Price: orderbookNew.Bids[i][0],
|
||||
Amount: orderbookNew.Bids[i][1],
|
||||
})
|
||||
}
|
||||
|
||||
for x := range orderbookNew.Asks {
|
||||
data := orderbookNew.Asks[x]
|
||||
orderBook.Asks = append(orderBook.Asks, orderbook.Item{Price: data[0], Amount: data[1]})
|
||||
for i := range orderbookNew.Asks {
|
||||
orderBook.Asks = append(orderBook.Asks,
|
||||
orderbook.Item{
|
||||
Price: orderbookNew.Asks[i][0],
|
||||
Amount: orderbookNew.Asks[i][1],
|
||||
})
|
||||
}
|
||||
|
||||
orderBook.Pair = p
|
||||
@@ -301,24 +310,22 @@ func (y *Yobit) GetExchangeHistory(p currency.Pair, assetType asset.Item) ([]exc
|
||||
|
||||
// SubmitOrder submits a new order
|
||||
// Yobit only supports limit orders
|
||||
func (y *Yobit) 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 (y *Yobit) SubmitOrder(s *order.Submit) (order.SubmitResponse, error) {
|
||||
var submitOrderResponse order.SubmitResponse
|
||||
if err := s.Validate(); err != nil {
|
||||
return submitOrderResponse, err
|
||||
}
|
||||
|
||||
if order.OrderType != exchange.LimitOrderType {
|
||||
if s.OrderType != order.Limit {
|
||||
return submitOrderResponse, errors.New("only limit orders are allowed")
|
||||
}
|
||||
|
||||
response, err := y.Trade(order.Pair.String(), order.OrderSide.ToString(),
|
||||
order.Amount, order.Price)
|
||||
response, err := y.Trade(s.Pair.String(),
|
||||
s.OrderSide.String(),
|
||||
s.Amount,
|
||||
s.Price)
|
||||
if response > 0 {
|
||||
submitOrderResponse.OrderID = fmt.Sprintf("%v", response)
|
||||
submitOrderResponse.OrderID = strconv.FormatInt(response, 10)
|
||||
}
|
||||
if err == nil {
|
||||
submitOrderResponse.IsOrderPlaced = true
|
||||
@@ -328,31 +335,31 @@ func (y *Yobit) SubmitOrder(order *exchange.OrderSubmission) (exchange.SubmitOrd
|
||||
|
||||
// ModifyOrder will allow of changing orderbook placement and limit to
|
||||
// market conversion
|
||||
func (y *Yobit) ModifyOrder(action *exchange.ModifyOrder) (string, error) {
|
||||
func (y *Yobit) ModifyOrder(action *order.Modify) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// CancelOrder cancels an order by its corresponding ID number
|
||||
func (y *Yobit) CancelOrder(order *exchange.OrderCancellation) error {
|
||||
func (y *Yobit) CancelOrder(order *order.Cancel) error {
|
||||
orderIDInt, err := strconv.ParseInt(order.OrderID, 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = y.CancelExistingOrder(orderIDInt)
|
||||
return err
|
||||
return y.CancelExistingOrder(orderIDInt)
|
||||
}
|
||||
|
||||
// CancelAllOrders cancels all orders associated with a currency pair
|
||||
func (y *Yobit) CancelAllOrders(_ *exchange.OrderCancellation) (exchange.CancelAllOrdersResponse, error) {
|
||||
cancelAllOrdersResponse := exchange.CancelAllOrdersResponse{
|
||||
OrderStatus: make(map[string]string),
|
||||
func (y *Yobit) CancelAllOrders(_ *order.Cancel) (order.CancelAllResponse, error) {
|
||||
cancelAllOrdersResponse := order.CancelAllResponse{
|
||||
Status: make(map[string]string),
|
||||
}
|
||||
var allActiveOrders []map[string]ActiveOrders
|
||||
|
||||
for _, pair := range y.GetEnabledPairs(asset.Spot) {
|
||||
activeOrdersForPair, err := y.GetOpenOrders(y.FormatExchangeCurrency(pair,
|
||||
asset.Spot).String())
|
||||
var allActiveOrders []map[string]ActiveOrders
|
||||
enabledPairs := y.GetEnabledPairs(asset.Spot)
|
||||
for i := range enabledPairs {
|
||||
fCurr := y.FormatExchangeCurrency(enabledPairs[i], asset.Spot).String()
|
||||
activeOrdersForPair, err := y.GetOpenOrders(fCurr)
|
||||
if err != nil {
|
||||
return cancelAllOrdersResponse, err
|
||||
}
|
||||
@@ -360,17 +367,17 @@ func (y *Yobit) CancelAllOrders(_ *exchange.OrderCancellation) (exchange.CancelA
|
||||
allActiveOrders = append(allActiveOrders, activeOrdersForPair)
|
||||
}
|
||||
|
||||
for _, activeOrders := range allActiveOrders {
|
||||
for key := range activeOrders {
|
||||
for i := range allActiveOrders {
|
||||
for key := range allActiveOrders[i] {
|
||||
orderIDInt, err := strconv.ParseInt(key, 10, 64)
|
||||
if err != nil {
|
||||
cancelAllOrdersResponse.OrderStatus[key] = err.Error()
|
||||
cancelAllOrdersResponse.Status[key] = err.Error()
|
||||
continue
|
||||
}
|
||||
|
||||
_, err = y.CancelExistingOrder(orderIDInt)
|
||||
err = y.CancelExistingOrder(orderIDInt)
|
||||
if err != nil {
|
||||
cancelAllOrdersResponse.OrderStatus[key] = err.Error()
|
||||
cancelAllOrdersResponse.Status[key] = err.Error()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -379,8 +386,8 @@ func (y *Yobit) CancelAllOrders(_ *exchange.OrderCancellation) (exchange.CancelA
|
||||
}
|
||||
|
||||
// GetOrderInfo returns information on a current open order
|
||||
func (y *Yobit) GetOrderInfo(orderID string) (exchange.OrderDetail, error) {
|
||||
var orderDetail exchange.OrderDetail
|
||||
func (y *Yobit) GetOrderInfo(orderID string) (order.Detail, error) {
|
||||
var orderDetail order.Detail
|
||||
return orderDetail, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
@@ -434,24 +441,24 @@ func (y *Yobit) GetFeeByType(feeBuilder *exchange.FeeBuilder) (float64, error) {
|
||||
}
|
||||
|
||||
// GetActiveOrders retrieves any orders that are active/open
|
||||
func (y *Yobit) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
var orders []exchange.OrderDetail
|
||||
for _, c := range getOrdersRequest.Currencies {
|
||||
resp, err := y.GetOpenOrders(y.FormatExchangeCurrency(c,
|
||||
asset.Spot).String())
|
||||
func (y *Yobit) GetActiveOrders(req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
var orders []order.Detail
|
||||
for x := range req.Currencies {
|
||||
fCurr := y.FormatExchangeCurrency(req.Currencies[x], asset.Spot).String()
|
||||
resp, err := y.GetOpenOrders(fCurr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for ID, order := range resp {
|
||||
symbol := currency.NewPairDelimiter(order.Pair,
|
||||
for id := range resp {
|
||||
symbol := currency.NewPairDelimiter(resp[id].Pair,
|
||||
y.GetPairFormat(asset.Spot, false).Delimiter)
|
||||
orderDate := time.Unix(int64(order.TimestampCreated), 0)
|
||||
side := exchange.OrderSide(strings.ToUpper(order.Type))
|
||||
orders = append(orders, exchange.OrderDetail{
|
||||
ID: ID,
|
||||
Amount: order.Amount,
|
||||
Price: order.Rate,
|
||||
orderDate := time.Unix(int64(resp[id].TimestampCreated), 0)
|
||||
side := order.Side(strings.ToUpper(resp[id].Type))
|
||||
orders = append(orders, order.Detail{
|
||||
ID: id,
|
||||
Amount: resp[id].Amount,
|
||||
Price: resp[id].Rate,
|
||||
OrderSide: side,
|
||||
OrderDate: orderDate,
|
||||
CurrencyPair: symbol,
|
||||
@@ -460,43 +467,42 @@ func (y *Yobit) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([]
|
||||
}
|
||||
}
|
||||
|
||||
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks,
|
||||
getOrdersRequest.EndTicks)
|
||||
exchange.FilterOrdersBySide(&orders, getOrdersRequest.OrderSide)
|
||||
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 (y *Yobit) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
func (y *Yobit) GetOrderHistory(req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
var allOrders []TradeHistory
|
||||
for _, currency := range getOrdersRequest.Currencies {
|
||||
for x := range req.Currencies {
|
||||
resp, err := y.GetTradeHistory(0,
|
||||
10000,
|
||||
math.MaxInt64,
|
||||
getOrdersRequest.StartTicks.Unix(),
|
||||
getOrdersRequest.EndTicks.Unix(),
|
||||
req.StartTicks.Unix(),
|
||||
req.EndTicks.Unix(),
|
||||
"DESC",
|
||||
y.FormatExchangeCurrency(currency, asset.Spot).String())
|
||||
y.FormatExchangeCurrency(req.Currencies[x], asset.Spot).String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, order := range resp {
|
||||
allOrders = append(allOrders, order)
|
||||
for key := range resp {
|
||||
allOrders = append(allOrders, resp[key])
|
||||
}
|
||||
}
|
||||
|
||||
var orders []exchange.OrderDetail
|
||||
for _, order := range allOrders {
|
||||
symbol := currency.NewPairDelimiter(order.Pair,
|
||||
var orders []order.Detail
|
||||
for i := range allOrders {
|
||||
symbol := currency.NewPairDelimiter(allOrders[i].Pair,
|
||||
y.GetPairFormat(asset.Spot, false).Delimiter)
|
||||
orderDate := time.Unix(int64(order.Timestamp), 0)
|
||||
side := exchange.OrderSide(strings.ToUpper(order.Type))
|
||||
orders = append(orders, exchange.OrderDetail{
|
||||
ID: fmt.Sprintf("%v", order.OrderID),
|
||||
Amount: order.Amount,
|
||||
Price: order.Rate,
|
||||
orderDate := time.Unix(int64(allOrders[i].Timestamp), 0)
|
||||
side := order.Side(strings.ToUpper(allOrders[i].Type))
|
||||
orders = append(orders, order.Detail{
|
||||
ID: strconv.FormatFloat(allOrders[i].OrderID, 'f', -1, 64),
|
||||
Amount: allOrders[i].Amount,
|
||||
Price: allOrders[i].Rate,
|
||||
OrderSide: side,
|
||||
OrderDate: orderDate,
|
||||
CurrencyPair: symbol,
|
||||
@@ -504,7 +510,7 @@ func (y *Yobit) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([]
|
||||
})
|
||||
}
|
||||
|
||||
exchange.FilterOrdersBySide(&orders, getOrdersRequest.OrderSide)
|
||||
order.FilterOrdersBySide(&orders, req.OrderSide)
|
||||
|
||||
return orders, nil
|
||||
}
|
||||
|
||||
@@ -10,6 +10,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/websocket/wshandler"
|
||||
)
|
||||
|
||||
@@ -284,8 +285,8 @@ func TestGetActiveOrders(t *testing.T) {
|
||||
z.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)},
|
||||
}
|
||||
@@ -302,9 +303,9 @@ func TestGetOrderHistory(t *testing.T) {
|
||||
z.SetDefaults()
|
||||
TestSetup(t)
|
||||
|
||||
var getOrdersRequest = exchange.GetOrdersRequest{
|
||||
OrderType: exchange.AnyOrderType,
|
||||
OrderSide: exchange.BuyOrderSide,
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
OrderType: order.AnyType,
|
||||
OrderSide: order.Buy,
|
||||
Currencies: []currency.Pair{currency.NewPair(currency.LTC,
|
||||
currency.BTC)},
|
||||
}
|
||||
@@ -332,14 +333,14 @@ func TestSubmitOrder(t *testing.T) {
|
||||
canManipulateRealOrders))
|
||||
}
|
||||
|
||||
var orderSubmission = &exchange.OrderSubmission{
|
||||
var orderSubmission = &order.Submit{
|
||||
Pair: currency.Pair{
|
||||
Delimiter: "_",
|
||||
Base: currency.QTUM,
|
||||
Quote: currency.USD,
|
||||
},
|
||||
OrderSide: exchange.BuyOrderSide,
|
||||
OrderType: exchange.LimitOrderType,
|
||||
OrderSide: order.Buy,
|
||||
OrderType: order.Limit,
|
||||
Price: 1,
|
||||
Amount: 1,
|
||||
ClientID: "meowOrder",
|
||||
@@ -362,7 +363,7 @@ func TestCancelExchangeOrder(t *testing.T) {
|
||||
|
||||
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
|
||||
var orderCancellation = &exchange.OrderCancellation{
|
||||
var orderCancellation = &order.Cancel{
|
||||
OrderID: "1",
|
||||
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
AccountID: "1",
|
||||
@@ -388,7 +389,7 @@ func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
|
||||
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
|
||||
var orderCancellation = &exchange.OrderCancellation{
|
||||
var orderCancellation = &order.Cancel{
|
||||
OrderID: "1",
|
||||
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
AccountID: "1",
|
||||
@@ -404,8 +405,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))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -424,7 +425,7 @@ func TestGetAccountInfo(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestModifyOrder(t *testing.T) {
|
||||
_, err := z.ModifyOrder(&exchange.ModifyOrder{})
|
||||
_, err := z.ModifyOrder(&order.Modify{})
|
||||
if err == nil {
|
||||
t.Error("ModifyOrder() Expected 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"
|
||||
)
|
||||
|
||||
// OrderbookResponse holds the orderbook data for a symbol
|
||||
@@ -241,7 +241,7 @@ var WithdrawalFees = map[currency.Code]float64{
|
||||
}
|
||||
|
||||
// orderSideMap holds order type info based on Alphapoint data
|
||||
var orderSideMap = map[int64]exchange.OrderSide{
|
||||
0: exchange.BuyOrderSide,
|
||||
1: exchange.SellOrderSide,
|
||||
var orderSideMap = map[int64]order.Side{
|
||||
0: order.Buy,
|
||||
1: order.Sell,
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
@@ -344,27 +345,23 @@ func (z *ZB) GetExchangeHistory(p currency.Pair, assetType asset.Item) ([]exchan
|
||||
}
|
||||
|
||||
// SubmitOrder submits a new order
|
||||
func (z *ZB) 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 (z *ZB) SubmitOrder(s *order.Submit) (order.SubmitResponse, error) {
|
||||
var submitOrderResponse order.SubmitResponse
|
||||
if err := s.Validate(); err != nil {
|
||||
return submitOrderResponse, err
|
||||
}
|
||||
|
||||
var oT SpotNewOrderRequestParamsType
|
||||
if order.OrderSide == exchange.BuyOrderSide {
|
||||
if s.OrderSide == order.Buy {
|
||||
oT = SpotNewOrderRequestParamsTypeBuy
|
||||
} else {
|
||||
oT = SpotNewOrderRequestParamsTypeSell
|
||||
}
|
||||
|
||||
var params = SpotNewOrderRequestParams{
|
||||
Amount: order.Amount,
|
||||
Price: order.Price,
|
||||
Symbol: order.Pair.Lower().String(),
|
||||
Amount: s.Amount,
|
||||
Price: s.Price,
|
||||
Symbol: s.Pair.Lower().String(),
|
||||
Type: oT,
|
||||
}
|
||||
response, err := z.SpotNewOrder(params)
|
||||
@@ -379,32 +376,34 @@ func (z *ZB) SubmitOrder(order *exchange.OrderSubmission) (exchange.SubmitOrderR
|
||||
|
||||
// ModifyOrder will allow of changing orderbook placement and limit to
|
||||
// market conversion
|
||||
func (z *ZB) ModifyOrder(action *exchange.ModifyOrder) (string, error) {
|
||||
func (z *ZB) ModifyOrder(action *order.Modify) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// CancelOrder cancels an order by its corresponding ID number
|
||||
func (z *ZB) CancelOrder(order *exchange.OrderCancellation) error {
|
||||
orderIDInt, err := strconv.ParseInt(order.OrderID, 10, 64)
|
||||
|
||||
func (z *ZB) CancelOrder(o *order.Cancel) error {
|
||||
orderIDInt, err := strconv.ParseInt(o.OrderID, 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return z.CancelExistingOrder(orderIDInt, z.FormatExchangeCurrency(order.CurrencyPair,
|
||||
order.AssetType).String())
|
||||
curr := z.FormatExchangeCurrency(o.CurrencyPair, o.AssetType).String()
|
||||
return z.CancelExistingOrder(orderIDInt, curr)
|
||||
}
|
||||
|
||||
// CancelAllOrders cancels all orders associated with a currency pair
|
||||
func (z *ZB) CancelAllOrders(_ *exchange.OrderCancellation) (exchange.CancelAllOrdersResponse, error) {
|
||||
cancelAllOrdersResponse := exchange.CancelAllOrdersResponse{
|
||||
OrderStatus: make(map[string]string),
|
||||
func (z *ZB) CancelAllOrders(_ *order.Cancel) (order.CancelAllResponse, error) {
|
||||
cancelAllOrdersResponse := order.CancelAllResponse{
|
||||
Status: make(map[string]string),
|
||||
}
|
||||
var allOpenOrders []Order
|
||||
for _, currency := range z.GetEnabledPairs(asset.Spot) {
|
||||
enabledPairs := z.GetEnabledPairs(asset.Spot)
|
||||
for x := range enabledPairs {
|
||||
// Limiting to 10 pages
|
||||
for i := 0; i < 10; i++ {
|
||||
openOrders, err := z.GetUnfinishedOrdersIgnoreTradeType(z.FormatExchangeCurrency(currency, asset.Spot).String(), 1, 10)
|
||||
for pageNumber := int64(0); pageNumber < 11; pageNumber++ {
|
||||
fCurr := z.FormatExchangeCurrency(enabledPairs[x], asset.Spot).String()
|
||||
openOrders, err := z.GetUnfinishedOrdersIgnoreTradeType(fCurr,
|
||||
pageNumber,
|
||||
10)
|
||||
if err != nil {
|
||||
return cancelAllOrdersResponse, err
|
||||
}
|
||||
@@ -417,10 +416,12 @@ func (z *ZB) CancelAllOrders(_ *exchange.OrderCancellation) (exchange.CancelAllO
|
||||
}
|
||||
}
|
||||
|
||||
for _, openOrder := range allOpenOrders {
|
||||
err := z.CancelExistingOrder(openOrder.ID, openOrder.Currency)
|
||||
for i := range allOpenOrders {
|
||||
err := z.CancelExistingOrder(allOpenOrders[i].ID,
|
||||
allOpenOrders[i].Currency)
|
||||
if err != nil {
|
||||
cancelAllOrdersResponse.OrderStatus[strconv.FormatInt(openOrder.ID, 10)] = err.Error()
|
||||
ID := strconv.FormatInt(allOpenOrders[i].ID, 10)
|
||||
cancelAllOrdersResponse.Status[ID] = err.Error()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -428,8 +429,8 @@ func (z *ZB) CancelAllOrders(_ *exchange.OrderCancellation) (exchange.CancelAllO
|
||||
}
|
||||
|
||||
// GetOrderInfo returns information on a current open order
|
||||
func (z *ZB) GetOrderInfo(orderID string) (exchange.OrderDetail, error) {
|
||||
var orderDetail exchange.OrderDetail
|
||||
func (z *ZB) GetOrderInfo(orderID string) (order.Detail, error) {
|
||||
var orderDetail order.Detail
|
||||
return orderDetail, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
@@ -477,13 +478,15 @@ func (z *ZB) 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 (z *ZB) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
func (z *ZB) GetActiveOrders(req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
var allOrders []Order
|
||||
for _, currency := range getOrdersRequest.Currencies {
|
||||
var pageNumber int64
|
||||
for x := range req.Currencies {
|
||||
// Limiting to 10 pages
|
||||
for i := 0; i < 10; i++ {
|
||||
resp, err := z.GetUnfinishedOrdersIgnoreTradeType(z.FormatExchangeCurrency(currency, asset.Spot).String(), pageNumber, 10)
|
||||
for pageNumber := int64(0); pageNumber < 11; pageNumber++ {
|
||||
fCurr := z.FormatExchangeCurrency(req.Currencies[x], asset.Spot).String()
|
||||
resp, err := z.GetUnfinishedOrdersIgnoreTradeType(fCurr,
|
||||
pageNumber,
|
||||
10)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -492,53 +495,51 @@ func (z *ZB) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([]exc
|
||||
}
|
||||
|
||||
allOrders = append(allOrders, resp...)
|
||||
pageNumber++
|
||||
}
|
||||
}
|
||||
|
||||
var orders []exchange.OrderDetail
|
||||
for _, order := range allOrders {
|
||||
symbol := currency.NewPairDelimiter(order.Currency,
|
||||
var orders []order.Detail
|
||||
for i := range allOrders {
|
||||
symbol := currency.NewPairDelimiter(allOrders[i].Currency,
|
||||
z.GetPairFormat(asset.Spot, false).Delimiter)
|
||||
orderDate := time.Unix(int64(order.TradeDate), 0)
|
||||
orderSide := orderSideMap[order.Type]
|
||||
orders = append(orders, exchange.OrderDetail{
|
||||
ID: fmt.Sprintf("%v", order.ID),
|
||||
Amount: order.TotalAmount,
|
||||
orderDate := time.Unix(int64(allOrders[i].TradeDate), 0)
|
||||
orderSide := orderSideMap[allOrders[i].Type]
|
||||
orders = append(orders, order.Detail{
|
||||
ID: fmt.Sprintf("%d", allOrders[i].ID),
|
||||
Amount: allOrders[i].TotalAmount,
|
||||
Exchange: z.Name,
|
||||
OrderDate: orderDate,
|
||||
Price: order.Price,
|
||||
Price: allOrders[i].Price,
|
||||
OrderSide: orderSide,
|
||||
CurrencyPair: symbol,
|
||||
})
|
||||
}
|
||||
|
||||
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks,
|
||||
getOrdersRequest.EndTicks)
|
||||
exchange.FilterOrdersBySide(&orders, getOrdersRequest.OrderSide)
|
||||
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
|
||||
// This function is not concurrency safe due to orderSide/orderType maps
|
||||
func (z *ZB) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
if getOrdersRequest.OrderSide == exchange.AnyOrderSide || getOrdersRequest.OrderSide == "" {
|
||||
func (z *ZB) GetOrderHistory(req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
if req.OrderSide == order.AnySide || req.OrderSide == "" {
|
||||
return nil, errors.New("specific order side is required")
|
||||
}
|
||||
|
||||
var allOrders []Order
|
||||
|
||||
var side int64
|
||||
if getOrdersRequest.OrderSide == exchange.BuyOrderSide {
|
||||
if req.OrderSide == order.Buy {
|
||||
side = 1
|
||||
}
|
||||
|
||||
for _, currency := range getOrdersRequest.Currencies {
|
||||
var pageNumber int64
|
||||
for x := range req.Currencies {
|
||||
// Limiting to 10 pages
|
||||
for i := 0; i < 10; i++ {
|
||||
resp, err := z.GetOrders(z.FormatExchangeCurrency(currency, asset.Spot).String(), pageNumber, side)
|
||||
for pageNumber := int64(0); pageNumber < 11; pageNumber++ {
|
||||
fCurr := z.FormatExchangeCurrency(req.Currencies[x], asset.Spot).String()
|
||||
resp, err := z.GetOrders(fCurr, pageNumber, side)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -548,28 +549,27 @@ func (z *ZB) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([]exc
|
||||
}
|
||||
|
||||
allOrders = append(allOrders, resp...)
|
||||
pageNumber++
|
||||
}
|
||||
}
|
||||
|
||||
var orders []exchange.OrderDetail
|
||||
for _, order := range allOrders {
|
||||
symbol := currency.NewPairDelimiter(order.Currency,
|
||||
var orders []order.Detail
|
||||
for i := range allOrders {
|
||||
symbol := currency.NewPairDelimiter(allOrders[i].Currency,
|
||||
z.GetPairFormat(asset.Spot, false).Delimiter)
|
||||
orderDate := time.Unix(int64(order.TradeDate), 0)
|
||||
orderSide := orderSideMap[order.Type]
|
||||
orders = append(orders, exchange.OrderDetail{
|
||||
ID: fmt.Sprintf("%v", order.ID),
|
||||
Amount: order.TotalAmount,
|
||||
orderDate := time.Unix(int64(allOrders[i].TradeDate), 0)
|
||||
orderSide := orderSideMap[allOrders[i].Type]
|
||||
orders = append(orders, order.Detail{
|
||||
ID: fmt.Sprintf("%d", allOrders[i].ID),
|
||||
Amount: allOrders[i].TotalAmount,
|
||||
Exchange: z.Name,
|
||||
OrderDate: orderDate,
|
||||
Price: order.Price,
|
||||
Price: allOrders[i].Price,
|
||||
OrderSide: orderSide,
|
||||
CurrencyPair: symbol,
|
||||
})
|
||||
}
|
||||
|
||||
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks, getOrdersRequest.EndTicks)
|
||||
order.FilterOrdersByTickRange(&orders, req.StartTicks, req.EndTicks)
|
||||
return orders, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user