mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-02 23:16:51 +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:
@@ -1,10 +1,12 @@
|
||||
package itbit
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"testing"
|
||||
|
||||
"github.com/thrasher-/gocryptotrader/config"
|
||||
"github.com/thrasher-/gocryptotrader/currency/pair"
|
||||
"github.com/thrasher-/gocryptotrader/currency/symbol"
|
||||
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||
)
|
||||
@@ -13,9 +15,10 @@ var i ItBit
|
||||
|
||||
// Please provide your own keys to do proper testing
|
||||
const (
|
||||
apiKey = ""
|
||||
apiSecret = ""
|
||||
clientID = ""
|
||||
apiKey = ""
|
||||
apiSecret = ""
|
||||
clientID = ""
|
||||
canPlaceOrders = false
|
||||
)
|
||||
|
||||
func TestSetDefaults(t *testing.T) {
|
||||
@@ -241,3 +244,26 @@ 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) {
|
||||
i.SetDefaults()
|
||||
TestSetup(t)
|
||||
i.Verbose = true
|
||||
|
||||
if i.APIKey == "" || i.APISecret == "" ||
|
||||
i.APIKey == "Key" || i.APISecret == "Secret" ||
|
||||
!canPlaceOrders {
|
||||
t.Skip(fmt.Sprintf("ApiKey: %s. Can place orders: %v", i.APIKey, canPlaceOrders))
|
||||
}
|
||||
var p = pair.CurrencyPair{
|
||||
Delimiter: "",
|
||||
FirstCurrency: symbol.BTC,
|
||||
SecondCurrency: symbol.USDT,
|
||||
}
|
||||
response, err := i.SubmitExchangeOrder(p, exchange.Buy, exchange.Limit, 1, 10, "hi")
|
||||
if err != nil || !response.IsOrderPlaced {
|
||||
t.Errorf("Order failed to be placed: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package itbit
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"strconv"
|
||||
"sync"
|
||||
@@ -129,8 +130,39 @@ func (i *ItBit) GetExchangeHistory(p pair.CurrencyPair, assetType string) ([]exc
|
||||
}
|
||||
|
||||
// SubmitExchangeOrder submits a new order
|
||||
func (i *ItBit) 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 (i *ItBit) SubmitExchangeOrder(p pair.CurrencyPair, side exchange.OrderSide, orderType exchange.OrderType, amount, price float64, clientID string) (exchange.SubmitOrderResponse, error) {
|
||||
var submitOrderResponse exchange.SubmitOrderResponse
|
||||
var wallet string
|
||||
|
||||
wallets, err := i.GetWallets(nil)
|
||||
if err != nil {
|
||||
return submitOrderResponse, err
|
||||
}
|
||||
|
||||
// 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 == p.FirstCurrency.String() && i.Balances[j].AvailableBalance >= amount {
|
||||
wallet = i.ID
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if wallet == "" {
|
||||
return submitOrderResponse, fmt.Errorf("No wallet found with currency: %s with amount >= %v", p.FirstCurrency.String(), amount)
|
||||
}
|
||||
|
||||
response, err := i.PlaceOrder(wallet, side.ToString(), orderType.ToString(), p.FirstCurrency.String(), amount, price, p.Pair().String(), "")
|
||||
|
||||
if response.ID != "" {
|
||||
submitOrderResponse.OrderID = 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