Skip to content

Commit

Permalink
Added HTTP Exchange support for DWVX.
Browse files Browse the repository at this point in the history
  • Loading branch information
thrasher- committed May 31, 2015
1 parent f30e0b3 commit 552dca5
Show file tree
Hide file tree
Showing 6 changed files with 287 additions and 50 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ A cryptocurrency trading bot supporting multiple exchanges written in Golang.

| Exchange | REST API | Streaming API | FIX API |
|----------|------|-----------|-----|
| Alphapoint | Yes | No | NA |
| ANXPRO | Yes | No | NA |
| Bitfinex | Yes | NA | NA |
| Bitstamp | Yes | Yes | NA |
Expand All @@ -14,6 +15,7 @@ A cryptocurrency trading bot supporting multiple exchanges written in Golang.
| BTCMarkets | Yes | NA | NA |
| Coinbase | Yes | Yes | No|
| Cryptsy | Yes | Yes | NA|
| DWVX | Yes | No | NA |
| Huobi | Yes | Yes |No
| ItBit | Yes | NA | NA |
| Kraken | Yes | NA | NA
Expand Down
120 changes: 70 additions & 50 deletions alphapointhttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,22 @@ type AlphapointProducts struct {
RejectReason string `json:"rejectReason"`
}

type AlphapointUserInfo struct {
UserInfoKVP []struct {
Key string `json:"key"`
Value string `json:"value"`
} `json:"userInfoKVP"`
IsAccepted bool `json:"isAccepted"`
RejectReason string `json:"rejectReason"`
}

type AlphapointAccountInfo struct {
Currencies []struct {
Name string `json:"name"`
Balance int `json:"balance"`
Hold int `json:"hold"`
} `json:"currencies"`
Productpairs []struct {
ProductPairs []struct {
ProductPairName string `json:"productPairName"`
ProductPairCode int `json:"productPairCode"`
TradeCount int `json:"tradeCount"`
Expand All @@ -141,18 +150,30 @@ type AlphapointAccountInfo struct {
}

type AlphapointOrder struct {
ServerOrderID int64 `json:"ServerOrderId"`
AccountID int `json:"AccountId"`
Price float64 `json:"price"`
QuantityTotal float64 `json:"QtyTotal"`
QuantityRemaining float64 `json:"QtyRemaining"`
ReceiveTime int64 `json:"ReceiveTime"`
Side int `json:"side"`
Serverorderid int `json:"ServerOrderId"`
AccountID int `json:"AccountId"`
Price int `json:"Price"`
QtyTotal int `json:"QtyTotal"`
QtyRemaining int `json:"QtyRemaining"`
ReceiveTime int64 `json:"ReceiveTime"`
Side int `json:"Side"`
}

type AlphapointOrderInfo struct {
type AlphapointOpenOrders struct {
Instrument string `json:"ins"`
Orders []AlphapointOrder `json:"openOrders"`
Openorders []AlphapointOrder `json:"openOrders"`
}

type AlphapointOrderInfo struct {
OpenOrders []AlphapointOpenOrders `json:"openOrdersInfo"`
IsAccepted bool `json:"isAccepted"`
DateTimeUTC int64 `json:"dateTimeUtc"`
RejectReason string `json:"rejectReason"`
}

type AlphapointDepositAddresses struct {
Name string `json:"name"`
DepositAddress string `json:"depositAddress"`
}

func (a *Alphapoint) SetDefaults() {
Expand Down Expand Up @@ -276,12 +297,13 @@ func (a *Alphapoint) CreateAccount(firstName, lastName, email, phone, password s
return nil
}

func (a *Alphapoint) GetUserInfo() error {
err := a.SendAuthenticatedHTTPRequest("POST", ALPHAPOINT_USERINFO, map[string]interface{}{}, nil)
func (a *Alphapoint) GetUserInfo() (AlphapointUserInfo, error) {
response := AlphapointUserInfo{}
err := a.SendAuthenticatedHTTPRequest("POST", ALPHAPOINT_USERINFO, map[string]interface{}{}, &response)
if err != nil {
return err
return AlphapointUserInfo{}, err
}
return nil
return response, nil
}

func (a *Alphapoint) GetAccountInfo() (AlphapointAccountInfo, error) {
Expand Down Expand Up @@ -313,21 +335,22 @@ func (a *Alphapoint) GetAccountTrades(symbol string, startIndex, count int) (Alp
return response, nil
}

func (a *Alphapoint) GetDepositAddresses() error {
func (a *Alphapoint) GetDepositAddresses() ([]AlphapointDepositAddresses, error) {
type Response struct {
Addresses []AlphapointDepositAddresses
IsAccepted bool `json:"isAccepted"`
RejectReason string `json:"rejectReason"`
}

response := Response{}
err := a.SendAuthenticatedHTTPRequest("POST", ALPHAPOINT_DEPOSIT_ADDRESSES, map[string]interface{}{}, &response)
if err != nil {
return err
return nil, err
}
if !response.IsAccepted {
return errors.New(response.RejectReason)
return nil, errors.New(response.RejectReason)
}
return nil
return response.Addresses, nil
}

func (a *Alphapoint) WithdrawCoins(symbol, product string, amount float64, address string) error {
Expand Down Expand Up @@ -358,15 +381,15 @@ func (a *Alphapoint) CreateOrder(symbol, side string, orderType int, quantity, p
request := make(map[string]interface{})
request["ins"] = symbol
request["side"] = side
request["orderType"] = "0"
request["orderType"] = orderType
request["qty"] = strconv.FormatFloat(quantity, 'f', 8, 64)
request["px"] = strconv.FormatFloat(price, 'f', 2, 64)

type Response struct {
IsAccepted bool `json:"isAccepted"`
RejectReason string `json:"rejectReason"`
DateTimeUTC int64 `json:"dateTimeUtc"`
OrderID int64 `json:"serverOrderId,string"`
ServerOrderID int64 `json:"serverOrderId"`
DateTimeUTC float64 `json:"dateTimeUtc"`
IsAccepted bool `json:"isAccepted"`
RejectReason string `json:"rejectReason"`
}

response := Response{}
Expand All @@ -378,7 +401,7 @@ func (a *Alphapoint) CreateOrder(symbol, side string, orderType int, quantity, p
if !response.IsAccepted {
return 0, errors.New(response.RejectReason)
}
return response.OrderID, nil
return response.ServerOrderID, nil
}

func (a *Alphapoint) ModifyOrder(symbol string, OrderID, action int64) (int64, error) {
Expand All @@ -388,10 +411,11 @@ func (a *Alphapoint) ModifyOrder(symbol string, OrderID, action int64) (int64, e
request["modifyAction"] = action

type Response struct {
IsAccepted bool `json:"isAccepted"`
RejectReason string `json:"rejectReason"`
DateTimeUTC int64 `json:"dateTimeUtc"`
OrderID int64 `json:"serverOrderId,string"`
ModifyOrderID int64 `json:"modifyOrderId"`
ServerOrderID int64 `json:"serverOrderId"`
DateTimeUTC float64 `json:"dateTimeUtc"`
IsAccepted bool `json:"isAccepted"`
RejectReason string `json:"rejectReason"`
}

response := Response{}
Expand All @@ -403,7 +427,7 @@ func (a *Alphapoint) ModifyOrder(symbol string, OrderID, action int64) (int64, e
if !response.IsAccepted {
return 0, errors.New(response.RejectReason)
}
return response.OrderID, nil
return response.ModifyOrderID, nil
}

func (a *Alphapoint) CancelOrder(symbol string, OrderID int64) (int64, error) {
Expand All @@ -412,10 +436,11 @@ func (a *Alphapoint) CancelOrder(symbol string, OrderID int64) (int64, error) {
request["serverOrderId"] = OrderID

type Response struct {
IsAccepted bool `json:"isAccepted"`
RejectReason string `json:"rejectReason"`
DateTimeUTC int64 `json:"dateTimeUtc"`
OrderID int64 `json:"serverOrderId,string"`
CancelOrderID int64 `json:"cancelOrderId"`
ServerOrderID int64 `json:"serverOrderId"`
DateTimeUTC float64 `json:"dateTimeUtc"`
IsAccepted bool `json:"isAccepted"`
RejectReason string `json:"rejectReason"`
}

response := Response{}
Expand All @@ -427,7 +452,7 @@ func (a *Alphapoint) CancelOrder(symbol string, OrderID int64) (int64, error) {
if !response.IsAccepted {
return 0, errors.New(response.RejectReason)
}
return response.OrderID, nil
return response.CancelOrderID, nil
}

func (a *Alphapoint) CancelAllOrders(symbol string) error {
Expand All @@ -451,38 +476,32 @@ func (a *Alphapoint) CancelAllOrders(symbol string) error {
return nil
}

func (a *Alphapoint) GetOrders() (AlphapointOrderInfo, error) {
type Response struct {
Orders AlphapointOrderInfo `json:"openOrdersInfo"`
IsAccepted bool `json:"isAccepted"`
RejectReason string `json:"rejectReason"`
}

response := Response{}
func (a *Alphapoint) GetOrders() ([]AlphapointOpenOrders, error) {
response := AlphapointOrderInfo{}
err := a.SendAuthenticatedHTTPRequest("POST", ALPHAPOINT_OPEN_ORDERS, map[string]interface{}{}, &response)
if err != nil {
return AlphapointOrderInfo{}, err
return nil, err
}

if !response.IsAccepted {
return AlphapointOrderInfo{}, errors.New(response.RejectReason)
return nil, errors.New(response.RejectReason)
}
return response.Orders, nil
return response.OpenOrders, nil
}

func (a *Alphapoint) GetOrderFee(symbol, side string, quantity, price float64) (float64, error) {
type Response struct {
IsAccepted bool `json:"isAccepted"`
RejectReason string `json:"rejectReason"`
Fee float64 `json:"fee,string"`
Fee float64 `json:"fee"`
FeeProduct string `json:"feeProduct"`
}

request := make(map[string]interface{})
request["ins"] = symbol
request["side"] = side
request["qty"] = strconv.FormatFloat(quantity, 'f', 8, 64)
request["px"] = strconv.FormatFloat(price, 'f', 2, 64)
request["qty"] = strconv.FormatFloat(quantity, 'f', -1, 64)
request["px"] = strconv.FormatFloat(price, 'f', -1, 64)

response := Response{}
err := a.SendAuthenticatedHTTPRequest("POST", ALPHAPOINT_ORDER_FEE, request, &response)
Expand Down Expand Up @@ -524,9 +543,10 @@ func (a *Alphapoint) SendAuthenticatedHTTPRequest(method, path string, data map[
headers := make(map[string]string)
headers["Content-Type"] = "application/json"
data["apiKey"] = a.APIKey
nonce := strconv.FormatInt(time.Now().Unix(), 10)
nonce := time.Now().UnixNano()
nonceStr := strconv.FormatInt(nonce, 10)
data["apiNonce"] = nonce
hmac := GetHMAC(HASH_SHA256, []byte(nonce+a.UserID+a.APIKey), []byte(a.APISecret))
hmac := GetHMAC(HASH_SHA256, []byte(nonceStr+a.UserID+a.APIKey), []byte(a.APISecret))
data["apiSig"] = StringToUpper(HexEncodeToString(hmac))
path = fmt.Sprintf("%s/ajax/v%s/%s", a.APIUrl, ALPHAPOINT_API_VERSION, path)
PayloadJson, err := JSONEncode(data)
Expand Down
14 changes: 14 additions & 0 deletions config_example.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,20 @@
"EnabledPairs": "BTCUSD,LTCUSD,DASHBTC,DOGEBTC",
"BaseCurrencies": "USD"
},
{
"Name": "DWVX",
"Enabled": true,
"Verbose": false,
"Websocket": false,
"RESTPollingDelay": 10,
"AuthenticatedAPISupport": false,
"APIKey": "Key",
"APISecret": "Secret",
"ClientID": "ClientID",
"AvailablePairs": "BTCAUD",
"EnabledPairs": "BTCAUD",
"BaseCurrencies": "AUD"
},
{
"Name": "Huobi",
"Enabled": true,
Expand Down
Loading

0 comments on commit 552dca5

Please sign in to comment.