コード例 #1
1
ファイル: MarketBtce.java プロジェクト: kevinbaya/tradingpiad
 public BigDecimal subFee(BigDecimal amount) {
   return Op.mult(Op.sub(Decimal.ONE, fee_percent), amount);
 }
コード例 #2
0
ファイル: MarketBtce.java プロジェクト: kevinbaya/tradingpiad
  public MarketBtce(Currency cur1, Currency cur2) throws ExchangeError {
    super(cur1, cur2, "btce");

    // JSON mapper inialisation
    mapper = new ObjectMapper();
    mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    mapper.configure(DeserializationConfig.Feature.USE_BIG_DECIMAL_FOR_FLOATS, false);

    // Ajout d'un deserializer d'ordre customis� pour passer de "[ prix, amount ]" dans le json �
    // "new Order(prix,amount,Type.XXX) en java"
    SimpleModule testModule = new SimpleModule("MyModule", new Version(1, 0, 0, null));
    testModule.addDeserializer(Order.class, new OrderDeserializer());
    mapper.registerModule(testModule);

    // Ajout d'un deserializer des types customis� pour passer de "ask"(resp. "bid") dans le json �
    // "Type.ASK" (resp. "Type.BID") en java
    testModule = new SimpleModule("MyModule2", new Version(1, 0, 0, null));
    testModule.addDeserializer(Type.class, new TypeDeserializer(true));
    mapper.registerModule(testModule);

    // Verification si la pair <cur1, cur2> est accepte par l'exchange
    URL fee_url;
    Fee f;
    try {
      fee_url =
          new URL(
              "https://btc-e.com/api/2/"
                  + cur1.name().toLowerCase()
                  + "_"
                  + cur2.name().toLowerCase()
                  + "/fee");
      String is = Util.getData(fee_url);
      f = mapper.readValue(is, Fee.class);
      Assert.checkPrecond(
          f.error == null,
          "BTC-E n'autorise pas la pair: <" + cur1.name() + "," + cur2.name() + ">");
      // On set les frais de transaction maintenant qu'on est sur que Btc-e autorise la paire
      // <cur1,cur2>
      fee_percent = Op.mult(f.trade, new Decimal("0.01"));
    } catch (JsonParseException e) {
      e.printStackTrace();
      throw new ExchangeError("JsonParseException: Erreur jackson");
    } catch (JsonMappingException e) {
      e.printStackTrace();
      throw new ExchangeError("JsonMappingException: Erreur jackson");
    } catch (IOException e) {
      e.printStackTrace();
      throw new ExchangeError("IOException: Erreur jackson");
    }
  }