mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-06 15:10:59 +00:00
Map exchange wrapper function "SubmitExchangeOrder" to exchange implementations (#211)
* Sets up Alphapoint and ANX wrappers to use exchange implementations of submit orders Creates const types for orderType and orderSides * Changes wrapper func SubmitExchangeOrder return type to string to account for GUID order ID responses * Adds binance and bitfinex new order wrapper support. Fixes alphapoint order wrapper. * Adds bitflyer type for exchange order. Adds bithumb and bitmex wrapper support for SubmitExchangeOrder * Fixes bitmex typo. Adds bitstamp, bittrex, coinbasePro, coinut SubmitExchangeOrder wrapper support * Maps exchange wrapper function 'SubmitExchangeOrder' to exchange methods for exmo, gateio, gemini, hitbtc, huobi, huobihadax and itbit * Maps exchange wrapper function 'SubmitExchangeOrder' to exchange methods for kraken, lakebtc, liqui, okcoin, okex, poloniex, wex, yobit and zb * Updates interface, fixes wrapper type mismatch and fixes tests from changed parameters * Adds generic support for SubmitExchangeOrder for localbitcoins_wrapper * Updates wrappers tests and submit order implementations for anx, binance, bitfinex, bitflyer (cannot test), bitmex, bitstamp * Fixes bitstamp tests * Adds tests for submitting orders with bittrex, btcmarkets, coinbasepro and coinut * Adds tests for exmo, gatio, gemini and hitbtc Makes adjustments where necessary * Adds tests and updates order implementations for huobi, huobiHadax, itbit, kraken, lakebtc, liqui, okcoin, okex, poloniex, wex, yobit and zb. Not all have been verified due to exchange issues * Fixes variable names and symbol usages * Fixes HitBTC order API implementation * Removes formatting code. Adds error handling for unsupported order types. Fixes typo * Fixes missed replace for new ToString function. Removes unused functions * Changes report of unknown withdrawal type with bitshift approximation. Improved code cov * Updates wrapper SubmitExchangeOrder return to use a fancy new SubmitOrderResponse struct type to clarify if an order submission is successful or not
This commit is contained in:
@@ -100,6 +100,10 @@ func (b *Bitstamp) Setup(exch config.ExchangeConfig) {
|
||||
b.BaseCurrencies = common.SplitStrings(exch.BaseCurrencies, ",")
|
||||
b.AvailablePairs = common.SplitStrings(exch.AvailablePairs, ",")
|
||||
b.EnabledPairs = common.SplitStrings(exch.EnabledPairs, ",")
|
||||
b.APIKey = exch.APIKey
|
||||
b.APISecret = exch.APISecret
|
||||
b.SetAPIKeys(exch.APIKey, exch.APISecret, b.ClientID, false)
|
||||
b.AuthenticatedAPISupport = true
|
||||
err := b.SetCurrencyPairFormat()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
@@ -612,5 +616,7 @@ func (b *Bitstamp) SendAuthenticatedHTTPRequest(path string, v2 bool, values url
|
||||
headers := make(map[string]string)
|
||||
headers["Content-Type"] = "application/x-www-form-urlencoded"
|
||||
|
||||
return b.SendPayload("POST", path, headers, strings.NewReader(values.Encode()), result, true, b.Verbose)
|
||||
encodedValues := values.Encode()
|
||||
readerValues := strings.NewReader(encodedValues)
|
||||
return b.SendPayload("POST", path, headers, readerValues, result, true, b.Verbose)
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/thrasher-/gocryptotrader/currency/pair"
|
||||
"github.com/thrasher-/gocryptotrader/currency/symbol"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
||||
|
||||
@@ -13,9 +14,10 @@ import (
|
||||
|
||||
// Please add your private keys and customerID for better tests
|
||||
const (
|
||||
apiKey = ""
|
||||
apiSecret = ""
|
||||
customerID = ""
|
||||
apiKey = ""
|
||||
apiSecret = ""
|
||||
customerID = ""
|
||||
canPlaceOrders = false
|
||||
)
|
||||
|
||||
var b Bitstamp
|
||||
@@ -47,9 +49,11 @@ func TestSetup(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error("Test Failed - Bitstamp Setup() init error")
|
||||
}
|
||||
bConfig.APIKey = apiKey
|
||||
bConfig.APISecret = apiSecret
|
||||
b.Setup(bConfig)
|
||||
|
||||
if !b.IsEnabled() || b.AuthenticatedAPISupport || b.RESTPollingDelay != time.Duration(10) ||
|
||||
if !b.IsEnabled() || b.RESTPollingDelay != time.Duration(10) ||
|
||||
b.Verbose || b.Websocket.IsEnabled() || len(b.BaseCurrencies) < 1 ||
|
||||
len(b.AvailablePairs) < 1 || len(b.EnabledPairs) < 1 {
|
||||
t.Error("Test Failed - Bitstamp Setup values not set correctly")
|
||||
@@ -248,7 +252,10 @@ func TestGetOpenOrders(t *testing.T) {
|
||||
|
||||
func TestGetOrderStatus(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if b.APIKey == "" || b.APISecret == "" ||
|
||||
b.APIKey == "Key" || b.APISecret == "Secret" {
|
||||
t.Skip()
|
||||
}
|
||||
_, err := b.GetOrderStatus(1337)
|
||||
if err == nil {
|
||||
t.Error("Test Failed - GetOpenOrders() error")
|
||||
@@ -275,7 +282,10 @@ func TestCancelAllOrders(t *testing.T) {
|
||||
|
||||
func TestPlaceOrder(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if b.APIKey == "" || b.APISecret == "" ||
|
||||
b.APIKey == "Key" || b.APISecret == "Secret" {
|
||||
t.Skip()
|
||||
}
|
||||
_, err := b.PlaceOrder("btcusd", 0.01, 1, true, true)
|
||||
if err == nil {
|
||||
t.Error("Test Failed - PlaceOrder() error")
|
||||
@@ -297,6 +307,10 @@ func TestGetWithdrawalRequests(t *testing.T) {
|
||||
|
||||
func TestCryptoWithdrawal(t *testing.T) {
|
||||
t.Parallel()
|
||||
if b.APIKey == "" || b.APISecret == "" ||
|
||||
b.APIKey == "Key" || b.APISecret == "Secret" {
|
||||
t.Skip()
|
||||
}
|
||||
|
||||
_, err := b.CryptoWithdrawal(0, "bla", "btc", "", true)
|
||||
if err == nil {
|
||||
@@ -323,8 +337,12 @@ func TestGetUnconfirmedBitcoinDeposits(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestTransferAccountBalance(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
t.Parallel()
|
||||
if b.APIKey == "" || b.APISecret == "" ||
|
||||
b.APIKey == "Key" || b.APISecret == "Secret" {
|
||||
t.Skip()
|
||||
}
|
||||
_, err := b.TransferAccountBalance(1, "", "", true)
|
||||
if err == nil {
|
||||
t.Error("Test Failed - TransferAccountBalance() error", err)
|
||||
@@ -346,3 +364,25 @@ func TestFormatWithdrawPermissions(t *testing.T) {
|
||||
t.Errorf("Expected: %s, Recieved: %s", expectedResult, withdrawPermissions)
|
||||
}
|
||||
}
|
||||
|
||||
// This will really really use the API to place an order
|
||||
// If you're going to test this, make sure you're willing to place real orders on the exchange
|
||||
func TestSubmitOrder(t *testing.T) {
|
||||
b.SetDefaults()
|
||||
TestSetup(t)
|
||||
|
||||
if b.APIKey == "" || b.APISecret == "" ||
|
||||
b.APIKey == "Key" || b.APISecret == "Secret" ||
|
||||
!canPlaceOrders {
|
||||
t.Skip()
|
||||
}
|
||||
var p = pair.CurrencyPair{
|
||||
Delimiter: "",
|
||||
FirstCurrency: symbol.BTC,
|
||||
SecondCurrency: symbol.USD,
|
||||
}
|
||||
response, err := b.SubmitExchangeOrder(p, exchange.Buy, exchange.Market, 1, 1, "clientId")
|
||||
if err != nil || !response.IsOrderPlaced {
|
||||
t.Errorf("Order failed to be placed: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package bitstamp
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -165,8 +166,21 @@ func (b *Bitstamp) GetExchangeHistory(p pair.CurrencyPair, assetType string) ([]
|
||||
}
|
||||
|
||||
// SubmitExchangeOrder submits a new order
|
||||
func (b *Bitstamp) SubmitExchangeOrder(p pair.CurrencyPair, side exchange.OrderSide, orderType exchange.OrderType, amount, price float64, clientID string) (int64, error) {
|
||||
return 0, errors.New("not yet implemented")
|
||||
func (b *Bitstamp) SubmitExchangeOrder(p pair.CurrencyPair, side exchange.OrderSide, orderType exchange.OrderType, amount, price float64, clientID string) (exchange.SubmitOrderResponse, error) {
|
||||
var submitOrderResponse exchange.SubmitOrderResponse
|
||||
buy := side == exchange.Buy
|
||||
market := orderType == exchange.Market
|
||||
response, err := b.PlaceOrder(p.Pair().String(), price, amount, buy, market)
|
||||
|
||||
if response.ID > 0 {
|
||||
submitOrderResponse.OrderID = fmt.Sprintf("%v", response.ID)
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
submitOrderResponse.IsOrderPlaced = true
|
||||
}
|
||||
|
||||
return submitOrderResponse, err
|
||||
}
|
||||
|
||||
// ModifyExchangeOrder will allow of changing orderbook placement and limit to
|
||||
|
||||
Reference in New Issue
Block a user