This repository has been archived by the owner on Jun 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exincore.go
104 lines (89 loc) · 2.44 KB
/
exincore.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package exincore_go
import (
"context"
"encoding/base64"
"encoding/json"
"errors"
bot "github.com/MixinNetwork/bot-api-go-client"
"github.com/MixinNetwork/go-number"
"github.com/gofrs/uuid"
"github.com/vmihailenco/msgpack"
"io/ioutil"
"net/http"
)
const (
exincoreUri = "https://exinone.com/exincore/"
exincoreBotUuid = "61103d28-3ac2-44a2-ae34-bd956070dab1"
)
type EClient struct {
userUuid string
sessionUuid string
pin string
pinToken string
privateKey string
}
func NewExinCoreClient(userUuid, sessionUuid, pin, pinToken, privateKey string) *EClient {
return &EClient{
userUuid: userUuid,
sessionUuid: sessionUuid,
pin: pin,
pinToken: pinToken,
privateKey: privateKey,
}
}
type PairInfo struct {
BaseAsset string `json:"base_asset"`
BaseAssetSymbol string `json:"base_asset_symbol"`
ExchangeAsset string `json:"exchange_asset"`
ExchangeAssetSymbol string `json:"exchange_asset_symbol"`
MinimumAmount string `json:"minimum_amount"`
MaximumAmount string `json:"maximum_amount"`
Exchanges []string `json:"exchanges"`
Price string `json:"price"`
}
// ----------------------
func (e *EClient) CreateOrder(ctx context.Context, base, exchange, traceId string, amount float64) error {
packUuid, _ := uuid.FromString(exchange)
var OrderAction struct {
A uuid.UUID
}
OrderAction.A = packUuid
pack, _ := msgpack.Marshal(OrderAction)
memo := base64.StdEncoding.EncodeToString(pack)
_, err := bot.CreateTransfer(ctx, &bot.TransferInput{
AssetId: base,
RecipientId: exincoreBotUuid,
Amount: number.FromFloat(amount),
TraceId: traceId,
Memo: memo,
}, e.userUuid, e.sessionUuid, e.privateKey, e.pin, e.pinToken)
if err != nil {
return err
}
return nil
}
func (e *EClient) ReadPair(base, exchange string) (*[]PairInfo, error) {
url := exincoreUri + "markets?base_asset=" + base + "&exchange_asset=" + exchange
response, err := http.Get(url)
if err != nil {
return nil, err
}
defer response.Body.Close()
body, err := ioutil.ReadAll(response.Body)
if err != nil {
return nil, err
}
var resp struct {
Code int `json:"code"`
Data []PairInfo `json:"data"`
Message string `json:"message"`
}
err = json.Unmarshal(body, &resp)
if err != nil {
return nil, err
}
if resp.Code != 0 || resp.Message != "" {
return nil, errors.New(resp.Message)
}
return &resp.Data, nil
}