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

trades: implement trades requesting #4

Merged
merged 1 commit into from
Aug 29, 2017
Merged

trades: implement trades requesting #4

merged 1 commit into from
Aug 29, 2017

Conversation

odeke-em
Copy link
Member

Fixes #3

Exhibit:

package main

import (
  "fmt"
  "log"

  "github.com/orijtech/okcoin/v1"
)

func main() {
  client, err := okcoin.NewDefaultClient()
  if err != nil {
    log.Fatal(err)
  }

  tres, err := client.LastTrades(&okcoin.LastTradesRequest{
    Symbol:      okcoin.BTCUSD,
    LastTradeID: 354425297,
  })
  if err != nil {
    log.Fatal(err)
  }

  fmt.Printf("Last Trades for Symbol: %s\n\n", tres.Symbol)
  for i, trade := range tres.Trades {
    fmt.Printf("#%d ID: %d\n", i, trade.ID)
    fmt.Printf("\tAmount: %.3f\n", trade.Amount)
    fmt.Printf("\tPrice: %.3f\n", trade.Price)
    fmt.Printf("\tType: %s\n\n", trade.Type)
  }
}

which gives

Last Trades for Symbol: btc_usd

*0 ID: 354425531
  Amount: 0.061
  Price: 4615.820
  Type: buy

since I just used that request trade for requesting
for a previous test set.

Fixes #3

* Implement a LastTrades method that retrieves
trades since a certain ID as provided by okcoin's
REST API at https://www.okcoin.com/rest_api.html#spapi

Exhibit:

```go
package main

import (
  "fmt"
  "log"

  "github.com/orijtech/okcoin/v1"
)

func main() {
  client, err := okcoin.NewDefaultClient()
  if err != nil {
    log.Fatal(err)
  }

  tres, err := client.LastTrades(&okcoin.LastTradesRequest{
    Symbol:      okcoin.BTCUSD,
    LastTradeID: 354425297,
  })
  if err != nil {
    log.Fatal(err)
  }

  fmt.Printf("Last Trades for Symbol: %s\n\n", tres.Symbol)
  for i, trade := range tres.Trades {
    fmt.Printf("#%d ID: %d\n", i, trade.ID)
    fmt.Printf("\tAmount: %.3f\n", trade.Amount)
    fmt.Printf("\tPrice: %.3f\n", trade.Price)
    fmt.Printf("\tType: %s\n\n", trade.Type)
  }
}
```

which gives
```shell
Last Trades for Symbol: btc_usd

*0 ID: 354425531
  Amount: 0.061
  Price: 4615.820
  Type: buy
```

since I just used that request trade for requesting
for a previous test set.
@odeke-em odeke-em merged commit c650964 into master Aug 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant