Skip to content

Commit

Permalink
More examples added
Browse files Browse the repository at this point in the history
  • Loading branch information
marcin.wolski committed Jun 7, 2016
1 parent cb5b58a commit 442434c
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 12 deletions.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,34 @@ btcmarketexamples - example program showcasing using BtcMarkets C++11 RESTfull A
{"asks":[[0.01,10000.0],[0.01,6334.1398],[0.0101,9938.0659],[0.0102,10000.0],[0.0105,8213.8165],[0.0115,1194.7316],[0.01175,500.0],[0.01199999,1500.0],[0.012,7648.2917],[0.012,1000.0],[0.012,490.2207],[0.0125,100.0],[0.013,9.15],[0.0145,100.0],[0.016345,987.0],[0.0177,600.0],[0.02,244.241],[0.02,1.12839],[0.02,325.8413],[0.051111,500.0],[0.060111,500.0],[0.07,500.0],[0.08299,500.0],[0.1,0.001],[0.101,100.0],[1.0129,99.0]],"bids":[[0.00943102,200.0],[0.00943101,100.0],[0.00943,110.0],[0.00930202,1000.0],[0.00930201,100.0],[0.00913128,1000.0],[0.00906,388.0],[0.009,5000.0],[0.008,4350.0],[0.006,10000.0],[0.005,2000.0],[0.001,0.001]],"currency":"ETH","instrument":"DAO","timestamp":1465263134}
```


*DAO/ETH order book (no authentication required)*

```bash
./btcmarketsexamples -t DAO/ETH -c order_book

{"asks":[[0.01,10000.0],[0.01,6334.1398],[0.0101,9938.0659],[0.0102,10000.0],[0.0105,8213.8165],[0.0115,1194.7316],[0.01175,500.0],[0.01199999,1500.0],[0.012,7648.2917],[0.012,1000.0],[0.012,490.2207],[0.0125,100.0],[0.013,9.15],[0.0145,100.0],[0.016345,987.0],[0.0177,600.0],[0.02,244.241],[0.02,1.12839],[0.02,325.8413],[0.051111,500.0],[0.060111,500.0],[0.07,500.0],[0.08299,500.0],[0.1,0.001],[0.101,100.0],[1.0129,99.0]],"bids":[[0.00943102,200.0],[0.00943101,100.0],[0.00943,110.0],[0.00930202,1000.0],[0.00930201,100.0],[0.00913128,1000.0],[0.00906,388.0],[0.009,5000.0],[0.008,4350.0],[0.006,10000.0],[0.005,2000.0],[0.001,0.001]],"currency":"ETH","instrument":"DAO","timestamp":1465263134}
```


*Recent LTC/AUD trades (no authentication required)*

Only part of the result shown.

```bash
./btcmarketsexamples -t LTC/AUD -c trades

[{"amount":83.627615,"date":1465265085,"price":6.67,"tid":102659907},{"amount":20.0,"date":1465265085,"price":6.68,"tid":102659896},{"amount":0.01485992,"date":1465212487,"price":6.66,"tid":102533229},{"amount":0.01485992,"date":1465212382,"price":6.84,"tid":102533038},{"amount":0.20175051,"date":1465177962,"price":6.66,"tid":102385472},{"amount":5.0,"date":1465039217,"price":7.0,"tid":101896247},{"amount":4.327,"date":1465039027,"price":6.99,"tid":101895354},{"amount":4.327,"date":1465038961,"price":6.6,"tid":101894843},{"amount":2.0,"date":1465038961,"price":6.6,"tid":101894831},{"amount":1.0,"date":1465038961,"price":6.61,"tid":101894820},{"amount":2.673,"date":1465038961,"price":6.71,"tid":101894809},{"amount":14.1,"date":1465029497,"price":7.0,"tid":101871393},{"amount":3.2655605,"date":1465027433,"price":7.0,"tid":101869010},
```
Also can limit number of recent trends, by providing trade id to start from.
```bash
./btcmarketsexamples -c trades -t LTC/AUD --since 101894809

[{"amount":83.627615,"date":1465265085,"price":6.67,"tid":102659907},{"amount":20.0,"date":1465265085,"price":6.68,"tid":102659896},{"amount":0.01485992,"date":1465212487,"price":6.66,"tid":102533229},{"amount":0.01485992,"date":1465212382,"price":6.84,"tid":102533038},{"amount":0.20175051,"date":1465177962,"price":6.66,"tid":102385472},{"amount":5.0,"date":1465039217,"price":7.0,"tid":101896247},{"amount":4.327,"date":1465039027,"price":6.99,"tid":101895354},{"amount":4.327,"date":1465038961,"price":6.6,"tid":101894843},{"amount":2.0,"date":1465038961,"price":6.6,"tid":101894831},{"amount":1.0,"date":1465038961,"price":6.61,"tid":101894820}]
```
*Account balance (authentication required)*
Public `api_key` and secret `private_key` are required for functions dealing
Expand Down
14 changes: 11 additions & 3 deletions btcmarkets.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,13 +432,21 @@ class BtcMarkets


json
trades(const string& currency, const string& instrument) const
trades(const string& currency,
const string& instrument,
const string& since_trade_id = "") const
{
if (!trading_pair_available(currency, instrument))
return json {};

return order_book(currency, instrument,
"/market/{inst}/{curr}/trades");
string path = "/market/{inst}/{curr}/trades";

if (!since_trade_id.empty())
{
path += "?since=" + since_trade_id;
}

return order_book(currency, instrument, path);
}


Expand Down
19 changes: 10 additions & 9 deletions examples.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ int main(int acc, const char* avv[])
j = btc_market->order_book(options["currency"],
options["instrument"]);
}

if (options["command"] == "trades")
{
j = btc_market->trades(options["currency"],
options["instrument"],
options["since"]); /* since is trade id here */
}
}
else
{
Expand Down Expand Up @@ -83,12 +90,6 @@ int main(int acc, const char* avv[])
stoull(options["since"]));
}

if (options["command"] == "trades")
{
j = btc_market->trades(options["currency"],
options["instrument"]);
}

if (options["command"] == "account_balance")
{
j = btc_market->account_balance();
Expand Down Expand Up @@ -149,8 +150,8 @@ parse_options(int acc, const char *avv[], map<string, string>& options)

set<string> commands_requiring_auth {"order_history", "open_orders",
"create_order", "cancel_order",
"trades", "order_detail",
"account_balance", "trade_history"};
"order_detail", "account_balance",
"trade_history"};

po::options_description desc("btcmarketexamples - example program "
"showcasing using BtcMarkets "
Expand Down Expand Up @@ -246,7 +247,7 @@ parse_options(int acc, const char *avv[], map<string, string>& options)
options["type"] = vm["type"].as<string>();

options["limit"] = std::to_string(vm["limit"].as<uint64_t>());
options["since"] = std::to_string(vm["limit"].as<uint64_t>());
options["since"] = std::to_string(vm["since"].as<uint64_t>());

if (commands_requiring_auth.find(options["command"]) != commands_requiring_auth.end())
{
Expand Down

0 comments on commit 442434c

Please sign in to comment.