Wrapper update modify order (#222)

* Changed IBotExchange interface ModifyOrder function paramater and return value to exchange type for easier addition or retraction of variables.

* Function ModifyOrder for Binance not supported via API

* Change to unsupported function for exchange ZB

* Change to unsupported function for exchange Yobit

* Add modify order support for Poloniex

*  Change to unsupported function for exchange Okex

* Change to unsupported function for exchange Localbitcoins

* Change to unsupported function for exchange Liqui

* Change to unsupported function for exchange LakeBTC

* Change to unsupported function for exchange Kraken

* Change to unsupported function for exchange Itbit

* Change to unsupported function for exchange HuobiHadax

* Change to unsupported function for exchange Huobi

* Change to unsupported function for exchange HitBTC

* Change to unsupported function for exchange Gemini

* Change to unsupported function for exchange GateIO

* Change to unsupported function for exchange Exmo

* Change to unsupported function for exchange Coinut

* Change to unsupported function for exchange Coinbase

* Change to unsupported function for exchange BTCMarkets

* Change to unsupported function for exchange Bittrex

* Change to unsupported function for exchange Bitstamp

* Add modify order support for Bitmex

* Add verbose header information in request package

* Add modify order support for Bithumb exchange

* Change to unsupported function for exchange Bitflyer

* Change to unsupported function for exchange Bitfinex

*  Change to unsupported function for exchange ANX

* Change interface function signature

* Rm redundant code for authenticated requests in Bithumb

* Add error check if decimal values supplied for create or modifying an order on Bitmex

* Added test functions across the exchanges

* Rm comment for modify order on Alphapoint exchange

* Update tmpl file for exchange wrapper
This commit is contained in:
Ryan O'Hara-Reid
2018-12-20 16:31:17 +11:00
committed by Adrian Gallagher
parent 2993ae17cf
commit 7c3134f35b
66 changed files with 477 additions and 216 deletions

View File

@@ -2,6 +2,7 @@ package bithumb
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"log"
@@ -247,15 +248,8 @@ func (b *Bithumb) GetAccountInformation(currency string) (Account, error) {
val.Set("currency", currency)
}
err := b.SendAuthenticatedHTTPRequest(privateAccInfo, val, &response)
if err != nil {
return response, err
}
if response.Status != noError {
return response, errors.New(response.Message)
}
return response, nil
return response,
b.SendAuthenticatedHTTPRequest(privateAccInfo, val, &response)
}
// GetAccountBalance returns customer wallet information
@@ -279,10 +273,6 @@ func (b *Bithumb) GetAccountBalance(c string) (FullBalance, error) {
return fullBalance, err
}
if response.Status != noError {
return fullBalance, errors.New(response.Message)
}
// Added due to increasing of the usuable currencies on exchange, usually
// without notificatation, so we dont need to update structs later on
for tag, datum := range response.Data {
@@ -331,30 +321,16 @@ func (b *Bithumb) GetWalletAddress(currency string) (WalletAddressRes, error) {
params := url.Values{}
params.Set("currency", common.StringToUpper(currency))
err := b.SendAuthenticatedHTTPRequest(privateWalletAdd, params, &response)
if err != nil {
return response, err
}
if response.Status != noError {
return response, errors.New(response.Message)
}
return response, nil
return response,
b.SendAuthenticatedHTTPRequest(privateWalletAdd, params, &response)
}
// GetLastTransaction returns customer last transaction
func (b *Bithumb) GetLastTransaction() (LastTransactionTicker, error) {
response := LastTransactionTicker{}
err := b.SendAuthenticatedHTTPRequest(privateTicker, nil, &response)
if err != nil {
return response, err
}
if response.Status != noError {
return response, errors.New(response.Message)
}
return response, nil
return response,
b.SendAuthenticatedHTTPRequest(privateTicker, nil, &response)
}
// GetOrders returns order list
@@ -374,30 +350,16 @@ func (b *Bithumb) GetOrders(orderID, transactionType, count, after, currency str
params.Set("after", after)
params.Set("currency", common.StringToUpper(currency))
err := b.SendAuthenticatedHTTPRequest(privateOrders, params, &response)
if err != nil {
return response, err
}
if response.Status != noError {
return response, errors.New(response.Message)
}
return response, nil
return response,
b.SendAuthenticatedHTTPRequest(privateOrders, params, &response)
}
// GetUserTransactions returns customer transactions
func (b *Bithumb) GetUserTransactions() (UserTransactions, error) {
response := UserTransactions{}
err := b.SendAuthenticatedHTTPRequest(privateUserTrans, nil, &response)
if err != nil {
return response, err
}
if response.Status != noError {
return response, errors.New(response.Message)
}
return response, nil
return response,
b.SendAuthenticatedHTTPRequest(privateUserTrans, nil, &response)
}
// PlaceTrade executes a trade order
@@ -417,15 +379,24 @@ func (b *Bithumb) PlaceTrade(orderCurrency, transactionType string, units float6
params.Set("units", strconv.FormatFloat(units, 'f', -1, 64))
params.Set("price", strconv.FormatInt(price, 10))
err := b.SendAuthenticatedHTTPRequest(privatePlaceTrade, params, &response)
if err != nil {
return response, err
}
return response,
b.SendAuthenticatedHTTPRequest(privatePlaceTrade, params, &response)
}
if response.Status != noError {
return response, errors.New(response.Message)
}
return response, nil
// ModifyTrade modifies an order already on the exchange books
func (b *Bithumb) ModifyTrade(orderID, orderCurrency, transactionType string, units float64, price int64) (OrderPlace, error) {
response := OrderPlace{}
params := url.Values{}
params.Set("order_currency", common.StringToUpper(orderCurrency))
params.Set("Payment_currency", "KRW")
params.Set("type", common.StringToUpper(transactionType))
params.Set("units", strconv.FormatFloat(units, 'f', -1, 64))
params.Set("price", strconv.FormatInt(price, 10))
params.Set("order_id", orderID)
return response,
b.SendAuthenticatedHTTPRequest(privatePlaceTrade, params, &response)
}
// GetOrderDetails returns specific order details
@@ -442,15 +413,8 @@ func (b *Bithumb) GetOrderDetails(orderID, transactionType, currency string) (Or
params.Set("type", common.StringToUpper(transactionType))
params.Set("currency", common.StringToUpper(currency))
err := b.SendAuthenticatedHTTPRequest(privateOrderDetail, params, &response)
if err != nil {
return response, err
}
if response.Status != noError {
return response, errors.New(response.Message)
}
return response, nil
return response,
b.SendAuthenticatedHTTPRequest(privateOrderDetail, params, &response)
}
// CancelTrade cancels a customer purchase/sales transaction
@@ -466,15 +430,8 @@ func (b *Bithumb) CancelTrade(transactionType, orderID, currency string) (Action
params.Set("type", common.StringToUpper(transactionType))
params.Set("currency", common.StringToUpper(currency))
err := b.SendAuthenticatedHTTPRequest(privateCancelTrade, nil, &response)
if err != nil {
return response, err
}
if response.Status != noError {
return response, errors.New(response.Message)
}
return response, nil
return response,
b.SendAuthenticatedHTTPRequest(privateCancelTrade, nil, &response)
}
// WithdrawCrypto withdraws a customer currency to an address
@@ -494,15 +451,8 @@ func (b *Bithumb) WithdrawCrypto(address, destination, currency string, units fl
params.Set("currency", common.StringToUpper(currency))
params.Set("units", strconv.FormatFloat(units, 'f', -1, 64))
err := b.SendAuthenticatedHTTPRequest(privateBTCWithdraw, params, &response)
if err != nil {
return response, err
}
if response.Status != noError {
return response, errors.New(response.Message)
}
return response, nil
return response,
b.SendAuthenticatedHTTPRequest(privateBTCWithdraw, params, &response)
}
// RequestKRWDepositDetails returns Bithumb banking details for deposit
@@ -510,15 +460,8 @@ func (b *Bithumb) WithdrawCrypto(address, destination, currency string, units fl
func (b *Bithumb) RequestKRWDepositDetails() (KRWDeposit, error) {
response := KRWDeposit{}
err := b.SendAuthenticatedHTTPRequest(privateKRWDeposit, nil, &response)
if err != nil {
return response, err
}
if response.Status != noError {
return response, errors.New(response.Message)
}
return response, nil
return response,
b.SendAuthenticatedHTTPRequest(privateKRWDeposit, nil, &response)
}
// RequestKRWWithdraw allows a customer KRW withdrawal request
@@ -534,15 +477,8 @@ func (b *Bithumb) RequestKRWWithdraw(bank, account string, price int64) (ActionS
params.Set("account", account)
params.Set("price", strconv.FormatInt(price, 10))
err := b.SendAuthenticatedHTTPRequest(privateKRWWithdraw, params, &response)
if err != nil {
return response, err
}
if response.Status != noError {
return response, errors.New(response.Message)
}
return response, nil
return response,
b.SendAuthenticatedHTTPRequest(privateKRWWithdraw, params, &response)
}
// MarketBuyOrder initiates a buy order through available order books
@@ -557,15 +493,8 @@ func (b *Bithumb) MarketBuyOrder(currency string, units float64) (MarketBuy, err
params.Set("currency", common.StringToUpper(currency))
params.Set("units", strconv.FormatFloat(units, 'f', -1, 64))
err := b.SendAuthenticatedHTTPRequest(privateMarketBuy, params, &response)
if err != nil {
return response, err
}
if response.Status != noError {
return response, errors.New(response.Message)
}
return response, nil
return response,
b.SendAuthenticatedHTTPRequest(privateMarketBuy, params, &response)
}
// MarketSellOrder initiates a sell order through available order books
@@ -580,15 +509,8 @@ func (b *Bithumb) MarketSellOrder(currency string, units float64) (MarketSell, e
params.Set("currency", common.StringToUpper(currency))
params.Set("units", strconv.FormatFloat(units, 'f', -1, 64))
err := b.SendAuthenticatedHTTPRequest(privateMarketSell, params, &response)
if err != nil {
return response, err
}
if response.Status != noError {
return response, errors.New(response.Message)
}
return response, nil
return response,
b.SendAuthenticatedHTTPRequest(privateMarketSell, params, &response)
}
// SendHTTPRequest sends an unauthenticated HTTP request
@@ -615,7 +537,9 @@ func (b *Bithumb) SendAuthenticatedHTTPRequest(path string, params url.Values, r
params.Set("endpoint", path)
payload := params.Encode()
hmacPayload := path + string(0) + payload + string(0) + b.Nonce.String()
hmac := common.GetHMAC(common.HashSHA512, []byte(hmacPayload), []byte(b.APISecret))
hmac := common.GetHMAC(common.HashSHA512,
[]byte(hmacPayload),
[]byte(b.APISecret))
hmacStr := common.HexEncodeToString(hmac)
headers := make(map[string]string)
@@ -624,7 +548,34 @@ func (b *Bithumb) SendAuthenticatedHTTPRequest(path string, params url.Values, r
headers["Api-Nonce"] = b.Nonce.String()
headers["Content-Type"] = "application/x-www-form-urlencoded"
return b.SendPayload("POST", b.APIUrl+path, headers, bytes.NewBufferString(payload), result, true, b.Verbose)
var intermediary json.RawMessage
errCapture := struct {
Status string `json:"status"`
Message string `json:"message"`
}{}
err := b.SendPayload("POST",
b.APIUrl+path,
headers,
bytes.NewBufferString(payload),
&intermediary,
true,
b.Verbose)
if err != nil {
return err
}
err = common.JSONDecode(intermediary, &errCapture)
if err == nil {
if errCapture.Status != "" && errCapture.Status != "0000" {
return fmt.Errorf("SendAuthenticatedHTTPRequest error Code:%s Message:%s",
errCapture.Status,
errCode[errCapture.Status])
}
}
return common.JSONDecode(intermediary, result)
}
// GetFee returns an estimate of fee based on type of transaction
@@ -692,3 +643,14 @@ func getDepositFee(currency string, amount float64) float64 {
func getWithdrawalFee(currency string) float64 {
return WithdrawalFees[currency]
}
var errCode = map[string]string{
"5100": "Bad Request",
"5200": "Not Member",
"5300": "Invalid Apikey",
"5302": "Method Not Allowed",
"5400": "Database Fail",
"5500": "Invalid Parameter",
"5600": "CUSTOM NOTICE (상황별 에러 메시지 출력) usually means transaction not allowed",
"5900": "Unknown Error",
}

View File

@@ -6,7 +6,7 @@ import (
"github.com/thrasher-/gocryptotrader/config"
"github.com/thrasher-/gocryptotrader/currency/pair"
"github.com/thrasher-/gocryptotrader/currency/symbol"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges"
)
// Please supply your own keys here for due diligence testing
@@ -389,3 +389,15 @@ func TestGetAccountInfo(t *testing.T) {
}
}
}
func TestModifyOrder(t *testing.T) {
curr := pair.NewCurrencyPairFromString("BTCUSD")
_, err := b.ModifyOrder(exchange.ModifyOrder{OrderID: "1337",
Price: 100,
Amount: 1000,
OrderSide: exchange.Sell,
Currency: curr})
if err == nil {
t.Error("Test Failed - ModifyOrder() error")
}
}

View File

@@ -189,8 +189,18 @@ func (b *Bithumb) SubmitOrder(p pair.CurrencyPair, side exchange.OrderSide, orde
// ModifyOrder will allow of changing orderbook placement and limit to
// market conversion
func (b *Bithumb) ModifyOrder(orderID int64, action exchange.ModifyOrder) (int64, error) {
return 0, common.ErrNotYetImplemented
func (b *Bithumb) ModifyOrder(action exchange.ModifyOrder) (string, error) {
order, err := b.ModifyTrade(action.OrderID,
action.Currency.FirstCurrency.String(),
common.StringToLower(action.OrderSide.ToString()),
action.Amount,
int64(action.Price))
if err != nil {
return "", err
}
return order.Data[0].ContID, nil
}
// CancelOrder cancels an order by its corresponding ID number