-
Notifications
You must be signed in to change notification settings - Fork 9
/
arb_end.go
59 lines (51 loc) · 1.44 KB
/
arb_end.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package ftxtrade
import (
"fmt"
"github.com/cqtrade/infobot/src/ftx"
)
func (ft *FtxTrade) ArbEnd(subAcc string, spot string) {
var spotUSD string
var future string
if spot == "BTC" {
spotUSD = "BTC/USD"
future = ft.cfg.FutureBTC
} else if spot == "ETH" {
spotUSD = "ETH/USD"
future = ft.cfg.FutureETH
}
fmt.Println("spotUSD: ", spotUSD)
fmt.Println("future: ", future)
// check if there's future short to close
key := ft.cfg.FTXKey
secret := ft.cfg.FTXSecret
client := ftx.New(key, secret, subAcc)
sBalance, _ := ft.CheckSpotBalance(client, subAcc, spot)
position, _ := ft.CheckFuturePosition(client, future)
// if !positions.Success {
// fmt.Println("FAILURE arb1 positions")
// return
// }
fmt.Println(sBalance.Total, position.Size)
if sBalance.Total > 0 {
orderMarketSpot, err := client.PlaceMarketOrder(spotUSD, "sell", "market", sBalance.Total)
if err != nil {
fmt.Println("Spot sell err", err)
} else if orderMarketSpot.Success {
fmt.Println("Spot sell success")
} else if !orderMarketSpot.Success {
fmt.Println("Spot sell failure", orderMarketSpot.Result)
}
} else {
fmt.Println("No spot to sell")
}
if position.Size > 0 {
orderMarketFuture, err := client.PlaceMarketOrder(future, "buy", "market", position.Size)
if err != nil {
fmt.Println("Future buy err", err)
} else if orderMarketFuture.Success {
fmt.Println("Future close success")
}
} else {
fmt.Println("No future to close")
}
}