131 lines
3.7 KiB
Go
131 lines
3.7 KiB
Go
|
|
package tastytrade
|
||
|
|
|
||
|
|
import (
|
||
|
|
"encoding/json"
|
||
|
|
"fmt"
|
||
|
|
"net/url"
|
||
|
|
)
|
||
|
|
|
||
|
|
type MarginRequirement struct {
|
||
|
|
UnderlyingSymbol string `json:"underlying-symbol"`
|
||
|
|
LongEquityInitial float64 `json:"long-equity-initial"`
|
||
|
|
ShortEquityInitial float64 `json:"short-equity-initial"`
|
||
|
|
LongEquityMaintenance float64 `json:"long-equity-maintenance"`
|
||
|
|
ShortEquityMaintenance float64 `json:"short-equity-maintenance"`
|
||
|
|
NakedOptionStandard float64 `json:"naked-option-standard"`
|
||
|
|
NakedOptionMinimum float64 `json:"naked-option-minimum"`
|
||
|
|
NakedOptionFloor float64 `json:"naked-option-floor"`
|
||
|
|
ClearingIdentifier string `json:"clearing-identifier"`
|
||
|
|
IsDeleted bool `json:"is-deleted"`
|
||
|
|
}
|
||
|
|
|
||
|
|
type MarginRequirementResponse struct {
|
||
|
|
Data struct {
|
||
|
|
Items []MarginRequirement `json:"items"`
|
||
|
|
}
|
||
|
|
Context string `json:"context"`
|
||
|
|
}
|
||
|
|
|
||
|
|
type PositionLimit struct {
|
||
|
|
Id int32 `json:"id"`
|
||
|
|
AccountNumber string `json:"account-number"`
|
||
|
|
EquityOrderSize int32 `json:"equity-order-size"`
|
||
|
|
EquityOptionOrderSize int32 `json:"equity-option-order-size"`
|
||
|
|
FutureOrderSize int32 `json:"future-order-size"`
|
||
|
|
FutureOptionOrderSize int32 `json:"future-option-order-size"`
|
||
|
|
UnderlyingOpeningOrderLimit int32 `json:"underlying-opening-order-limit"`
|
||
|
|
EquityPositionSize int32 `json:"equity-position-size"`
|
||
|
|
EquityOptionPositionSize int32 `json:"equity-option-position-size"`
|
||
|
|
FuturePositionSize int32 `json:"future-position-size"`
|
||
|
|
FutureOptionPositionSize int32 `json:"future-option-position-size"`
|
||
|
|
}
|
||
|
|
|
||
|
|
type PositionLimitResponse struct {
|
||
|
|
Data struct {
|
||
|
|
Items []PositionLimit `json:"items"`
|
||
|
|
}
|
||
|
|
Context string `json:"context"`
|
||
|
|
}
|
||
|
|
|
||
|
|
type MarginRequirementsGlobalConfiguration struct {
|
||
|
|
RiskFreeRate float32 `json:"risk-free-rate"`
|
||
|
|
}
|
||
|
|
|
||
|
|
type MarginRequirementsGlobalConfigurationResponse struct {
|
||
|
|
Data struct {
|
||
|
|
Items []MarginRequirementsGlobalConfiguration `json:"items"`
|
||
|
|
}
|
||
|
|
Context string `json:"context"`
|
||
|
|
}
|
||
|
|
|
||
|
|
func (api *TastytradeAPI) GetMarginRequirements(accountNumber string, symbol string) (MarginRequirementResponse, error) {
|
||
|
|
urlVal := fmt.Sprintf(
|
||
|
|
"%s/accounts/%s/margin-requirements/%s/effective",
|
||
|
|
api.host,
|
||
|
|
url.PathEscape(accountNumber),
|
||
|
|
url.PathEscape(symbol))
|
||
|
|
data, err := api.fetchData(urlVal)
|
||
|
|
if err != nil {
|
||
|
|
return MarginRequirementResponse{}, err
|
||
|
|
}
|
||
|
|
|
||
|
|
var response MarginRequirementResponse
|
||
|
|
jsonData, err := json.Marshal(data)
|
||
|
|
if err != nil {
|
||
|
|
return MarginRequirementResponse{}, err
|
||
|
|
}
|
||
|
|
|
||
|
|
err = json.Unmarshal(jsonData, &response)
|
||
|
|
if err != nil {
|
||
|
|
return MarginRequirementResponse{}, err
|
||
|
|
}
|
||
|
|
|
||
|
|
return response, nil
|
||
|
|
}
|
||
|
|
|
||
|
|
func (api *TastytradeAPI) GetPositionLimit(accountNumber string) (PositionLimitResponse, error) {
|
||
|
|
urlVal := fmt.Sprintf(
|
||
|
|
"%s/accounts/%s/position-limit",
|
||
|
|
api.host,
|
||
|
|
url.PathEscape(accountNumber))
|
||
|
|
data, err := api.fetchData(urlVal)
|
||
|
|
if err != nil {
|
||
|
|
return PositionLimitResponse{}, err
|
||
|
|
}
|
||
|
|
|
||
|
|
var response PositionLimitResponse
|
||
|
|
jsonData, err := json.Marshal(data)
|
||
|
|
if err != nil {
|
||
|
|
return PositionLimitResponse{}, err
|
||
|
|
}
|
||
|
|
|
||
|
|
err = json.Unmarshal(jsonData, &response)
|
||
|
|
if err != nil {
|
||
|
|
return PositionLimitResponse{}, err
|
||
|
|
}
|
||
|
|
|
||
|
|
return response, nil
|
||
|
|
}
|
||
|
|
|
||
|
|
func (api *TastytradeAPI) GetMarginRequirementsPublicConfiguration(accountNumber string) (MarginRequirementsGlobalConfigurationResponse, error) {
|
||
|
|
urlVal := fmt.Sprintf( "%s/margin-requirements-public-configuration", api.host)
|
||
|
|
data, err := api.fetchData(urlVal)
|
||
|
|
if err != nil {
|
||
|
|
return MarginRequirementsGlobalConfigurationResponse{}, err
|
||
|
|
}
|
||
|
|
|
||
|
|
var response MarginRequirementsGlobalConfigurationResponse
|
||
|
|
jsonData, err := json.Marshal(data)
|
||
|
|
if err != nil {
|
||
|
|
return MarginRequirementsGlobalConfigurationResponse{}, err
|
||
|
|
}
|
||
|
|
|
||
|
|
err = json.Unmarshal(jsonData, &response)
|
||
|
|
if err != nil {
|
||
|
|
return MarginRequirementsGlobalConfigurationResponse{}, err
|
||
|
|
}
|
||
|
|
|
||
|
|
return response, nil
|
||
|
|
}
|
||
|
|
|