Skip to content
This repository has been archived by the owner on Nov 29, 2022. It is now read-only.

Mod/fix4 #60

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*.DS_Store
*.vscode
*.DS_Store
*.vscode
.env
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/go-numb/go-ftx
module github.com/boyi/go-ftx

go 1.14

Expand Down
8 changes: 4 additions & 4 deletions realtime/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import (
"os"
"time"

"github.com/boyi/go-ftx/rest/private/fills"
"github.com/boyi/go-ftx/rest/private/orders"
"github.com/boyi/go-ftx/rest/public/markets"
"github.com/boyi/go-ftx/types"
"github.com/buger/jsonparser"
"github.com/go-numb/go-ftx/rest/private/fills"
"github.com/go-numb/go-ftx/rest/private/orders"
"github.com/go-numb/go-ftx/rest/public/markets"
"github.com/go-numb/go-ftx/types"
"github.com/gorilla/websocket"
)

Expand Down
2 changes: 1 addition & 1 deletion realtime/websocket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"testing"
"time"

"github.com/go-numb/go-ftx/realtime"
"github.com/boyi/go-ftx/realtime"
)

func TestConnect(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion rest/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package rest
import (
"time"

"github.com/go-numb/go-ftx/auth"
"github.com/boyi/go-ftx/auth"
jsoniter "github.com/json-iterator/go"
"github.com/valyala/fasthttp"
)
Expand Down
30 changes: 30 additions & 0 deletions rest/private/convert/accept-quote.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package convert

import (
"fmt"
"net/http"
)

type RequestForAcceptQuote struct {
QuoteId int `json:"quoteId"`
}

type ResponseForAcceptQuote struct {
// Filled bool `json:"filled"`
}

func (req *RequestForAcceptQuote) Path() string {
return fmt.Sprintf("/otc/quotes/%d/accept", req.QuoteId)
}

func (req *RequestForAcceptQuote) Method() string {
return http.MethodPost
}

func (req *RequestForAcceptQuote) Query() string {
return ""
}

func (req *RequestForAcceptQuote) Payload() []byte {
return nil
}
41 changes: 41 additions & 0 deletions rest/private/convert/get-quote-status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package convert

import (
"fmt"
"net/http"
)

type RequestForQuoteStatus struct {
QuoteId int `json:"quoteId"`
}

type ResponseForQuoteStatus struct {
BaseCoin string `json:"baseCoin"`
Cost float64 `json:"cost"`
Expired bool `json:"expired"`
Expiry float64 `json:"expiry"`
Filled bool `json:"filled"`
FromCoin string `json:"fromCoin"`
QuoteId int `json:"id"`
Price float64 `json:"price"`
Proceeds float64 `json:"proceeds"`
QuoteCoin string `json:"quoteCoin"`
Side string `json:"side"`
ToCoin string `json:"toCoin"`
}

func (req *RequestForQuoteStatus) Path() string {
return fmt.Sprintf("/otc/quotes/%d", req.QuoteId)
}

func (req *RequestForQuoteStatus) Method() string {
return http.MethodGet
}

func (req *RequestForQuoteStatus) Query() string {
return ""
}

func (req *RequestForQuoteStatus) Payload() []byte {
return nil
}
37 changes: 37 additions & 0 deletions rest/private/convert/request-quote.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package convert

import (
"encoding/json"
"net/http"
)

type RequestForRequestQuote struct {
FromCoin string `json:"fromCoin"`
ToCoin string `json:"toCoin"`
Size float64 `json:"size"`
// WaitForPrice bool `json:"waitForPrice,omitempty"`
}

type ResponseForRequestQuote struct {
QuoteId int `json:"quoteId"`
}

func (req *RequestForRequestQuote) Path() string {
return "/otc/quotes"
}

func (req *RequestForRequestQuote) Method() string {
return http.MethodPost
}

func (req *RequestForRequestQuote) Query() string {
return ""
}

func (req *RequestForRequestQuote) Payload() []byte {
b, err := json.Marshal(req)
if err != nil {
return nil
}
return b
}
112 changes: 112 additions & 0 deletions rest/private/convert/request-quote_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package convert_test

import (
"fmt"
"os"
"testing"

"github.com/boyi/go-ftx/auth"
"github.com/boyi/go-ftx/rest"
"github.com/boyi/go-ftx/rest/private/account"
"github.com/boyi/go-ftx/rest/private/convert"
"github.com/stretchr/testify/assert"
)

func getAuth() *rest.Client {
subaccountNickname := os.Getenv("FTXSUBACCOUNT")

if subaccountNickname == "" {
return rest.New(auth.New(os.Getenv("FTXKEY"), os.Getenv("FTXSECRET")))
}

c := rest.New(auth.New(os.Getenv("FTXKEY"), os.Getenv("FTXSECRET"),
auth.SubAccount{
UUID: 1,
Nickname: subaccountNickname,
}))
c.Auth.UseSubAccountID(1)
return c
}

func TestInformation(t *testing.T) {
c := getAuth()

res, err := c.Information(&account.RequestForInformation{})
assert.NoError(t, err)

fmt.Printf("%+v\n", res)
}

func GetQuote() (resp *convert.ResponseForRequestQuote, err error) {
c := getAuth()

res, err := c.RequestConvertQuote(&convert.RequestForRequestQuote{
FromCoin: "USDT",
ToCoin: "USD",
Size: 2,
})
return res, err
}

func TestRequestQuote(t *testing.T) {
quote, err := GetQuote()
assert.NoError(t, err)
assert.NotZero(t, quote.QuoteId)
quoteId := quote.QuoteId

fmt.Printf("QuoteID: %+v\n", quoteId)
}

func GetQuoteStatus(quoteId int) (resp *convert.ResponseForQuoteStatus, err error) {
c := getAuth()

res, err := c.GetConvertQuoteStatus(&convert.RequestForQuoteStatus{
QuoteId: quoteId,
})

return res, err
}

func TestQuoteStatus(t *testing.T) {
quote, err := GetQuote()
assert.NoError(t, err)
assert.NotZero(t, quote.QuoteId)
quoteId := quote.QuoteId
fmt.Printf("Got quote with ID: %+v\n", quoteId)

res, err := GetQuoteStatus(quoteId)

assert.NoError(t, err)
assert.Equal(t, res.QuoteId, quoteId)
assert.NotZero(t, res.Price)

fmt.Printf("Result: %+v\n", res)
}

func AcceptQuote(quoteId int) (resp *convert.ResponseForAcceptQuote, err error) {
c := getAuth()

res, err := c.AcceptConvertQuote(&convert.RequestForAcceptQuote{
QuoteId: quoteId,
})

return res, err
}

func TestAcceptQuote(t *testing.T) {
quote, err := GetQuote()
assert.NoError(t, err)
assert.NotZero(t, quote.QuoteId)
quoteId := quote.QuoteId
fmt.Printf("Got quote with ID: %+v\n", quoteId)

res_status, err := GetQuoteStatus(quoteId)
assert.NoError(t, err)
assert.Equal(t, res_status.QuoteId, quoteId)
assert.NotZero(t, res_status.Cost)
fmt.Printf("Got quote status: %+v\n", res_status)

res_accept, err := AcceptQuote(quoteId)
assert.NoError(t, err)
fmt.Printf("Accepted quote: %+v\n", res_accept)
}
2 changes: 2 additions & 0 deletions rest/private/wallet/deposit-histories.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
)

type RequestForDepositHistories struct {
StartTime time.Time `url:"start_time,omitempty"`
EndTime time.Time `url:"end_time,omitempty"`
}

type ResponseForDepositHistories []History
Expand Down
2 changes: 1 addition & 1 deletion rest/private/wallet/withdraw-histories.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type Withdraw struct {
Method string `json:"method"`

Fee float64 `json:"fee"`
Size float64 `json:"size,string"`
Size float64 `json:"size"`

Time time.Time `json:"time"`

Expand Down
10 changes: 10 additions & 0 deletions rest/private/wallet/withdraw.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package wallet

import (
"net/http"
"time"
)

type RequestForWithdraw struct {
Expand All @@ -16,6 +17,15 @@ type RequestForWithdraw struct {
}

type ResponseForWithdraw struct {
Coin string `json:"coin,omitempty"`
Address string `json:"address,omitempty"`
Tag string `json:"tag,omitempty"`
Fee float64 `json:"fee,omitempty"`
ID int64 `json:"id,omitempty"`
Size float64 `json:"size,omitempty"`
Status string `json:"status,omitempty"` // one of "requested", "processing", "complete", or "cancelled"
Time time.Time `json:"time,omitempty"`
TxID string `json:"txid,omitempty"`
}

func (req *RequestForWithdraw) Path() string {
Expand Down
2 changes: 1 addition & 1 deletion rest/public/markets/trades.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"net/http"
"time"

"github.com/go-numb/go-ftx/types"
"github.com/boyi/go-ftx/types"
"github.com/google/go-querystring/query"
)

Expand Down
4 changes: 2 additions & 2 deletions rest/request-lev-options.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package rest

import (
"github.com/go-numb/go-ftx/rest/private/leveraged"
"github.com/go-numb/go-ftx/rest/private/options"
"github.com/boyi/go-ftx/rest/private/leveraged"
"github.com/boyi/go-ftx/rest/private/options"
)

/*
Expand Down
10 changes: 5 additions & 5 deletions rest/request-lev-options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import (
"testing"
"time"

"github.com/go-numb/go-ftx/auth"
"github.com/go-numb/go-ftx/types"
"github.com/boyi/go-ftx/auth"
"github.com/boyi/go-ftx/types"

"github.com/stretchr/testify/assert"

"github.com/go-numb/go-ftx/rest"
"github.com/go-numb/go-ftx/rest/private/leveraged"
"github.com/go-numb/go-ftx/rest/private/options"
"github.com/boyi/go-ftx/rest"
"github.com/boyi/go-ftx/rest/private/leveraged"
"github.com/boyi/go-ftx/rest/private/options"
)

/*
Expand Down
Loading