Giter Club home page Giter Club logo

zaif-api-rust's Introduction

zaif-api-rust Crates.io

Use Zaif-Api from Rust

Description

Zaif ApiのWrapperです。 reqwest crateを使って実装しています。

Zaif Web API Reference

Usage

extern crate zaif_api;

use zaif_api::AccessKey;
use zaif_api::public_api::*;
use zaif_api::trade_api::*;

fn main() {
    let api = CurrenciesBuilder::new().name("btc".to_string()).finalize();
    for currency in api.exec().unwrap() {
        println!("name: {} is_token: {}", currency.name, currency.is_token);
    }

    let access_key = AccessKey::new("YOUR_API_KEY", "YOUR_API_SECRET");

    let api = TradeBuilder::new()
        .access_key(access_key.clone())
        .currency_pair("zaif_jpy".to_string())
        .action(TradeAction::Bid)
        .price(1.0)
        .amount(0.1)
        .finalize();
    let _ = api.exec().and_then(|res| {
        println!(
            "received: {}, remains: {}, order_id: {}",
            res.received,
            res.remains,
            res.order_id
        );
        if res.order_id == 0 {
            panic!("Complete trade.");
        }
        Ok(res.order_id)
    });
}

zaif-api-rust's People

Contributors

yajamon avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

hhatto incker2

zaif-api-rust's Issues

通信部をreqwestに限定しなくて良いのでは

ミドルウェアと言っていいのかわからないけど、APIとの通信部としてreqwestを埋め込む必要はないのではないか。
API利用者に必要なのは種類と、パラメータと、結果の型ではないか。

呼び出し側でエラーハンドリングしたい

はじめまして。
zaif-api-rustよいですね。便利に使っています。

一つ提案というか、設計方針や今後の対応についての確認なのですが、
今APIをコールした場合、reqwestに紐づくエラー(主にはネットワーク系)が発生した場合にpanicになってしまうのですが、呼び出し側で処理を継続するか選択したいので、panicにしないで欲しいという要望です。
(例えばこのあたりis_success()がfalseの場合にアサーションでpanicになる箇所

このあたりの対応予定等があれば教えていただきたいです。

ちなみに今はフォークしたこちらのブランチで、エラーが発生した場合でも無理やりOkを返して、serde_jsonのデコード処理でエラーにして、最終的に呼び出し側でエラー判定したりしています。
一時回避的なかなり怠惰な実装です;-)

CurrenciesなどのAPI毎の構造体を、public_apiなどの上位モジュールで開き直しているのは良くないと思う

v0.3.0の生成ドキュメントを見てもらうと、API・Builer・Responseが冗長に並んでいる。

https://docs.rs/zaif-api/0.3.0/zaif_api/public_api/index.html

いざドキュメントを書いたとして、これでは読み手がたらい回しになる気がしている。
currenciesひとつとっても、どの構造体のドキュメントを見に行けばBuilderの組み立て、実行、結果の使用方法が分かるのか悩んでしまうと考えている。

内部的にはAPIひとつにつきモジュールがひとつ切ってあるのだから、zaif_api::public_api::currencies::{Caller, Builder, Response}のように整理してしまっても良いのではなかろうか。

zaif_api::public_apiの配下には、各Builderへのショートカットになるfunctionがあればいいと思う。

あるいはファクトリを用意するか。毎回AccessToken.clone()するのも面倒だし、UserAgentだって共有して楽したい場面もあるだろうし。

Override User-Agent

CrateデフォルトのUser-Agentを書く?
それともUser-Agentの指定を必須にさせる?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.