This repository has been archived by the owner on Jul 24, 2024. It is now read-only.
forked from andrewstuart/go-robinhood
-
Notifications
You must be signed in to change notification settings - Fork 0
/
currency_pairs.go
63 lines (54 loc) · 2.09 KB
/
currency_pairs.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
package robinhood
import (
"context"
"errors"
"fmt"
)
// CryptoCurrencyPair represent all availabe crypto currencies and whether they are tradeable or not
type CryptoCurrencyPair struct {
CyrptoAssetCurrency AssetCurrency `json:"asset_currency"`
ID string `json:"id"`
MaxOrderSize float64 `json:"max_order_size,string"`
MinOrderPriceIncrement float64 `json:"min_order_price_increment,string"`
MinOrderSize float64 `json:"min_order_size,string"`
Name string `json:"name"`
CrytoQuoteCurrency QuoteCurrency `json:"quote_currency"`
Symbol string `json:"symbol"`
Tradability string `json:"tradability"`
}
// QuoteCurrency holds info about currency you can use to buy the cyrpto currency
type QuoteCurrency struct {
Code string `json:"code"`
ID string `json:"id"`
Increment float64 `json:"increment,string"`
Name string `json:"name"`
Type string `json:"type"`
}
// AssetCurrency has code and id of cryptocurrency
type AssetCurrency struct {
BrandColor string `json:"brand_color"`
Code string `json:"code"`
ID string `json:"id"`
Increment float64 `json:"increment,string"`
Name string `json:"name"`
}
// GetCryptoCurrencyPairs will give which crypto currencies are tradeable and corresponding ids
func (c *Client) GetCryptoCurrencyPairs(ctx context.Context) ([]CryptoCurrencyPair, error) {
var r struct{ Results []CryptoCurrencyPair }
err := c.GetAndDecode(ctx, EPCryptoCurrencyPairs, &r)
return r.Results, err
}
// GetCryptoInstrument will take standard crypto symbol and return usable information
// to place the order
func (c *Client) GetCryptoInstrument(ctx context.Context, symbol string) (*CryptoCurrencyPair, error) {
allPairs, err := c.GetCryptoCurrencyPairs(ctx)
if err != nil {
return nil, fmt.Errorf("call failed with error: %v", err.Error())
}
for _, pair := range allPairs {
if pair.CyrptoAssetCurrency.Code == symbol {
return &pair, nil
}
}
return nil, errors.New("could not find given symbol")
}