Skip to content

Commit

Permalink
update readme, enums
Browse files Browse the repository at this point in the history
  • Loading branch information
larscom committed Jul 20, 2024
1 parent 1c45b85 commit ee43f5c
Show file tree
Hide file tree
Showing 17 changed files with 157 additions and 145 deletions.
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,16 @@ For each event on the Bitvavo platform there is a listener available. A listener
- TradesListener

```go
package main

import "github.com/larscom/bitvavo-go/pkg/bitvavo"

func main() {
// listen for candle (public) events
listener := bitvavo.NewCandlesListener()
defer listener.Close()

chn, err := listener.Subscribe([]string{"ETH-EUR"}, []bitvavo.Interval{bitvavo.INTERVAL_1M})
chn, err := listener.Subscribe([]string{"ETH-EUR"}, []bitvavo.Interval{bitvavo.Interval1m})
if err != nil {
panic(err)
}
Expand All @@ -76,6 +78,8 @@ func main() {
- FillListener

```go
package main

import "github.com/larscom/bitvavo-go/pkg/bitvavo"

func main() {
Expand Down Expand Up @@ -103,17 +107,19 @@ func main() {
It's possible to create your own wrapper arround the websocket and listen to multiple events at the same time.

```go
package main

import "github.com/larscom/bitvavo-go/pkg/bitvavo"

func main() {
onMessage := func(data bitvavo.WebSocketEventData, err error) {
if err != nil {
// oh no error!
} else if data.Event == bitvavo.EVENT_BOOK {
} else if data.Event == bitvavo.EventBook {
// decode into Book
var book bitvavo.Book
data.Decode(&book)
} else if data.Event == bitvavo.EVENT_CANDLE {
} else if data.Event == bitvavo.EventCandle {
// decode into Candle
var candle bitvavo.Candle
data.Decode(&candle)
Expand All @@ -139,6 +145,8 @@ If you need both private and public endpoints you can create a private http clie
### Private and Public endpoints

```go
package main

import "github.com/larscom/bitvavo-go/pkg/bitvavo"

func main() {
Expand All @@ -157,6 +165,8 @@ func main() {
### Public endpoints only

```go
package main

import "github.com/larscom/bitvavo-go/pkg/bitvavo"

func main() {
Expand All @@ -177,6 +187,8 @@ func main() {
Some endpoints have additional params which you can provide.

```go
package main

import "github.com/larscom/bitvavo-go/pkg/bitvavo"

func main() {
Expand Down
2 changes: 1 addition & 1 deletion example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func main() {

tradingMarkets := make([]string, 0)
for _, market := range markets {
if market.Status == bitvavo.MARKET_STATUS_TRADING {
if market.Status == bitvavo.MarketStatusTrading {
tradingMarkets = append(tradingMarkets, market.Market)
}
}
Expand Down
20 changes: 10 additions & 10 deletions pkg/bitvavo/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ import (
type DepositStatus enum.Member[string]

var (
depositStatus = enum.NewBuilder[string, DepositStatus]()
DEPOSIT_STATUS_TRADING = depositStatus.Add(DepositStatus{"OK"})
DEPOSIT_STATUS_HALTED = depositStatus.Add(DepositStatus{"MAINTENANCE"})
DEPOSIT_STATUS_AUCTION = depositStatus.Add(DepositStatus{"DELISTED"})
depositStatuses = depositStatus.Enum()
depositStatus = enum.NewBuilder[string, DepositStatus]()
DepositStatusTrading = depositStatus.Add(DepositStatus{"OK"})
DepositStatusHalted = depositStatus.Add(DepositStatus{"MAINTENANCE"})
DepositStatusAuction = depositStatus.Add(DepositStatus{"DELISTED"})
depositStatuses = depositStatus.Enum()
)

type WithdrawalStatus enum.Member[string]

var (
withdrawalStatus = enum.NewBuilder[string, WithdrawalStatus]()
WITHDRAWAL_STATUS_TRADING = withdrawalStatus.Add(WithdrawalStatus{"OK"})
WITHDRAWAL_STATUS_HALTED = withdrawalStatus.Add(WithdrawalStatus{"MAINTENANCE"})
WITHDRAWAL_STATUS_AUCTION = withdrawalStatus.Add(WithdrawalStatus{"DELISTED"})
withdrawalStatuses = withdrawalStatus.Enum()
withdrawalStatus = enum.NewBuilder[string, WithdrawalStatus]()
WithdrawalStatusTrading = withdrawalStatus.Add(WithdrawalStatus{"OK"})
WithdrawalStatusHalted = withdrawalStatus.Add(WithdrawalStatus{"MAINTENANCE"})
WithdrawalStatusAuction = withdrawalStatus.Add(WithdrawalStatus{"DELISTED"})
withdrawalStatuses = withdrawalStatus.Enum()
)

type Asset struct {
Expand Down
6 changes: 3 additions & 3 deletions pkg/bitvavo/book_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func NewBookListener() Listener[BookEvent] {
chn: chn,
rchn: rchn,
once: new(sync.Once),
channel: CHANNEL_BOOK,
channel: ChannelBook,
}

ctx, cancel := context.WithCancel(context.Background())
Expand Down Expand Up @@ -75,7 +75,7 @@ func (l *BookListener) Close() error {
func (l *BookListener) onMessage(data WebSocketEventData, err error) {
if err != nil {
l.chn <- BookEvent{Error: err}
} else if data.Event == EVENT_SUBSCRIBED || data.Event == EVENT_UNSUBSCRIBED {
} else if data.Event == EventSubscribed || data.Event == EventUnsubscribed {
var subscribed Subscribed
if err := data.Decode(&subscribed); err != nil {
l.chn <- BookEvent{Error: err}
Expand All @@ -87,7 +87,7 @@ func (l *BookListener) onMessage(data WebSocketEventData, err error) {
l.chn <- BookEvent{Error: ErrExpectedChannel(l.channel)}
}
}
} else if data.Event == EVENT_BOOK {
} else if data.Event == EventBook {
var book Book
l.chn <- BookEvent{Value: book, Error: data.Decode(&book)}
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/bitvavo/candles_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func NewCandlesListener() *CandlesListener {
chn: chn,
rchn: rchn,
once: new(sync.Once),
channel: CHANNEL_CANDLES,
channel: ChannelCandles,
}

ctx, cancel := context.WithCancel(context.Background())
Expand Down Expand Up @@ -78,7 +78,7 @@ func (l *CandlesListener) Close() error {
func (l *CandlesListener) onMessage(data WebSocketEventData, err error) {
if err != nil {
l.chn <- CandleEvent{Error: err}
} else if data.Event == EVENT_SUBSCRIBED || data.Event == EVENT_UNSUBSCRIBED {
} else if data.Event == EventSubscribed || data.Event == EventUnsubscribed {
var subscribed Subscribed
if err := data.Decode(&subscribed); err != nil {
l.chn <- CandleEvent{Error: err}
Expand All @@ -96,7 +96,7 @@ func (l *CandlesListener) onMessage(data WebSocketEventData, err error) {
l.chn <- CandleEvent{Error: ErrExpectedChannel(l.channel)}
}
}
} else if data.Event == EVENT_CANDLE {
} else if data.Event == EventCandle {
var candle Candle
l.chn <- CandleEvent{Value: candle, Error: data.Decode(&candle)}
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/bitvavo/fill_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func NewFillListener(apiKey, apiSecret string) Listener[FillEvent] {
chn: chn,
rchn: rchn,
once: new(sync.Once),
channel: CHANNEL_ACCOUNT,
channel: ChannelAccount,
},
}

Expand Down Expand Up @@ -90,14 +90,14 @@ func (l *FillListener) Close() error {
func (l *FillListener) onMessage(data WebSocketEventData, err error) {
if err != nil {
l.chn <- FillEvent{Error: err}
} else if data.Event == EVENT_AUTHENTICATE {
} else if data.Event == EventAuthenticate {
var auth Authenticate
if err := data.Decode(&auth); err != nil {
l.chn <- FillEvent{Error: err}
} else {
l.authchn <- auth.Authenticated
}
} else if data.Event == EVENT_SUBSCRIBED || data.Event == EVENT_UNSUBSCRIBED {
} else if data.Event == EventSubscribed || data.Event == EventUnsubscribed {
var subscribed Subscribed
if err := data.Decode(&subscribed); err != nil {
l.chn <- FillEvent{Error: err}
Expand All @@ -109,7 +109,7 @@ func (l *FillListener) onMessage(data WebSocketEventData, err error) {
l.chn <- FillEvent{Error: ErrExpectedChannel(l.channel)}
}
}
} else if data.Event == EVENT_FILL {
} else if data.Event == EventFill {
var fill Fill
l.chn <- FillEvent{Value: fill, Error: data.Decode(&fill)}
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/bitvavo/market.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (
type MarketStatus enum.Member[string]

var (
marketStatus = enum.NewBuilder[string, MarketStatus]()
MARKET_STATUS_TRADING = marketStatus.Add(MarketStatus{"trading"})
MARKET_STATUS_HALTED = marketStatus.Add(MarketStatus{"halted"})
MARKET_STATUS_AUCTION = marketStatus.Add(MarketStatus{"auction"})
marketStatuses = marketStatus.Enum()
marketStatus = enum.NewBuilder[string, MarketStatus]()
MarketStatusTrading = marketStatus.Add(MarketStatus{"trading"})
MarketStatusHalted = marketStatus.Add(MarketStatus{"halted"})
MarketStatusAuction = marketStatus.Add(MarketStatus{"auction"})
marketStatuses = marketStatus.Enum()
)

type Market struct {
Expand Down
92 changes: 46 additions & 46 deletions pkg/bitvavo/order.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,77 +53,77 @@ func (o *OrderParams) Params() url.Values {
type OrderStatus enum.Member[string]

var (
orderStatus = enum.NewBuilder[string, OrderStatus]()
ORDER_STATUS_NEW = orderStatus.Add(OrderStatus{"new"})
ORDER_STATUS_AWAITING_TRIGGER = orderStatus.Add(OrderStatus{"awaitingTrigger"})
ORDER_STATUS_CANCELED = orderStatus.Add(OrderStatus{"canceled"})
ORDER_STATUS_CANCELED_AUCTION = orderStatus.Add(OrderStatus{"canceledAuction"})
ORDER_STATUS_CANCELED_STP = orderStatus.Add(OrderStatus{"canceledSelfTradePrevention"})
ORDER_STATUS_CANCELED_IOC = orderStatus.Add(OrderStatus{"canceledIOC"})
ORDER_STATUS_CANCELED_FOK = orderStatus.Add(OrderStatus{"canceledFOK"})
ORDER_STATUS_CANCELED_MP = orderStatus.Add(OrderStatus{"canceledMarketProtection"})
ORDER_STATUS_CANCELED_PO = orderStatus.Add(OrderStatus{"canceledPostOnly"})
ORDER_STATUS_FILLED = orderStatus.Add(OrderStatus{"filled"})
ORDER_STATUS_PARTIALLY_FILLED = orderStatus.Add(OrderStatus{"partiallyFilled"})
ORDER_STATUS_EXPIRED = orderStatus.Add(OrderStatus{"expired"})
ORDER_STATUS_REJECTED = orderStatus.Add(OrderStatus{"rejected"})
orderStatuses = orderStatus.Enum()
orderStatus = enum.NewBuilder[string, OrderStatus]()
OrderStatusNew = orderStatus.Add(OrderStatus{"new"})
OrderStatusAwaitingTrigger = orderStatus.Add(OrderStatus{"awaitingTrigger"})
OrderStatusCanceled = orderStatus.Add(OrderStatus{"canceled"})
OrderStatusCanceledAuction = orderStatus.Add(OrderStatus{"canceledAuction"})
OrderStatusCanceledStp = orderStatus.Add(OrderStatus{"canceledSelfTradePrevention"})
OrderStatusCanceledIoc = orderStatus.Add(OrderStatus{"canceledIOC"})
OrderStatusCanceledFok = orderStatus.Add(OrderStatus{"canceledFOK"})
OrderStatusCanceledMp = orderStatus.Add(OrderStatus{"canceledMarketProtection"})
OrderStatusCanceledPo = orderStatus.Add(OrderStatus{"canceledPostOnly"})
OrderStatusFilled = orderStatus.Add(OrderStatus{"filled"})
OrderStatusPartiallyFilled = orderStatus.Add(OrderStatus{"partiallyFilled"})
OrderStatusExpired = orderStatus.Add(OrderStatus{"expired"})
OrderStatusRejected = orderStatus.Add(OrderStatus{"rejected"})
orderStatuses = orderStatus.Enum()
)

type OrderType enum.Member[string]

var (
orderType = enum.NewBuilder[string, OrderType]()
ORDER_TYPE_MARKET = orderType.Add(OrderType{"market"})
ORDER_TYPE_LIMIT = orderType.Add(OrderType{"limit"})
ORDER_TYPE_STOP_LOSS = orderType.Add(OrderType{"stopLoss"})
ORDER_TYPE_STOP_LOSS_LIMIT = orderType.Add(OrderType{"stopLossLimit"})
ORDER_TYPE_TAKE_PROFIT = orderType.Add(OrderType{"takeProfit"})
ORDER_TYPE_TAKE_PROFIT_LIMIT = orderType.Add(OrderType{"takeProfitLimit"})
orderTypes = orderType.Enum()
orderType = enum.NewBuilder[string, OrderType]()
OrderTypeMarket = orderType.Add(OrderType{"market"})
OrderTypeLimit = orderType.Add(OrderType{"limit"})
OrderTypeStopLoss = orderType.Add(OrderType{"stopLoss"})
OrderTypeStopLossLimit = orderType.Add(OrderType{"stopLossLimit"})
OrderTypeTakeProfit = orderType.Add(OrderType{"takeProfit"})
OrderTypeTakeProfitLimit = orderType.Add(OrderType{"takeProfitLimit"})
orderTypes = orderType.Enum()
)

type OrderTriggerType enum.Member[string]

var (
orderTriggerType = enum.NewBuilder[string, OrderTriggerType]()
ORDER_TRIGGER_TYPE_DEFAULT = ORDER_TRIGGER_TYPE_PRICE
ORDER_TRIGGER_TYPE_PRICE = orderTriggerType.Add(OrderTriggerType{"price"})
orderTriggerTypes = orderTriggerType.Enum()
orderTriggerType = enum.NewBuilder[string, OrderTriggerType]()
OrderTriggerTypeDefault = OrderTriggerTypePrice
OrderTriggerTypePrice = orderTriggerType.Add(OrderTriggerType{"price"})
orderTriggerTypes = orderTriggerType.Enum()
)

type OrderTriggerRef enum.Member[string]

var (
orderTriggerRef = enum.NewBuilder[string, OrderTriggerRef]()
ORDER_TRIGGER_REF_LAST_TRADE = orderTriggerRef.Add(OrderTriggerRef{"lastTrade"})
ORDER_TRIGGER_REF_BEST_BID = orderTriggerRef.Add(OrderTriggerRef{"bestBid"})
ORDER_TRIGGER_REF_BEST_ASK = orderTriggerRef.Add(OrderTriggerRef{"bestAsk"})
ORDER_TRIGGER_REF_MID_PRICE = orderTriggerRef.Add(OrderTriggerRef{"midPrice"})
orderTriggerRefs = orderTriggerRef.Enum()
orderTriggerRef = enum.NewBuilder[string, OrderTriggerRef]()
OrderTriggerRefLastTrade = orderTriggerRef.Add(OrderTriggerRef{"lastTrade"})
OrderTriggerRefBestBid = orderTriggerRef.Add(OrderTriggerRef{"bestBid"})
OrderTriggerRefBestAsk = orderTriggerRef.Add(OrderTriggerRef{"bestAsk"})
OrderTriggerRefMidPrice = orderTriggerRef.Add(OrderTriggerRef{"midPrice"})
orderTriggerRefs = orderTriggerRef.Enum()
)

type TimeInForce enum.Member[string]

var (
timeInForce = enum.NewBuilder[string, TimeInForce]()
TIME_IN_FORCE_DEFAULT = TIME_IN_FORCE_GTC
TIME_IN_FORCE_GTC = timeInForce.Add(TimeInForce{"GTC"})
TIME_IN_FORCE_IOC = timeInForce.Add(TimeInForce{"IOC"})
TIME_IN_FORCE_FOK = timeInForce.Add(TimeInForce{"FOK"})
timeInForces = timeInForce.Enum()
timeInForce = enum.NewBuilder[string, TimeInForce]()
TimeInForceDefault = TimeInForceGtc
TimeInForceGtc = timeInForce.Add(TimeInForce{"GTC"})
TimeInForceIoc = timeInForce.Add(TimeInForce{"IOC"})
TimeInForceFok = timeInForce.Add(TimeInForce{"FOK"})
timeInForces = timeInForce.Enum()
)

type SelfTradePrevention enum.Member[string]

var (
selfTradePrevention = enum.NewBuilder[string, SelfTradePrevention]()
SELF_TRADE_PREVENTION_DEFAULT = SELF_TRADE_PREVENTION_DAC
SELF_TRADE_PREVENTION_DAC = selfTradePrevention.Add(SelfTradePrevention{"decrementAndCancel"})
SELF_TRADE_PREVENTION_CO = selfTradePrevention.Add(SelfTradePrevention{"cancelOldest"})
SELF_TRADE_PREVENTION_CN = selfTradePrevention.Add(SelfTradePrevention{"cancelNewest"})
SELF_TRADE_PREVENTION_CB = selfTradePrevention.Add(SelfTradePrevention{"cancelBoth"})
selfTradePreventions = selfTradePrevention.Enum()
selfTradePrevention = enum.NewBuilder[string, SelfTradePrevention]()
SelfTradePreventionDefault = SelfTradePreventionDac
SelfTradePreventionDac = selfTradePrevention.Add(SelfTradePrevention{"decrementAndCancel"})
SelfTradePreventionCo = selfTradePrevention.Add(SelfTradePrevention{"cancelOldest"})
SelfTradePreventionCn = selfTradePrevention.Add(SelfTradePrevention{"cancelNewest"})
SelfTradePreventionCb = selfTradePrevention.Add(SelfTradePrevention{"cancelBoth"})
selfTradePreventions = selfTradePrevention.Enum()
)

type Order struct {
Expand Down
8 changes: 4 additions & 4 deletions pkg/bitvavo/order_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func NewOrderListener(apiKey, apiSecret string) Listener[OrderEvent] {
chn: chn,
rchn: rchn,
once: new(sync.Once),
channel: CHANNEL_ACCOUNT,
channel: ChannelAccount,
},
}

Expand Down Expand Up @@ -90,14 +90,14 @@ func (l *OrderListener) Close() error {
func (l *OrderListener) onMessage(data WebSocketEventData, err error) {
if err != nil {
l.chn <- OrderEvent{Error: err}
} else if data.Event == EVENT_AUTHENTICATE {
} else if data.Event == EventAuthenticate {
var auth Authenticate
if err := data.Decode(&auth); err != nil {
l.chn <- OrderEvent{Error: err}
} else {
l.authchn <- auth.Authenticated
}
} else if data.Event == EVENT_SUBSCRIBED || data.Event == EVENT_UNSUBSCRIBED {
} else if data.Event == EventSubscribed || data.Event == EventUnsubscribed {
var subscribed Subscribed
if err := data.Decode(&subscribed); err != nil {
l.chn <- OrderEvent{Error: err}
Expand All @@ -109,7 +109,7 @@ func (l *OrderListener) onMessage(data WebSocketEventData, err error) {
l.chn <- OrderEvent{Error: ErrExpectedChannel(l.channel)}
}
}
} else if data.Event == EVENT_ORDER {
} else if data.Event == EventOrder {
var order Order
l.chn <- OrderEvent{Value: order, Error: data.Decode(&order)}
}
Expand Down
Loading

0 comments on commit ee43f5c

Please sign in to comment.