Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.9.0 #66

Merged
merged 11 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@
# vendor/

# CUSTOM
*.env
*.env
*.json
*.crt
*.key
20 changes: 20 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# contributing to go-schwab/trader

contributing to this project is very easy! development happens on the [dev](https://github.com/go-schwab/trader/tree/dev) branch. the goal is for the main branch to remain essentially unchanged (barring library-breaking behavior) until the next semantic release, to keep things as stable as possible.

---

BEFORE DOING ANY OF THIS, YOU MUST TEST YOUR CHANGES BY RUNNING GO TEST.

IF YOUR CODE DOESNT PASS OUR CI TESTS, YOUR PR WILL NOT BE REVIEWED KINDLY :)

0. create a fork
1. commit your changes
2. create a pull request to the dev branch, preferably with the following description:

```
major | minor:
ref: [issue] #_ | [pr] v_._._
desc:
- ...
```
67 changes: 49 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
# go wrapper for schwab's trader-api

[![Go Reference](https://pkg.go.dev/badge/github.com/samjtro/schwab.svg)](https://pkg.go.dev/github.com/samjtro/schwab)
[![Go Report Card](https://goreportcard.com/badge/github.com/samjtro/schwab)](https://goreportcard.com/report/github.com/samjtro/schwab)
[![License](https://img.shields.io/badge/License-GPLv2-green)](LICENSE)

built by [@samjtro](https://github.com/samjtro)
built by: [@samjtro](https://github.com/samjtro)

see: [CONTRIBUTING.md](https://github.com/go-schwab/trader/blob/main/CONTRIBUTING.md)

if you want to contribute - go for it! there is no contribution guide, just a simple golden rule: if it ain't broke, don't fix it:
**all** contributions should be tested via `go test` before submission.
---

why should you use this project?

- lightning fast
- return structs are easily indexable
- easy to setup, easy to use (personal preference, i know - but trust me!)
Expand All @@ -17,14 +20,23 @@ why should you use this project?

### 0.0 quick start

0. go to https://developer.schwab.com, create an account, create an app, get app credentials from https://developer.schwab.com/dashboard/apps
1. create `config.env` in your project directory, formatted as such:
0. go to <https://developer.schwab.com>, create an account, create an app, get app credentials from <https://developer.schwab.com/dashboard/apps>
1. create any file with the `.env` extension in your project directory (can also have multiple, if necessary), formatted as such:

```
APPKEY=KEY0 // App Key
SECRET=KEY1 // App Secret
CBURL=https://127.0.0.1 // App Callback URL
```
2. `go get github.com/go-schwab/[email protected]`

2. run the following command in your cwd to generate ssl certs for secure tls transmission of your bearer token:

```
openssl req -x509 -out localhost.crt -keyout localhost.key -newkey rsa:2048 -nodes -sha256 -subj '/CN=localhost' -extensions EXT -config <( \
printf "[dn]\nCN=localhost\n[req]\ndistinguished_name = dn\n[EXT]\nsubjectAltName=DNS.1:localhost,IP:127.0.0.1\nkeyUsage=digitalSignature\nextendedKeyUsage=serverAuth")
```

3. `go get github.com/go-schwab/[email protected]`

### 0.1 agent

Expand All @@ -44,7 +56,7 @@ agent := trader.Initiate()

code samples:

```
```go
df, err := agent.GetPriceHistory("AAPL", "month", "1", "daily", "1", "", "")
check(err)
```
Expand All @@ -62,7 +74,7 @@ return:

code samples:

```
```go
quote, err := agent.GetQuote("AAPL")
check(err)
```
Expand All @@ -76,14 +88,13 @@ return:
{EQUITY COE NBBO true 1973757747 AAPL 199.62 164.075 EDGX 195.75 5 1717687921950 XNAS 195.74 4 1717687920970 195.87 196.5 XADF 195.745 100 195.21 195.745 -0.125 -0.06381784 -0.125 -0.06381784 0 0 0 1717687921950 Normal 14237020 1717687921574}
```


#### 1.3.0 instruments

##### 1.3.1 simple

code samples:

```
```go
simple, err := agent.SearchInstrumentSimple("AAPL")
check(err)
```
Expand All @@ -101,7 +112,7 @@ return:

code samples:

```
```go
fundamental, err := agent.SearchInstrumentFundamental("AAPL")
check(err)
```
Expand All @@ -119,7 +130,7 @@ return:

code samples:

```
```go
movers, err := agent.GetMovers("$DJI", "up", "percent")
check(err)
```
Expand All @@ -139,7 +150,7 @@ return:

to submit any trades in this library, one must use your encrypted account id. this as accessed by using the `agent.GetAccountNumbers()` function, which is then passed to the submission function. this is because there are use cases where you might want to change between multiple accounts while trading the same session.

```
```go
an, err := agent.GetAccountNumbers()
check(err)
```
Expand All @@ -150,15 +161,15 @@ the rest of the docs assume you want to use the first element of the `[]AccountN

suppose we wanted to submit a single-leg market order for the symbol "AAPL". this is as easy as:

```
```go
err = agent.SubmitSingleLegOrder(an[0].HashValue, CreateSingleLegOrder(OrderType("MARKET"), Session("NORMAL"), Duration("DAY"), Strategy("SINGLE"), Instruction("BUY"), Quantity(1.0), Instrument(SimpleOrderInstrument{
Symbol: "AAPL",
AssetType: "EQUITY",
Symbol: "AAPL",
AssetType: "EQUITY",
})))
check(err)
```

let's break this down, although it's fairly straight forward. `CreateSingleLegOrder` returns a `SingleLegOrder`, passed to `agent.SubmitSingleLegOrder` after the hash value of your encrypted id. `CreateSingleOrder` accepts an unknown amount of parameters setting the various required elements for the order:
let's break this down, although it's fairly straight forward. `CreateSingleLegOrder` returns a `SingleLegOrder`, passed to `agent.SubmitSingleLegOrder` after the hash value of your encrypted id. `CreateSingleOrder` accepts an unknown amount of parameters setting the various elements for the order:

```
OrderType:
Expand All @@ -170,12 +181,32 @@ Quantity:
Instrument:
```

the default behavior of CreateSingleLegOrder() assumes you are submitting an order with the following parameters:

```
OrderType: MARKET
Session: NORMAL
Duration: DAY
Strategy: SINGLE
```

meaning only `INSTRUCTION`, `QUANTITY` & `INSTRUMENT` are the only required directives. the above example can be simplified thusly:

```go
err = agent.SubmitSingleLegOrder(an[0].HashValue, CreateSingleLegOrder(Instruction("BUY"), Quantity(1.0), Instrument(SimpleOrderInstrument{
Symbol: "AAPL",
AssetType: "EQUITY",
})))
check(err)
```

## WIP: DO NOT CROSS, DANGER DANGER

#### 2.2.0 accessing account data

##### 2.2.1.0

```
```go
an, err := agent.GetAccountNumbers()
check(err)
fmt.Println(an)
Expand Down
Loading