forked from andrewstuart/go-robinhood
-
Notifications
You must be signed in to change notification settings - Fork 1
/
instrument.go
68 lines (62 loc) · 2.24 KB
/
instrument.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
package robinhood
import (
"context"
"fmt"
)
// Instrument is a type to represent the "instrument" API type in the
// unofficial robinhood API.
type Instrument struct {
BloombergUnique string `json:"bloomberg_unique"`
Country string `json:"country"`
DayTradeRatio string `json:"day_trade_ratio"`
DefaultCollarFraction string `json:"default_collar_fraction"`
FractionalTradability string `json:"fractional_tradability"`
Fundamentals string `json:"fundamentals"`
ID string `json:"id"`
ListDate string `json:"list_date"`
MaintenanceRatio string `json:"maintenance_ratio"`
MarginInitialRatio string `json:"margin_initial_ratio"`
Market string `json:"market"`
MinTickSize interface{} `json:"min_tick_size"`
Name string `json:"name"`
Quote string `json:"quote"`
RhsTradability string `json:"rhs_tradability"`
SimpleName interface{} `json:"simple_name"`
Splits string `json:"splits"`
State string `json:"state"`
Symbol string `json:"symbol"`
Tradeable bool `json:"tradeable"`
Tradability string `json:"tradability"`
TradableChainID string `json:"tradable_chain_id"`
Type string `json:"type"`
URL string `json:"url"`
}
func (i Instrument) OrderURL() string {
return i.URL
}
func (i Instrument) OrderSymbol() string {
return i.Symbol
}
// GetInstrument returns an Instrument given a URL
func (c *Client) GetInstrument(ctx context.Context, instURL string) (*Instrument, error) {
var i Instrument
err := c.GetAndDecode(ctx, instURL, &i)
if err != nil {
return nil, err
}
return &i, err
}
// GetInstrumentForSymbol returns an Instrument given a ticker symbol
func (c *Client) GetInstrumentForSymbol(ctx context.Context, sym string) (*Instrument, error) {
var i struct {
Results []Instrument
}
err := c.GetAndDecode(ctx, EPInstruments+"?symbol="+sym, &i)
if err != nil {
return nil, err
}
if len(i.Results) < 1 {
return nil, fmt.Errorf("no results")
}
return &i.Results[0], err
}