Skip to content

Commit

Permalink
FTX REST bootstrapping, websocket is missing orderbook channel and ex…
Browse files Browse the repository at this point in the history
…ample ftx.ws client is working.
  • Loading branch information
hoakbuilds committed May 6, 2021
1 parent 58e19fb commit 4e1cf67
Show file tree
Hide file tree
Showing 58 changed files with 1,308 additions and 427 deletions.
19 changes: 19 additions & 0 deletions .github/ISSUE_TEMPLATES/ccip---ccex-improvement-proposal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
name: CCIP - CCEX Improvement Proposal
about: Suggest an idea for this project
title: "[CCIP]"
labels: ''
assignees: murlokito
---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
31 changes: 31 additions & 0 deletions .github/ISSUE_TEMPLATES/issues---bug-reports.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
name: Issues / Bug Reports
about: Create a report to help us improve
title: "[Issue]"
labels: ''
assignees: murlokito
---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]

**Additional context**
Add any other context about the problem here.
21 changes: 11 additions & 10 deletions builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,29 @@ package builder

import (
"fmt"
. "github.com/murlokito/ccex"

"github.com/murlokito/ccex"
"github.com/murlokito/ccex/config"
"github.com/murlokito/ccex/exchange"
"github.com/murlokito/ccex/ftx"
)

// NewExchange returns a configured client with the passed config.
func NewExchange(exchange Exchange, config *config.Configuration) (*ExchangeClient, error) {
func NewExchange(exchange exchange.Exchange, config *config.Configuration) (*exchange.ExchangeClient, error) {
switch exchange {
case Binance:
return nil, ErrExchangeNotImplemented
return nil, ccex.ErrExchangeNotImplemented
case BinanceUS:
return nil, ErrExchangeNotImplemented
return nil, ccex.ErrExchangeNotImplemented
case BitMEX:
return nil, ErrExchangeNotImplemented
return nil, ccex.ErrExchangeNotImplemented
case Bybit:
return nil, ErrExchangeNotImplemented
return nil, ccex.ErrExchangeNotImplemented
case Deribit:
return nil, ErrExchangeNotImplemented
return nil, ccex.ErrExchangeNotImplemented
case FTX:
return NewFTXClient(config)
return ftx.NewFTXClient(config)
case FTXUS:
return nil, ErrExchangeNotImplemented
return nil, ccex.ErrExchangeNotImplemented
default:
return nil, fmt.Errorf("new clients error [%v]", Exchanges[exchange])
}
Expand Down
2 changes: 1 addition & 1 deletion exchanges.go → builder/exchanges.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ccex
package builder

const (
Binance = iota
Expand Down
48 changes: 0 additions & 48 deletions builder/ftx.go

This file was deleted.

2 changes: 1 addition & 1 deletion bybit/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ import "fmt"

var (
ErrMethodNotImplemented = fmt.Errorf("bybit: method not implemented")
ErrNotAuthenticated = fmt.Errorf("bybit: not authenticated")
ErrNotAuthenticated = fmt.Errorf("bybit: not authenticated")
)
2 changes: 1 addition & 1 deletion common/market.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ const (
Spot = iota
Futures
Options
)
)
4 changes: 1 addition & 3 deletions common/order.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@ const (
LimitOrder = iota
MarketOrder
TriggerOrder
)


)
9 changes: 8 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
package config

import "github.com/murlokito/ccex/auth"
import (
"fmt"
"github.com/murlokito/ccex/auth"
)

// Configuration holds everything necessary to
type Configuration struct {
Auth *auth.Authentication
SubAccount string
}

func (c Configuration) String() string {
return fmt.Sprintf("k: %v s: %v sub-account: %v", c.Auth.GetKey(), c.Auth.GetSecret(), c.SubAccount)
}

// GetAuth retrieves the configuration's authentication
func (c *Configuration) GetAuth() *auth.Authentication {
return c.Auth
Expand Down
4 changes: 2 additions & 2 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestConfig(t *testing.T) {

func TestSetConfig(t *testing.T) {
config := Configuration{
Auth: nil,
Auth: nil,
SubAccount: "none",
}
authInfo := &auth.Authentication{
Expand All @@ -40,4 +40,4 @@ func TestSetConfig(t *testing.T) {
}

})
}
}
57 changes: 0 additions & 57 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,60 +5,3 @@ This package holds examples on how to use `ccex` in the following ways:
- exchange-agnostic using the builder package
- exchange-specific using any of the supported exchanges

## Preview

### Exchange agnostic

```go
package main

import (
"fmt"
"net/http"

"github.com/murlokito/ccex"
builder "github.com/murlokito/ccex/builder"
)

func main() {

var (
exchanges []ccex.Exchange
)

clients := ccex.{
ccex.FTX,
ccex.Binance,
}


params := &ccex.Parameters{
Debug: false,
HttpClient: &http.Client{},
ProxyURL: "",
AccessKey: "access-key",
SecretKey: "access-secret",
}

exchange, err := builder.NewExchangeFromParameters(ccex.FTX, params)
if err != nil {
fmt.Println(err)
}

exchange.
}

```

### FTX

```go
package main

import "github.com/murlokito/ccex"

func main(){

}

```
75 changes: 56 additions & 19 deletions examples/ftx/main.go
Original file line number Diff line number Diff line change
@@ -1,41 +1,78 @@
package ftx
package main

import (
"fmt"
"github.com/murlokito/ccex/auth"
"github.com/murlokito/ccex/builder"
"github.com/murlokito/ccex/config"
"github.com/murlokito/ccex/ftx"
"github.com/murlokito/ccex/ftx/websocket"
"github.com/murlokito/ccex/ftx/websocket/models"
"time"
)

type Data struct {
Trades map[string][]models.TradeData
Ticker map[string]models.TickerData
}

func main() {

cfg := &config.Configuration{
Auth: &auth.Authentication{
Key: "some-key",
Secret: "some-secret",
},
SubAccount: "some-sub-account",
markets := []string{
"BTC-PERP", "ETH-PERP",
}

ftxClient, err := builder.NewFTXClient(cfg)
if err != nil {
fmt.Printf("err: %v", err)
data := Data{
Trades: map[string][]models.TradeData{},
Ticker: map[string]models.TickerData{},
}

handler := func(message models.TickerMessage) {
fmt.Printf("bid: %v ask: %v last: %v", message.Data.Bid, message.Data.Ask, message.Data.Last)
tickerHandler := func(message models.TickerMessage) {
//fmt.Printf("bid: %v ask: %v last: %v\n", message.Data.Bid, message.Data.Ask, message.Data.Last)
data.Ticker[message.Market] = message.Data
}

err = ftxClient.Websocket.TickerHandler(handler)
if err != nil {
fmt.Printf("err: %v", err)
tradeHandler := func(message models.TradeMessage) {
//complete := fmt.Sprintf("num trades: %v", len(message.Data))
for _, trade := range message.Data {
data.Trades[message.Market] = append(data.Trades[message.Market], trade)
//str := fmt.Sprintf("price: %v size: %v side: %v liq: %v\n", trade.Price, trade.Price, trade.Side, trade.Liquidation)
//complete += str
tradeVol := trade.Size * trade.Price
if tradeVol > 100000 {
fmt.Printf("{%v} {%v} Volume: $%.2f Price: $%v Liquidation: %v\n", message.Market, trade.Side, tradeVol, trade.Price, trade.Liquidation)
}
}
//fmt.Println(complete)
}

err = ftxClient.Websocket.Subscribe(websocket.Ticker, "BTC-PERP")
ftxClient, err := ftx.NewFTXClient(nil, nil, tickerHandler, tradeHandler, nil)
if err != nil {
fmt.Printf("err: %v", err)
}

ftxClient.Websocket.Connect()

for _, market := range markets {
err = ftxClient.Websocket.Subscribe(websocket.Ticker, market)
if err != nil {
fmt.Printf("err: %v", err)
}

err = ftxClient.Websocket.Subscribe(websocket.Trades, market)
if err != nil {
fmt.Printf("err: %v", err)
}
}

for {
if ftxClient.Websocket.Connected() {
fmt.Println(fmt.Sprintf("client is connected - active subs %v", ftxClient.Websocket.Subscriptions()))
}
for k, v := range data.Trades {
fmt.Println(fmt.Sprintf("number of trades for %v - %v", k, len(v)))
}
for k, v := range data.Ticker {
fmt.Println(fmt.Sprintf("latest ticker for %v - %v", k, v.Last))
}
time.Sleep(15 * time.Second)
}

}
22 changes: 0 additions & 22 deletions exchange.go

This file was deleted.

3 changes: 3 additions & 0 deletions exchange/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# exchange

This package specifies library-wide interfaces and constants.
Loading

0 comments on commit 4e1cf67

Please sign in to comment.