Exemplo n.º 1
0
func TestCalculateNeededArb(t *testing.T) {
	// Test without FX
	neededArbTests := []neededArb{
		{500, -500, .02},
		{-500, 500, -.01},
		{500, 500, .005},
		{-100, -100, .005},
		{0, 0, .005},
		{-250, 250, -.0025},
		{250, -250, .0125},
		{100, -100, .008},
		{0, -200, .008},
		{-200, 0, .002},
		{-100, 100, .002},
	}
	buyExg := okcoin.New("", "", "", "usd", 1, 0.002, 500, 0)
	buyExg.SetMaxPos(500)
	sellExg := bitfinex.New("", "", "", "usd", 2, 0.001, 500, 0)
	sellExg.SetMaxPos(500)

	for _, neededArb := range neededArbTests {
		buyExg.SetPosition(neededArb.buyExgPos)
		sellExg.SetPosition(neededArb.sellExgPos)
		arb := calcNeededArb(buyExg, sellExg)
		if math.Abs(arb-neededArb.arb) > .000001 {
			t.Errorf("For %.4f / %.4f expect %.4f, got %.4f\n", buyExg.Position(), sellExg.Position(), neededArb.arb, arb)
		}
	}

	// Test with FX
	neededArbTests = []neededArb{
		{500, -500, .03},
		{-500, 500, 0},
		{500, 500, .015},
		{-100, -100, .015},
		{0, 0, .015},
		{-250, 250, .0075},
		{250, -250, .0225},
		{100, -100, .018},
		{0, -200, .018},
		{-200, 0, .012},
		{-100, 100, .012},
	}
	buyExg = okcoin.New("", "", "", "cny", 1, 0.002, 500, 0)
	buyExg.SetMaxPos(500)
	sellExg = bitfinex.New("", "", "", "usd", 2, 0.001, 500, 0)
	sellExg.SetMaxPos(500)

	for _, neededArb := range neededArbTests {
		buyExg.SetPosition(neededArb.buyExgPos)
		sellExg.SetPosition(neededArb.sellExgPos)
		arb := calcNeededArb(buyExg, sellExg)
		if math.Abs(arb-neededArb.arb) > .000001 {
			t.Errorf("For %.4f / %.4f expect %.4f, got %.4f\n", buyExg.Position(), sellExg.Position(), neededArb.arb, arb)
		}
	}

}
Exemplo n.º 2
0
// Initialize exchanges
func setExchanges() {
	exchanges = []exchange.Interface{
		bitfinex.New(os.Getenv("BITFINEX_KEY"), os.Getenv("BITFINEX_SECRET"), cfg.Sec.Symbol, "usd", 1, 0.001, cfg.Sec.AvailShortBitfinex, cfg.Sec.AvailFundsBitfinex),
		okcoin.New(os.Getenv("OKUSD_KEY"), os.Getenv("OKUSD_SECRET"), cfg.Sec.Symbol, "usd", 1, 0.002, cfg.Sec.AvailShortOKusd, cfg.Sec.AvailFundsOKusd),
		okcoin.New(os.Getenv("OKCNY_KEY"), os.Getenv("OKCNY_SECRET"), cfg.Sec.Symbol, "cny", 1, 0.000, cfg.Sec.AvailShortOKcny, cfg.Sec.AvailFundsOKcny),
		btcchina.New(os.Getenv("BTC_KEY"), os.Getenv("BTC_SECRET"), cfg.Sec.Symbol, "cny", 1, 0.000, cfg.Sec.AvailShortBTC, cfg.Sec.AvailFundsBTC),
	}
	for _, exg := range exchanges {
		log.Printf("Using exchange %s with priority %d and fee of %.4f", exg, exg.Priority(), exg.Fee())
	}
	currencies = append(currencies, "cny")
}
Exemplo n.º 3
0
// Tester program for displaying Bitfinex book data to terminal

package main

import (
	"bitfx/bitfinex"
	"bitfx/exchange"
	"fmt"
	"log"
	"os"
	"os/exec"
)

var bf = bitfinex.New("", "", "ltc", "usd", 0, 0, 0, 0)

func main() {
	filename := "bfbook.log"
	logFile, err := os.OpenFile(filename, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
	if err != nil {
		log.Fatal(err)
	}
	log.SetOutput(logFile)
	log.Println("Starting new run")

	bookChan := make(chan exchange.Book)
	if book := bf.CommunicateBook(bookChan); book.Error != nil {
		log.Fatal(book.Error)
	}
	inputChan := make(chan rune)
	go checkStdin(inputChan)