Skip to content
This repository has been archived by the owner on Jul 4, 2024. It is now read-only.

Commit

Permalink
move types
Browse files Browse the repository at this point in the history
  • Loading branch information
larscom committed Dec 2, 2023
1 parent 6f0bedc commit 43ea4ce
Show file tree
Hide file tree
Showing 16 changed files with 279 additions and 254 deletions.
3 changes: 2 additions & 1 deletion httpc/balance.go → bitv/balance.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package httpc
package bitv

import (
"github.com/goccy/go-json"

"github.com/larscom/go-bitvavo/v2/util"
)

Expand Down
3 changes: 3 additions & 0 deletions bitv/bitv.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package bitv

const zerof64 = float64(0)
22 changes: 22 additions & 0 deletions bitv/book.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package bitv

type Page struct {
// Bid / ask price.
Price float64 `json:"price"`

// Size of 0 means orders are no longer present at that price level, otherwise the returned size is the new total size on that price level.
Size float64 `json:"size"`
}

type Book struct {
// Integer which is increased by one for every update to the book. Useful for synchronizing. Resets to zero after restarting the matching engine.
Nonce int64 `json:"nonce"`

// Slice with all bids in the format [price, size], where an size of 0 means orders are no longer present at that price level,
// otherwise the returned size is the new total size on that price level.
Bids []Page `json:"bids"`

// Slice with all asks in the format [price, size], where an size of 0 means orders are no longer present at that price level,
// otherwise the returned size is the new total size on that price level.
Asks []Page `json:"asks"`
}
41 changes: 41 additions & 0 deletions bitv/candle.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package bitv

import (
"fmt"

"github.com/goccy/go-json"
"github.com/larscom/go-bitvavo/v2/util"
)

type Candle struct {
// Timestamp in unix milliseconds.
Timestamp int64 `json:"timestamp"`
Open float64 `json:"open"`
High float64 `json:"high"`
Low float64 `json:"low"`
Close float64 `json:"close"`
Volume float64 `json:"volume"`
}

func (c *Candle) UnmarshalJSON(bytes []byte) error {
var event [][]any

err := json.Unmarshal(bytes, &event)
if err != nil {
return err
}
if len(event) != 1 {
return fmt.Errorf("unexpected length: %d, expected: 1", len(event))
}

candle := event[0]

c.Timestamp = int64(candle[0].(float64))
c.Open = util.MustFloat64(candle[1].(string))
c.High = util.MustFloat64(candle[2].(string))
c.Low = util.MustFloat64(candle[3].(string))
c.Close = util.MustFloat64(candle[4].(string))
c.Volume = util.MustFloat64(candle[5].(string))

return nil
}
23 changes: 23 additions & 0 deletions bitv/fill.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package bitv

type Fill struct {
// The id of the order on which has been filled
OrderId string `json:"orderId"`
// The id of the returned fill
FillId string `json:"fillId"`
// The current timestamp in milliseconds since 1 Jan 1970
Timestamp int64 `json:"timestamp"`
// The amount in base currency for which the trade has been made
Amount float64 `json:"amount"`
// The side for the taker
// Enum: "buy" | "sell"
Side string `json:"side"`
// The price in quote currency for which the trade has been made
Price float64 `json:"price"`
// True for takers, false for makers
Taker bool `json:"taker"`
// The amount of fee that has been paid. Value is negative for rebates. Only available if settled is true
Fee float64 `json:"fee"`
// Currency in which the fee has been paid. Only available if settled is true
FeeCurrency string `json:"feeCurrency"`
}
78 changes: 78 additions & 0 deletions bitv/order.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package bitv

type Order struct {
Guid string `json:"guid"`

// The order id of the returned order.
OrderId string `json:"orderId"`

// Is a timestamp in milliseconds since 1 Jan 1970.
Created int64 `json:"created"`

// Is a timestamp in milliseconds since 1 Jan 1970.
Updated int64 `json:"updated"`

// The current status of the order.
// Enum: "new" | "awaitingTrigger" | "canceled" | "canceledAuction" | "canceledSelfTradePrevention" | "canceledIOC" | "canceledFOK" | "canceledMarketProtection" | "canceledPostOnly" | "filled" | "partiallyFilled" | "expired" | "rejected"
Status string `json:"status"`

// Side
// Enum: "buy" | "sell"
Side string `json:"side"`

// OrderType
// Enum: "limit" | "market"
OrderType string `json:"orderType"`

// Original amount.
Amount float64 `json:"amount"`

// Amount remaining (lower than 'amount' after fills).
AmountRemaining float64 `json:"amountRemaining"`

// The price of the order.
Price float64 `json:"price"`

// Amount of 'onHoldCurrency' that is reserved for this order. This is released when orders are canceled.
OnHold float64 `json:"onHold"`

// The currency placed on hold is the quote currency for sell orders and base currency for buy orders.
OnHoldCurrency string `json:"onHoldCurrency"`

// Only for stop orders: The current price used in the trigger. This is based on the triggerAmount and triggerType.
TriggerPrice float64 `json:"triggerPrice"`

// Only for stop orders: The value used for the triggerType to determine the triggerPrice.
TriggerAmount float64 `json:"triggerAmount"`

// Only for stop orders.
// Enum: "price"
TriggerType string `json:"triggerType"`

// Only for stop orders: The reference price used for stop orders.
// Enum: "lastTrade" | "bestBid" | "bestAsk" | "midPrice"
TriggerReference string `json:"triggerReference"`

// Only for limit orders: Determines how long orders remain active.
// Possible values: Good-Til-Canceled (GTC), Immediate-Or-Cancel (IOC), Fill-Or-Kill (FOK).
// GTC orders will remain on the order book until they are filled or canceled.
// IOC orders will fill against existing orders, but will cancel any remaining amount after that.
// FOK orders will fill against existing orders in its entirety, or will be canceled (if the entire order cannot be filled).
// Enum: "GTC" | "IOC" | "FOK"
TimeInForce string `json:"timeInForce"`

// Default: false
PostOnly bool `json:"postOnly"`

// Self trading is not allowed on Bitvavo. Multiple options are available to prevent this from happening.
// The default ‘decrementAndCancel’ decrements both orders by the amount that would have been filled, which in turn cancels the smallest of the two orders.
// ‘cancelOldest’ will cancel the entire older order and places the new order.
// ‘cancelNewest’ will cancel the order that is submitted.
// ‘cancelBoth’ will cancel both the current and the old order.
// Default: "decrementAndCancel"
// Enum: "decrementAndCancel" | "cancelOldest" | "cancelNewest" | "cancelBoth"
SelfTradePrevention string `json:"selfTradePrevention"`

// Whether this order is visible on the order book.
Visible bool `json:"visible"`
}
18 changes: 18 additions & 0 deletions bitv/ticker.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package bitv

type Ticker struct {
// The price of the best (highest) bid offer available, only sent when either bestBid or bestBidSize has changed.
BestBid float64 `json:"bestBid"`

// The size of the best (highest) bid offer available, only sent when either bestBid or bestBidSize has changed.
BestBidSize float64 `json:"bestBidSize"`

// The price of the best (lowest) ask offer available, only sent when either bestAsk or bestAskSize has changed.
BestAsk float64 `json:"bestAsk"`

// The size of the best (lowest) ask offer available, only sent when either bestAsk or bestAskSize has changed.
BestAskSize float64 `json:"bestAskSize"`

// The last price for which a trade has occurred, only sent when lastPrice has changed.
LastPrice float64 `json:"lastPrice"`
}
45 changes: 45 additions & 0 deletions bitv/ticker24h.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package bitv

type Ticker24h struct {
// The open price of the 24 hour period.
Open float64 `json:"open"`

// The highest price for which a trade occurred in the 24 hour period.
High float64 `json:"high"`

// The lowest price for which a trade occurred in the 24 hour period.
Low float64 `json:"low"`

// The last price for which a trade occurred in the 24 hour period.
Last float64 `json:"last"`

// The total volume of the 24 hour period in base currency.
Volume float64 `json:"volume"`

// The total volume of the 24 hour period in quote currency.
VolumeQuote float64 `json:"volumeQuote"`

// The best (highest) bid offer at the current moment.
Bid float64 `json:"bid"`

// The size of the best (highest) bid offer.
BidSize float64 `json:"bidSize"`

// The best (lowest) ask offer at the current moment.
Ask float64 `json:"ask"`

// The size of the best (lowest) ask offer.
AskSize float64 `json:"askSize"`

// Timestamp in unix milliseconds.
Timestamp int64 `json:"timestamp"`

// Start timestamp in unix milliseconds.
StartTimestamp int64 `json:"startTimestamp"`

// Open timestamp in unix milliseconds.
OpenTimestamp int64 `json:"openTimestamp"`

// Close timestamp in unix milliseconds.
CloseTimestamp int64 `json:"closeTimestamp"`
}
19 changes: 19 additions & 0 deletions bitv/trade.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package bitv

type Trade struct {
// The trade ID of the returned trade (UUID).
Id string `json:"id"`

// The amount in base currency for which the trade has been made.
Amount float64 `json:"amount"`

// The price in quote currency for which the trade has been made.
Price float64 `json:"price"`

// The side for the taker.
// Enum: "buy" | "sell"
Side string `json:"side"`

// Timestamp in unix milliseconds.
Timestamp int64 `json:"timestamp"`
}
8 changes: 5 additions & 3 deletions httpc/httpclientauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package httpc

import (
"fmt"

"github.com/larscom/go-bitvavo/v2/bitv"
)

type HttpClientAuth interface {
// GetBalance returns the balance on the account
GetBalance() ([]Balance, error)
GetBalance() ([]bitv.Balance, error)

// GetAccount returns generic information about your account
GetAccount() (any, error)
Expand All @@ -30,8 +32,8 @@ func newHttpClientAuth(updateRateLimit func(int), config *authConfig) *httpClien
}
}

func (c *httpClientAuth) GetBalance() ([]Balance, error) {
return httpGet[[]Balance](fmt.Sprintf("%s/balance", httpUrl), c.updateRateLimit, c.config)
func (c *httpClientAuth) GetBalance() ([]bitv.Balance, error) {
return httpGet[[]bitv.Balance](fmt.Sprintf("%s/balance", httpUrl), c.updateRateLimit, c.config)
}

func (c *httpClientAuth) GetAccount() (any, error) {
Expand Down
Loading

0 comments on commit 43ea4ce

Please sign in to comment.